You are here

protected function ContributorName::computeValue 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::computeValue()

Computes the values for an item list.

Overrides ComputedItemListTrait::computeValue

1 call to ContributorName::computeValue()
ContributorName::ensureComputedValue in modules/bibcite_entity/src/ContributorName.php
Compute values every time.

File

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

Class

ContributorName
Contributor name computed field.

Namespace

Drupal\bibcite_entity

Code

protected function computeValue() {

  /** @var \Drupal\bibcite_entity\Entity\ContributorInterface $contributor */
  $contributor = $this->parent
    ->getValue();
  $arguments = [];
  foreach ($contributor::getNameParts() as $part) {
    $arguments["@{$part}"] = $contributor
      ->get($part)->value;
  }

  // @todo Dependency injection.
  $format = \Drupal::config('bibcite_entity.contributor.settings')
    ->get('full_name_pattern') ?: '@prefix @first_name @last_name @suffix';
  $full_name = strtr($format, $arguments);
  $value = trim(preg_replace('/\\s+/', ' ', $full_name));
  $this->list[0] = $this
    ->createItem(0, $value);
}