You are here

protected function ContributorName::updateContributorEntity in Bibliography & Citation 8

Same name and namespace in other branches
  1. 2.0.x modules/bibcite_entity/src/ContributorName.php \Drupal\bibcite_entity\ContributorName::updateContributorEntity()

Updates name parts of the bibcite_contributor entity.

Parameters

string $name: Full name string.

2 calls to ContributorName::updateContributorEntity()
ContributorName::onChange in modules/bibcite_entity/src/ContributorName.php
React to changes to a child property or item.
ContributorName::setValue in modules/bibcite_entity/src/ContributorName.php
Sets the data value.

File

modules/bibcite_entity/src/ContributorName.php, line 109

Class

ContributorName
Contributor name computed field.

Namespace

Drupal\bibcite_entity

Code

protected function updateContributorEntity($name) {

  /** @var \Drupal\bibcite_entity\Entity\Contributor $entity */
  $entity = $this
    ->getEntity();
  if ($name) {
    $name_parts = \Drupal::service('bibcite.human_name_parser')
      ->parse($name);

    // Explicitly map name parts. Entity fields names and keys returned by
    // the name parser do not have to be the same.
    $entity->prefix = $name_parts['prefix'];
    $entity->leading_title = $name_parts['leading_title'];
    $entity->first_name = $name_parts['first_name'];
    $entity->middle_name = $name_parts['middle_name'];
    $entity->last_name = $name_parts['last_name'];
    $entity->nick = $name_parts['nick'];
    $entity->suffix = $name_parts['suffix'];
  }
  else {
    $part_value = $name === '' ? '' : NULL;
    foreach ($entity::getNameParts() as $name_part) {
      $entity
        ->set($name_part, $part_value);
    }
  }
}