Changed name of Profile entity to Hat
so as not to conflict with Profile or Profile2 module on existing sites
This commit is contained in:
parent
1e1bfe0ca9
commit
a48e37ad39
12
modules/zencrm_entities/config/schema/hat_type.schema.yml
Normal file
12
modules/zencrm_entities/config/schema/hat_type.schema.yml
Normal file
@ -0,0 +1,12 @@
|
||||
zencrm_entities.hat_type.*:
|
||||
type: config_entity
|
||||
label: 'Hat type config'
|
||||
mapping:
|
||||
id:
|
||||
type: string
|
||||
label: 'ID'
|
||||
label:
|
||||
type: label
|
||||
label: 'Label'
|
||||
uuid:
|
||||
type: string
|
30
modules/zencrm_entities/hat.page.inc
Normal file
30
modules/zencrm_entities/hat.page.inc
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains hat.page.inc.
|
||||
*
|
||||
* Page callback for Hat entities.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Render\Element;
|
||||
|
||||
/**
|
||||
* Prepares variables for Hat templates.
|
||||
*
|
||||
* Default template: hat.html.twig.
|
||||
*
|
||||
* @param array $variables
|
||||
* An associative array containing:
|
||||
* - elements: An associative array containing the user information and any
|
||||
* - attributes: HTML attributes for the containing element.
|
||||
*/
|
||||
function template_preprocess_hat(array &$variables) {
|
||||
// Fetch Hat Entity Object.
|
||||
$hat = $variables['elements']['#hat'];
|
||||
|
||||
// Helpful $content variable for templates.
|
||||
foreach (Element::children($variables['elements']) as $key) {
|
||||
$variables['content'][$key] = $variables['elements'][$key];
|
||||
}
|
||||
}
|
@ -192,7 +192,7 @@ class ContactDetails extends ContentEntityBase implements ContactDetailsInterfac
|
||||
// Person field is always set from the context so no form or display required.
|
||||
$fields['person'] = BaseFieldDefinition::create('entity_reference')
|
||||
->setLabel(t('Person'))
|
||||
->setDescription(t('The person this profile is of.'))
|
||||
->setDescription(t('The person this set of contact details is for.'))
|
||||
->setSetting('target_type', 'person')
|
||||
->setRequired(TRUE);
|
||||
|
||||
|
210
modules/zencrm_entities/src/Entity/Hat.php
Normal file
210
modules/zencrm_entities/src/Entity/Hat.php
Normal file
@ -0,0 +1,210 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities\Entity;
|
||||
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\Core\Entity\ContentEntityBase;
|
||||
use Drupal\Core\Entity\EntityChangedTrait;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\user\UserInterface;
|
||||
|
||||
/**
|
||||
* Defines the Hat entity.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "hat",
|
||||
* label = @Translation("Hat"),
|
||||
* bundle_label = @Translation("Hat type"),
|
||||
* handlers = {
|
||||
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
|
||||
* "list_builder" = "Drupal\zencrm_entities\HatListBuilder",
|
||||
* "views_data" = "Drupal\zencrm_entities\Entity\HatViewsData",
|
||||
* "translation" = "Drupal\zencrm_entities\HatTranslationHandler",
|
||||
*
|
||||
* "form" = {
|
||||
* "default" = "Drupal\zencrm_entities\Form\HatForm",
|
||||
* "add" = "Drupal\zencrm_entities\Form\HatForm",
|
||||
* "edit" = "Drupal\zencrm_entities\Form\HatForm",
|
||||
* "delete" = "Drupal\zencrm_entities\Form\HatDeleteForm",
|
||||
* },
|
||||
* "access" = "Drupal\zencrm_entities\HatAccessControlHandler",
|
||||
* "route_provider" = {
|
||||
* "html" = "Drupal\zencrm_entities\HatHtmlRouteProvider",
|
||||
* },
|
||||
* },
|
||||
* base_table = "hat",
|
||||
* data_table = "hat_field_data",
|
||||
* translatable = TRUE,
|
||||
* admin_permission = "administer hat entities",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "bundle" = "type",
|
||||
* "label" = "name",
|
||||
* "uuid" = "uuid",
|
||||
* "uid" = "user_id",
|
||||
* "langcode" = "langcode",
|
||||
* "status" = "status",
|
||||
* },
|
||||
* links = {
|
||||
* "canonical" = "/admin/structure/hat/{hat}",
|
||||
* "add-page" = "/admin/structure/hat/add",
|
||||
* "add-form" = "/admin/structure/hat/add/{hat_type}",
|
||||
* "edit-form" = "/admin/structure/hat/{hat}/edit",
|
||||
* "delete-form" = "/admin/structure/hat/{hat}/delete",
|
||||
* "collection" = "/admin/structure/hat",
|
||||
* },
|
||||
* bundle_entity_type = "hat_type",
|
||||
* field_ui_base_route = "entity.hat_type.edit_form"
|
||||
* )
|
||||
*/
|
||||
class Hat extends ContentEntityBase implements HatInterface {
|
||||
|
||||
use EntityChangedTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
|
||||
parent::preCreate($storage_controller, $values);
|
||||
$values += [
|
||||
'user_id' => \Drupal::currentUser()->id(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName() {
|
||||
return $this->get('name')->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setName($name) {
|
||||
$this->set('name', $name);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCreatedTime() {
|
||||
return $this->get('created')->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setCreatedTime($timestamp) {
|
||||
$this->set('created', $timestamp);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getOwner() {
|
||||
return $this->get('user_id')->entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getOwnerId() {
|
||||
return $this->get('user_id')->target_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setOwnerId($uid) {
|
||||
$this->set('user_id', $uid);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setOwner(UserInterface $account) {
|
||||
$this->set('user_id', $account->id());
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isPublished() {
|
||||
return (bool) $this->getEntityKey('status');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setPublished($published) {
|
||||
$this->set('status', $published ? TRUE : FALSE);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
$fields = parent::baseFieldDefinitions($entity_type);
|
||||
|
||||
$fields['user_id'] = BaseFieldDefinition::create('entity_reference')
|
||||
->setLabel(t('Authored by'))
|
||||
->setDescription(t('The user ID of the author.'))
|
||||
->setRevisionable(TRUE)
|
||||
->setSetting('target_type', 'user')
|
||||
->setSetting('handler', 'default')
|
||||
->setTranslatable(TRUE);
|
||||
# ->setDisplayOptions('form', [
|
||||
# 'type' => 'entity_reference_autocomplete',
|
||||
# 'weight' => 5,
|
||||
# 'settings' => [
|
||||
# 'match_operator' => 'CONTAINS',
|
||||
# 'size' => '60',
|
||||
# 'autocomplete_type' => 'tags',
|
||||
# 'placeholder' => '',
|
||||
# ],
|
||||
# ]);
|
||||
|
||||
// This field is always implied from the context,
|
||||
// so has no form or view display.
|
||||
$fields['person'] = BaseFieldDefinition::create('entity_reference')
|
||||
->setLabel(t('Person'))
|
||||
->setDescription(t('The person this hat is of.'))
|
||||
->setSetting('target_type', 'person');
|
||||
|
||||
// This field is computed in a presave hook, and used for entity reference
|
||||
// options when selecting a person for involvement in a case etc.
|
||||
$fields['name'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(t('Name'))
|
||||
->setDescription(t('The name of this hat instance as it appears in entity reference fields.'));
|
||||
|
||||
$fields['status'] = BaseFieldDefinition::create('boolean')
|
||||
->setLabel(t('Publishing status'))
|
||||
->setDescription(t('A boolean indicating whether the Hat is published.'))
|
||||
# ->setDisplayOptions('form', [
|
||||
# 'type' => 'boolean_checkbox',
|
||||
# 'weight' => -3,
|
||||
# ])
|
||||
->setDefaultValue(TRUE);
|
||||
|
||||
|
||||
$fields['created'] = BaseFieldDefinition::create('created')
|
||||
->setLabel(t('Created'))
|
||||
->setDescription(t('The time that the entity was created.'));
|
||||
|
||||
$fields['changed'] = BaseFieldDefinition::create('changed')
|
||||
->setLabel(t('Changed'))
|
||||
->setDescription(t('The time that the entity was last edited.'));
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
}
|
77
modules/zencrm_entities/src/Entity/HatInterface.php
Normal file
77
modules/zencrm_entities/src/Entity/HatInterface.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities\Entity;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\EntityChangedInterface;
|
||||
use Drupal\user\EntityOwnerInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface for defining Hat entities.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*/
|
||||
interface HatInterface extends ContentEntityInterface, EntityChangedInterface, EntityOwnerInterface {
|
||||
|
||||
// Add get/set methods for your configuration properties here.
|
||||
|
||||
/**
|
||||
* Gets the Hat name.
|
||||
*
|
||||
* @return string
|
||||
* Name of the Hat.
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Sets the Hat name.
|
||||
*
|
||||
* @param string $name
|
||||
* The Hat name.
|
||||
*
|
||||
* @return \Drupal\zencrm_entities\Entity\HatInterface
|
||||
* The called Hat entity.
|
||||
*/
|
||||
public function setName($name);
|
||||
|
||||
/**
|
||||
* Gets the Hat creation timestamp.
|
||||
*
|
||||
* @return int
|
||||
* Creation timestamp of the Hat.
|
||||
*/
|
||||
public function getCreatedTime();
|
||||
|
||||
/**
|
||||
* Sets the Hat creation timestamp.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* The Hat creation timestamp.
|
||||
*
|
||||
* @return \Drupal\zencrm_entities\Entity\HatInterface
|
||||
* The called Hat entity.
|
||||
*/
|
||||
public function setCreatedTime($timestamp);
|
||||
|
||||
/**
|
||||
* Returns the Hat published status indicator.
|
||||
*
|
||||
* Unpublished Hat are only visible to restricted users.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the Hat is published.
|
||||
*/
|
||||
public function isPublished();
|
||||
|
||||
/**
|
||||
* Sets the published status of a Hat.
|
||||
*
|
||||
* @param bool $published
|
||||
* TRUE to set this Hat to published, FALSE to set it to unpublished.
|
||||
*
|
||||
* @return \Drupal\zencrm_entities\Entity\HatInterface
|
||||
* The called Hat entity.
|
||||
*/
|
||||
public function setPublished($published);
|
||||
|
||||
}
|
58
modules/zencrm_entities/src/Entity/HatType.php
Normal file
58
modules/zencrm_entities/src/Entity/HatType.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
|
||||
|
||||
/**
|
||||
* Defines the Hat type entity.
|
||||
*
|
||||
* @ConfigEntityType(
|
||||
* id = "hat_type",
|
||||
* label = @Translation("Hat type"),
|
||||
* handlers = {
|
||||
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
|
||||
* "list_builder" = "Drupal\zencrm_entities\HatTypeListBuilder",
|
||||
* "form" = {
|
||||
* "add" = "Drupal\zencrm_entities\Form\HatTypeForm",
|
||||
* "edit" = "Drupal\zencrm_entities\Form\HatTypeForm",
|
||||
* "delete" = "Drupal\zencrm_entities\Form\HatTypeDeleteForm"
|
||||
* },
|
||||
* "route_provider" = {
|
||||
* "html" = "Drupal\zencrm_entities\HatTypeHtmlRouteProvider",
|
||||
* },
|
||||
* },
|
||||
* config_prefix = "hat_type",
|
||||
* admin_permission = "administer site configuration",
|
||||
* bundle_of = "hat",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "label" = "label",
|
||||
* "uuid" = "uuid"
|
||||
* },
|
||||
* links = {
|
||||
* "canonical" = "/admin/structure/hat_type/{hat_type}",
|
||||
* "add-form" = "/admin/structure/hat_type/add",
|
||||
* "edit-form" = "/admin/structure/hat_type/{hat_type}/edit",
|
||||
* "delete-form" = "/admin/structure/hat_type/{hat_type}/delete",
|
||||
* "collection" = "/admin/structure/hat_type"
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class HatType extends ConfigEntityBundleBase implements HatTypeInterface {
|
||||
|
||||
/**
|
||||
* The Hat type ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* The Hat type label.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label;
|
||||
|
||||
}
|
13
modules/zencrm_entities/src/Entity/HatTypeInterface.php
Normal file
13
modules/zencrm_entities/src/Entity/HatTypeInterface.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface for defining Hat type entities.
|
||||
*/
|
||||
interface HatTypeInterface extends ConfigEntityInterface {
|
||||
|
||||
// Add get/set methods for your configuration properties here.
|
||||
}
|
24
modules/zencrm_entities/src/Entity/HatViewsData.php
Normal file
24
modules/zencrm_entities/src/Entity/HatViewsData.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities\Entity;
|
||||
|
||||
use Drupal\views\EntityViewsData;
|
||||
|
||||
/**
|
||||
* Provides Views data for Hat entities.
|
||||
*/
|
||||
class HatViewsData extends EntityViewsData {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getViewsData() {
|
||||
$data = parent::getViewsData();
|
||||
|
||||
// Additional information for Views integration, such as table joins, can be
|
||||
// put here.
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
15
modules/zencrm_entities/src/Form/HatDeleteForm.php
Normal file
15
modules/zencrm_entities/src/Form/HatDeleteForm.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities\Form;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityDeleteForm;
|
||||
|
||||
/**
|
||||
* Provides a form for deleting Hat entities.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*/
|
||||
class HatDeleteForm extends ContentEntityDeleteForm {
|
||||
|
||||
|
||||
}
|
50
modules/zencrm_entities/src/Form/HatForm.php
Normal file
50
modules/zencrm_entities/src/Form/HatForm.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities\Form;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityForm;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Form controller for Hat edit forms.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*/
|
||||
class HatForm extends ContentEntityForm {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
/* @var $entity \Drupal\zencrm_entities\Entity\Hat */
|
||||
$form = parent::buildForm($form, $form_state);
|
||||
|
||||
$entity = $this->entity;
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save(array $form, FormStateInterface $form_state) {
|
||||
$entity = $this->entity;
|
||||
|
||||
$status = parent::save($form, $form_state);
|
||||
|
||||
switch ($status) {
|
||||
case SAVED_NEW:
|
||||
drupal_set_message($this->t('Created the %label Hat.', [
|
||||
'%label' => $entity->label(),
|
||||
]));
|
||||
break;
|
||||
|
||||
default:
|
||||
drupal_set_message($this->t('Saved the %label Hat.', [
|
||||
'%label' => $entity->label(),
|
||||
]));
|
||||
}
|
||||
$form_state->setRedirect('entity.hat.canonical', ['hat' => $entity->id()]);
|
||||
}
|
||||
|
||||
}
|
53
modules/zencrm_entities/src/Form/HatSettingsForm.php
Normal file
53
modules/zencrm_entities/src/Form/HatSettingsForm.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities\Form;
|
||||
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Class HatSettingsForm.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*/
|
||||
class HatSettingsForm extends FormBase {
|
||||
|
||||
/**
|
||||
* Returns a unique string identifying the form.
|
||||
*
|
||||
* @return string
|
||||
* The unique string identifying the form.
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'hat_settings';
|
||||
}
|
||||
|
||||
/**
|
||||
* Form submission handler.
|
||||
*
|
||||
* @param array $form
|
||||
* An associative array containing the structure of the form.
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The current state of the form.
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
// Empty implementation of the abstract submit class.
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the settings form for Hat entities.
|
||||
*
|
||||
* @param array $form
|
||||
* An associative array containing the structure of the form.
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The current state of the form.
|
||||
*
|
||||
* @return array
|
||||
* Form definition array.
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['hat_settings']['#markup'] = 'Settings form for Hat entities. Manage field settings here.';
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
53
modules/zencrm_entities/src/Form/HatTypeDeleteForm.php
Normal file
53
modules/zencrm_entities/src/Form/HatTypeDeleteForm.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities\Form;
|
||||
|
||||
use Drupal\Core\Entity\EntityConfirmFormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
* Builds the form to delete Hat type entities.
|
||||
*/
|
||||
class HatTypeDeleteForm extends EntityConfirmFormBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuestion() {
|
||||
return $this->t('Are you sure you want to delete %name?', ['%name' => $this->entity->label()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelUrl() {
|
||||
return new Url('entity.hat_type.collection');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfirmText() {
|
||||
return $this->t('Delete');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
$this->entity->delete();
|
||||
|
||||
drupal_set_message(
|
||||
$this->t('content @type: deleted @label.',
|
||||
[
|
||||
'@type' => $this->entity->bundle(),
|
||||
'@label' => $this->entity->label(),
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$form_state->setRedirectUrl($this->getCancelUrl());
|
||||
}
|
||||
|
||||
}
|
65
modules/zencrm_entities/src/Form/HatTypeForm.php
Normal file
65
modules/zencrm_entities/src/Form/HatTypeForm.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities\Form;
|
||||
|
||||
use Drupal\Core\Entity\EntityForm;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Class HatTypeForm.
|
||||
*/
|
||||
class HatTypeForm extends EntityForm {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function form(array $form, FormStateInterface $form_state) {
|
||||
$form = parent::form($form, $form_state);
|
||||
|
||||
$hat_type = $this->entity;
|
||||
$form['label'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Label'),
|
||||
'#maxlength' => 255,
|
||||
'#default_value' => $hat_type->label(),
|
||||
'#description' => $this->t("Label for the Hat type."),
|
||||
'#required' => TRUE,
|
||||
];
|
||||
|
||||
$form['id'] = [
|
||||
'#type' => 'machine_name',
|
||||
'#default_value' => $hat_type->id(),
|
||||
'#machine_name' => [
|
||||
'exists' => '\Drupal\zencrm_entities\Entity\HatType::load',
|
||||
],
|
||||
'#disabled' => !$hat_type->isNew(),
|
||||
];
|
||||
|
||||
/* You will need additional form elements for your custom properties. */
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save(array $form, FormStateInterface $form_state) {
|
||||
$hat_type = $this->entity;
|
||||
$status = $hat_type->save();
|
||||
|
||||
switch ($status) {
|
||||
case SAVED_NEW:
|
||||
drupal_set_message($this->t('Created the %label Hat type.', [
|
||||
'%label' => $hat_type->label(),
|
||||
]));
|
||||
break;
|
||||
|
||||
default:
|
||||
drupal_set_message($this->t('Saved the %label Hat type.', [
|
||||
'%label' => $hat_type->label(),
|
||||
]));
|
||||
}
|
||||
$form_state->setRedirectUrl($hat_type->toUrl('collection'));
|
||||
}
|
||||
|
||||
}
|
47
modules/zencrm_entities/src/HatAccessControlHandler.php
Normal file
47
modules/zencrm_entities/src/HatAccessControlHandler.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities;
|
||||
|
||||
use Drupal\Core\Entity\EntityAccessControlHandler;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
|
||||
/**
|
||||
* Access controller for the Hat entity.
|
||||
*
|
||||
* @see \Drupal\zencrm_entities\Entity\Hat.
|
||||
*/
|
||||
class HatAccessControlHandler extends EntityAccessControlHandler {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
|
||||
/** @var \Drupal\zencrm_entities\Entity\HatInterface $entity */
|
||||
switch ($operation) {
|
||||
case 'view':
|
||||
if (!$entity->isPublished()) {
|
||||
return AccessResult::allowedIfHasPermission($account, 'view unpublished hat entities');
|
||||
}
|
||||
return AccessResult::allowedIfHasPermission($account, 'view published hat entities');
|
||||
|
||||
case 'update':
|
||||
return AccessResult::allowedIfHasPermission($account, 'edit hat entities');
|
||||
|
||||
case 'delete':
|
||||
return AccessResult::allowedIfHasPermission($account, 'delete hat entities');
|
||||
}
|
||||
|
||||
// Unknown operation, no opinion.
|
||||
return AccessResult::neutral();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
|
||||
return AccessResult::allowedIfHasPermission($account, 'add hat entities');
|
||||
}
|
||||
|
||||
}
|
56
modules/zencrm_entities/src/HatHtmlRouteProvider.php
Normal file
56
modules/zencrm_entities/src/HatHtmlRouteProvider.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities;
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* Provides routes for Hat entities.
|
||||
*
|
||||
* @see \Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
|
||||
* @see \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
|
||||
*/
|
||||
class HatHtmlRouteProvider extends AdminHtmlRouteProvider {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRoutes(EntityTypeInterface $entity_type) {
|
||||
$collection = parent::getRoutes($entity_type);
|
||||
|
||||
$entity_type_id = $entity_type->id();
|
||||
|
||||
if ($settings_form_route = $this->getSettingsFormRoute($entity_type)) {
|
||||
$collection->add("$entity_type_id.settings", $settings_form_route);
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the settings form route.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
||||
* The entity type.
|
||||
*
|
||||
* @return \Symfony\Component\Routing\Route|null
|
||||
* The generated route, if available.
|
||||
*/
|
||||
protected function getSettingsFormRoute(EntityTypeInterface $entity_type) {
|
||||
if (!$entity_type->getBundleEntityType()) {
|
||||
$route = new Route("/admin/structure/{$entity_type->id()}/settings");
|
||||
$route
|
||||
->setDefaults([
|
||||
'_form' => 'Drupal\zencrm_entities\Form\HatSettingsForm',
|
||||
'_title' => "{$entity_type->getLabel()} settings",
|
||||
])
|
||||
->setRequirement('_permission', $entity_type->getAdminPermission())
|
||||
->setOption('_admin_route', TRUE);
|
||||
|
||||
return $route;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
40
modules/zencrm_entities/src/HatListBuilder.php
Normal file
40
modules/zencrm_entities/src/HatListBuilder.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities;
|
||||
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityListBuilder;
|
||||
use Drupal\Core\Link;
|
||||
|
||||
/**
|
||||
* Defines a class to build a listing of Hat entities.
|
||||
*
|
||||
* @ingroup zencrm_entities
|
||||
*/
|
||||
class HatListBuilder extends EntityListBuilder {
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildHeader() {
|
||||
$header['id'] = $this->t('Hat ID');
|
||||
$header['name'] = $this->t('Name');
|
||||
return $header + parent::buildHeader();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildRow(EntityInterface $entity) {
|
||||
/* @var $entity \Drupal\zencrm_entities\Entity\Hat */
|
||||
$row['id'] = $entity->id();
|
||||
$row['name'] = Link::createFromRoute(
|
||||
$entity->label(),
|
||||
'entity.hat.edit_form',
|
||||
['hat' => $entity->id()]
|
||||
);
|
||||
return $row + parent::buildRow($entity);
|
||||
}
|
||||
|
||||
}
|
14
modules/zencrm_entities/src/HatTranslationHandler.php
Normal file
14
modules/zencrm_entities/src/HatTranslationHandler.php
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities;
|
||||
|
||||
use Drupal\content_translation\ContentTranslationHandler;
|
||||
|
||||
/**
|
||||
* Defines the translation handler for hat.
|
||||
*/
|
||||
class HatTranslationHandler extends ContentTranslationHandler {
|
||||
|
||||
// Override here the needed methods from ContentTranslationHandler.
|
||||
|
||||
}
|
28
modules/zencrm_entities/src/HatTypeHtmlRouteProvider.php
Normal file
28
modules/zencrm_entities/src/HatTypeHtmlRouteProvider.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities;
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* Provides routes for Hat type entities.
|
||||
*
|
||||
* @see Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
|
||||
* @see Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
|
||||
*/
|
||||
class HatTypeHtmlRouteProvider extends AdminHtmlRouteProvider {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRoutes(EntityTypeInterface $entity_type) {
|
||||
$collection = parent::getRoutes($entity_type);
|
||||
|
||||
// Provide your custom entity routes here.
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
}
|
32
modules/zencrm_entities/src/HatTypeListBuilder.php
Normal file
32
modules/zencrm_entities/src/HatTypeListBuilder.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm_entities;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
|
||||
/**
|
||||
* Provides a listing of Hat type entities.
|
||||
*/
|
||||
class HatTypeListBuilder extends ConfigEntityListBuilder {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildHeader() {
|
||||
$header['label'] = $this->t('Hat type');
|
||||
$header['id'] = $this->t('Machine name');
|
||||
return $header + parent::buildHeader();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildRow(EntityInterface $entity) {
|
||||
$row['label'] = $entity->label();
|
||||
$row['id'] = $entity->id();
|
||||
// You probably want a few more properties here...
|
||||
return $row + parent::buildRow($entity);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
{#
|
||||
/**
|
||||
* @file
|
||||
* Default theme implementation to present a list of custom content entity types/bundles.
|
||||
*
|
||||
* Available variables:
|
||||
* - types: A collection of all the available custom entity types/bundles.
|
||||
* Each type/bundle contains the following:
|
||||
* - link: A link to add a content entity of this type.
|
||||
* - description: A description of this content entity types/bundle.
|
||||
*
|
||||
* @see template_preprocess_hat_content_add_list()
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
#}
|
||||
{% spaceless %}
|
||||
<dl>
|
||||
{% for type in types %}
|
||||
<dt>{{ type.link }}</dt>
|
||||
{% endfor %}
|
||||
</dl>
|
||||
{% endspaceless %}
|
22
modules/zencrm_entities/templates/hat.html.twig
Normal file
22
modules/zencrm_entities/templates/hat.html.twig
Normal file
@ -0,0 +1,22 @@
|
||||
{#
|
||||
/**
|
||||
* @file hat.html.twig
|
||||
* Default theme implementation to present Hat data.
|
||||
*
|
||||
* This template is used when viewing Hat pages.
|
||||
*
|
||||
*
|
||||
* Available variables:
|
||||
* - content: A list of content items. Use 'content' to print all content, or
|
||||
* - attributes: HTML attributes for the container element.
|
||||
*
|
||||
* @see template_preprocess_hat()
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
#}
|
||||
<div{{ attributes.addClass('hat') }}>
|
||||
{% if content %}
|
||||
{{- content -}}
|
||||
{% endif %}
|
||||
</div>
|
@ -3,16 +3,6 @@ entity.person.add_form:
|
||||
title: 'Add Person'
|
||||
appears_on:
|
||||
- entity.person.collection
|
||||
entity.profile.add_form:
|
||||
route_name: entity.profile.add_page
|
||||
title: 'Add Profile'
|
||||
appears_on:
|
||||
- entity.profile.collection
|
||||
entity.profile_type.add_form:
|
||||
route_name: entity.profile_type.add_form
|
||||
title: 'Add Profile type'
|
||||
appears_on:
|
||||
- entity.profile_type.collection
|
||||
|
||||
entity.contact_details.add_form:
|
||||
route_name: entity.contact_details.add_form
|
||||
@ -29,3 +19,14 @@ entity.contact_details.add_form:
|
||||
title: 'Add Contact details'
|
||||
appears_on:
|
||||
- entity.contact_details.collection
|
||||
entity.hat.add_form:
|
||||
route_name: entity.hat.add_page
|
||||
title: 'Add Hat'
|
||||
appears_on:
|
||||
- entity.hat.collection
|
||||
entity.hat_type.add_form:
|
||||
route_name: entity.hat_type.add_form
|
||||
title: 'Add Hat type'
|
||||
appears_on:
|
||||
- entity.hat_type.collection
|
||||
|
||||
|
@ -13,24 +13,6 @@ person.admin.structure.settings:
|
||||
route_name: person.settings
|
||||
parent: system.admin_structure
|
||||
|
||||
# Profile menu items definition
|
||||
entity.profile.collection:
|
||||
title: 'Profile list'
|
||||
route_name: entity.profile.collection
|
||||
description: 'List Profile entities'
|
||||
parent: system.admin_structure
|
||||
weight: 100
|
||||
|
||||
|
||||
# Profile type menu items definition
|
||||
entity.profile_type.collection:
|
||||
title: 'Profile type'
|
||||
route_name: entity.profile_type.collection
|
||||
description: 'List Profile type (bundles)'
|
||||
parent: system.admin_structure
|
||||
weight: 99
|
||||
|
||||
|
||||
# Contact Details menu items definition
|
||||
entity.contact_details.collection:
|
||||
title: 'Contact Details list'
|
||||
@ -72,3 +54,21 @@ contact_details.admin.structure.settings:
|
||||
description: 'Configure Contact details entities'
|
||||
route_name: contact_details.settings
|
||||
parent: system.admin_structure
|
||||
|
||||
# Hat menu items definition
|
||||
entity.hat.collection:
|
||||
title: 'Hat list'
|
||||
route_name: entity.hat.collection
|
||||
description: 'List Hat entities'
|
||||
parent: system.admin_structure
|
||||
weight: 100
|
||||
|
||||
|
||||
# Hat type menu items definition
|
||||
entity.hat_type.collection:
|
||||
title: 'Hat type'
|
||||
route_name: entity.hat_type.collection
|
||||
description: 'List Hat type (bundles)'
|
||||
parent: system.admin_structure
|
||||
weight: 99
|
||||
|
||||
|
@ -25,29 +25,6 @@ entity.person.delete_form:
|
||||
title: Delete
|
||||
weight: 10
|
||||
|
||||
# Profile routing definition
|
||||
|
||||
entity.profile.canonical:
|
||||
route_name: entity.profile.canonical
|
||||
base_route: entity.profile.canonical
|
||||
title: 'View'
|
||||
|
||||
entity.profile.edit_form:
|
||||
route_name: entity.profile.edit_form
|
||||
base_route: entity.profile.canonical
|
||||
title: 'Edit'
|
||||
|
||||
entity.profile.version_history:
|
||||
route_name: entity.profile.version_history
|
||||
base_route: entity.profile.canonical
|
||||
title: 'Revisions'
|
||||
|
||||
entity.profile.delete_form:
|
||||
route_name: entity.profile.delete_form
|
||||
base_route: entity.profile.canonical
|
||||
title: Delete
|
||||
weight: 10
|
||||
|
||||
# Contact Details routing definition
|
||||
contact_details.settings_tab:
|
||||
route_name: contact_details.settings
|
||||
@ -119,3 +96,21 @@ entity.contact_details.delete_form:
|
||||
title: Delete
|
||||
weight: 10
|
||||
|
||||
# Hat routing definition
|
||||
|
||||
entity.hat.canonical:
|
||||
route_name: entity.hat.canonical
|
||||
base_route: entity.hat.canonical
|
||||
title: 'View'
|
||||
|
||||
entity.hat.edit_form:
|
||||
route_name: entity.hat.edit_form
|
||||
base_route: entity.hat.canonical
|
||||
title: 'Edit'
|
||||
|
||||
entity.hat.delete_form:
|
||||
route_name: entity.hat.delete_form
|
||||
base_route: entity.hat.canonical
|
||||
title: Delete
|
||||
weight: 10
|
||||
|
||||
|
@ -29,9 +29,9 @@ function zencrm_entities_person_presave($entity) {
|
||||
/**
|
||||
* Implements hook_ENTITY_TYPE_presave().
|
||||
* Computes the name field from the full name of the referenced person
|
||||
* plus the profile type.
|
||||
* plus the hat type.
|
||||
*/
|
||||
function zencrm_entities_profile_presave($entity) {
|
||||
function zencrm_entities_hat_presave($entity) {
|
||||
$person_id = $entity->person->first()->getValue()['target_id'];
|
||||
$person = \Drupal\zencrm_entities\Entity\Person::load($person_id);
|
||||
$full_name = $person->full_name->getString();
|
||||
@ -64,15 +64,15 @@ function zencrm_entities_theme() {
|
||||
$theme['zencrm_entities'] = [
|
||||
'render element' => 'children',
|
||||
];
|
||||
$theme['profile'] = [
|
||||
$theme['hat'] = [
|
||||
'render element' => 'elements',
|
||||
'file' => 'profile.page.inc',
|
||||
'template' => 'profile',
|
||||
'file' => 'hat.page.inc',
|
||||
'template' => 'hat',
|
||||
];
|
||||
$theme['profile_content_add_list'] = [
|
||||
$theme['hat_content_add_list'] = [
|
||||
'render element' => 'content',
|
||||
'variables' => ['content' => NULL],
|
||||
'file' => 'profile.page.inc',
|
||||
'file' => 'hat.page.inc',
|
||||
];
|
||||
return $theme;
|
||||
}
|
||||
@ -80,15 +80,15 @@ function zencrm_entities_theme() {
|
||||
/**
|
||||
* Implements hook_theme_suggestions_HOOK().
|
||||
*/
|
||||
function zencrm_entities_theme_suggestions_profile(array $variables) {
|
||||
function zencrm_entities_theme_suggestions_hat(array $variables) {
|
||||
$suggestions = [];
|
||||
$entity = $variables['elements']['#profile'];
|
||||
$entity = $variables['elements']['#hat'];
|
||||
$sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
|
||||
|
||||
$suggestions[] = 'profile__' . $sanitized_view_mode;
|
||||
$suggestions[] = 'profile__' . $entity->bundle();
|
||||
$suggestions[] = 'profile__' . $entity->bundle() . '__' . $sanitized_view_mode;
|
||||
$suggestions[] = 'profile__' . $entity->id();
|
||||
$suggestions[] = 'profile__' . $entity->id() . '__' . $sanitized_view_mode;
|
||||
$suggestions[] = 'hat__' . $sanitized_view_mode;
|
||||
$suggestions[] = 'hat__' . $entity->bundle();
|
||||
$suggestions[] = 'hat__' . $entity->bundle() . '__' . $sanitized_view_mode;
|
||||
$suggestions[] = 'hat__' . $entity->id();
|
||||
$suggestions[] = 'hat__' . $entity->id() . '__' . $sanitized_view_mode;
|
||||
return $suggestions;
|
||||
}
|
||||
|
@ -28,36 +28,6 @@ revert all person revisions:
|
||||
delete all person revisions:
|
||||
title: 'Delete all revisions'
|
||||
description: 'Role requires permission to <em>view Person revisions</em> and <em>delete rights</em> for person entities in question or <em>administer person entities</em>.'
|
||||
add profile entities:
|
||||
title: 'Create new Profile entities'
|
||||
|
||||
administer profile entities:
|
||||
title: 'Administer Profile entities'
|
||||
description: 'Allow to access the administration form to configure Profile entities.'
|
||||
restrict access: true
|
||||
|
||||
delete profile entities:
|
||||
title: 'Delete Profile entities'
|
||||
|
||||
edit profile entities:
|
||||
title: 'Edit Profile entities'
|
||||
|
||||
view published profile entities:
|
||||
title: 'View published Profile entities'
|
||||
|
||||
view unpublished profile entities:
|
||||
title: 'View unpublished Profile entities'
|
||||
|
||||
view all profile revisions:
|
||||
title: 'View all Profile revisions'
|
||||
|
||||
revert all profile revisions:
|
||||
title: 'Revert all Profile revisions'
|
||||
description: 'Role requires permission <em>view Profile revisions</em> and <em>edit rights</em> for profile entities in question or <em>administer profile entities</em>.'
|
||||
|
||||
delete all profile revisions:
|
||||
title: 'Delete all revisions'
|
||||
description: 'Role requires permission to <em>view Profile revisions</em> and <em>delete rights</em> for profile entities in question or <em>administer profile entities</em>.'
|
||||
add contact details entities:
|
||||
title: 'Create new Contact Details entities'
|
||||
|
||||
@ -126,3 +96,23 @@ view published contact details entities:
|
||||
|
||||
view unpublished contact details entities:
|
||||
title: 'View unpublished Contact details entities'
|
||||
|
||||
add hat entities:
|
||||
title: 'Create new Hat entities'
|
||||
|
||||
administer hat entities:
|
||||
title: 'Administer Hat entities'
|
||||
description: 'Allow to access the administration form to configure Hat entities.'
|
||||
restrict access: true
|
||||
|
||||
delete hat entities:
|
||||
title: 'Delete Hat entities'
|
||||
|
||||
edit hat entities:
|
||||
title: 'Edit Hat entities'
|
||||
|
||||
view published hat entities:
|
||||
title: 'View published Hat entities'
|
||||
|
||||
view unpublished hat entities:
|
||||
title: 'View unpublished Hat entities'
|
||||
|
@ -5,9 +5,9 @@ namespace Drupal\zencrm\Controller;
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
|
||||
/**
|
||||
* Class ProfileController.
|
||||
* Class HatController.
|
||||
*/
|
||||
class ProfileController extends ControllerBase {
|
||||
class HatController extends ControllerBase {
|
||||
|
||||
/**
|
||||
* Hello.
|
||||
@ -15,18 +15,18 @@ class ProfileController extends ControllerBase {
|
||||
* @return string
|
||||
* Return Hello string.
|
||||
*/
|
||||
public function createProfileForPerson($type, $person_id) {
|
||||
public function createHatForPerson($type, $person_id) {
|
||||
$values = array(
|
||||
'type' => $type,
|
||||
'person' => $person_id
|
||||
);
|
||||
|
||||
$node = \Drupal::entityTypeManager()
|
||||
->getStorage('profile')
|
||||
->getStorage('hat')
|
||||
->create($values);
|
||||
|
||||
$form = \Drupal::entityTypeManager()
|
||||
->getFormObject('profile', 'default')
|
||||
->getFormObject('hat', 'default')
|
||||
->setEntity($node);
|
||||
return \Drupal::formBuilder()->getForm($form);
|
||||
}
|
@ -5,14 +5,14 @@ namespace Drupal\zencrm\Plugin\Block;
|
||||
use Drupal\Core\Block\BlockBase;
|
||||
|
||||
/**
|
||||
* Provides a 'ProfileCreator' block.
|
||||
* Provides a 'HatCreator' block.
|
||||
*
|
||||
* @Block(
|
||||
* id = "profile_creator",
|
||||
* admin_label = @Translation("Profile creator"),
|
||||
* id = "hat_creator",
|
||||
* admin_label = @Translation("Hat creator"),
|
||||
* )
|
||||
*/
|
||||
class ProfileCreator extends BlockBase {
|
||||
class HatCreator extends BlockBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@ -21,15 +21,15 @@ class ProfileCreator extends BlockBase {
|
||||
$person_id = \Drupal::routeMatch()->getParameter('person')->id();
|
||||
$markup = "";
|
||||
|
||||
// Only offer profile creation on profiles they don't already have.
|
||||
$profile_types = \Drupal::service('entity_type.bundle.info')->getBundleInfo('profile');
|
||||
foreach($profile_types as $id => $type) {
|
||||
$profiles = \Drupal::entityTypeManager()
|
||||
->getStorage('profile')
|
||||
// Only offer hat creation on hats they don't already have.
|
||||
$hat_types = \Drupal::service('entity_type.bundle.info')->getBundleInfo('hat');
|
||||
foreach($hat_types as $id => $type) {
|
||||
$hats = \Drupal::entityTypeManager()
|
||||
->getStorage('hat')
|
||||
->loadByProperties(['type' => $id, 'person' => $person_id]);
|
||||
if (!reset($profiles)) {
|
||||
if (!reset($hats)) {
|
||||
$label = $type['label'];
|
||||
$markup .= "<p><a class='use-ajax' data-dialog-type='modal' href='/zencrm/profile/add/$id/$person_id'>Create $label Profile</a></p>";
|
||||
$markup .= "<p><a class='use-ajax' data-dialog-type='modal' href='/zencrm/hat/add/$id/$person_id'>Create $label Hat</a></p>";
|
||||
}
|
||||
}
|
||||
return [
|
@ -1,7 +1,7 @@
|
||||
zencrm.profile.create:
|
||||
path: '/zencrm/profile/add/{type}/{person_id}'
|
||||
zencrm.hat.create:
|
||||
path: '/zencrm/hat/add/{type}/{person_id}'
|
||||
defaults:
|
||||
_controller: '\Drupal\zencrm\Controller\ProfileController::createProfileForPerson'
|
||||
_title: 'Add New Profile'
|
||||
_controller: '\Drupal\zencrm\Controller\HatController::createHatForPerson'
|
||||
_title: 'Add New Hat'
|
||||
requirements:
|
||||
_permission: 'access content'
|
||||
|
Reference in New Issue
Block a user