Profile labels now read "First Name Last Name - Profile Type"

This commit is contained in:
naomi 2018-04-06 15:34:03 +02:00
parent 4a49cfecfb
commit 3128d0cabf
3 changed files with 19 additions and 19 deletions

View File

@ -208,11 +208,13 @@ class Person extends RevisionableContentEntityBase implements PersonInterface {
]) ])
->setTranslatable(TRUE); ->setTranslatable(TRUE);
// This field is computed in a presave hook.
$fields['full_name'] = BaseFieldDefinition::create('string') $fields['full_name'] = BaseFieldDefinition::create('string')
->setLabel(t('Full Name')) ->setLabel(t('Full Name'))
->setDescription(t('The full name of the person.')) ->setDescription(t('The full name of the person.'))
->setRevisionable(TRUE); ->setRevisionable(TRUE);
// This field is computed in a presave hook.
$fields['first_and_last_name'] = BaseFieldDefinition::create('string') $fields['first_and_last_name'] = BaseFieldDefinition::create('string')
->setLabel(t('First and Last Name')) ->setLabel(t('First and Last Name'))
->setDescription(t('The first and last name of the person. Used for searching and autocomplete')) ->setDescription(t('The first and last name of the person. Used for searching and autocomplete'))

View File

@ -253,27 +253,11 @@ class Profile extends RevisionableContentEntityBase implements ProfileInterface
'weight' => 0, 'weight' => 0,
]); ]);
// This field is computed in a presave hook.
$fields['name'] = BaseFieldDefinition::create('string') $fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name')) ->setLabel(t('Name'))
->setDescription(t('The name of the Profile entity.')) ->setDescription(t('The name of this profile instance.'))
->setRevisionable(TRUE) ->setRevisionable(TRUE);
->setSettings([
'max_length' => 50,
'text_processing' => 0,
])
->setDefaultValue('')
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'string',
'weight' => -4,
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => -4,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE)
->setRequired(TRUE);
$fields['status'] = BaseFieldDefinition::create('boolean') $fields['status'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Publishing status')) ->setLabel(t('Publishing status'))

View File

@ -26,6 +26,20 @@ 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.
*/
function zencrm_entities_profile_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();
$bundle_name = $entity->type->entity->label();
$entity->set('name', $full_name . ' - ' . $bundle_name);
}
/** /**
* Implements hook_help(). * Implements hook_help().
*/ */