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);
// This field is computed in a presave hook.
$fields['full_name'] = BaseFieldDefinition::create('string')
->setLabel(t('Full Name'))
->setDescription(t('The full name of the person.'))
->setRevisionable(TRUE);
// This field is computed in a presave hook.
$fields['first_and_last_name'] = BaseFieldDefinition::create('string')
->setLabel(t('First and Last Name'))
->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,
]);
// This field is computed in a presave hook.
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('The name of the Profile entity.'))
->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);
->setDescription(t('The name of this profile instance.'))
->setRevisionable(TRUE);
$fields['status'] = BaseFieldDefinition::create('boolean')
->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().
*/