You are here

public function Reference::generateCitekey in Bibliography & Citation 8

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

Generate citekey by pattern.

Return value

string Generated citekey.

Throws

\Drupal\Core\TypedData\Exception\MissingDataException

Overrides ReferenceInterface::generateCitekey

File

modules/bibcite_entity/src/Entity/Reference.php, line 461

Class

Reference
Defines the Reference entity.

Namespace

Drupal\bibcite_entity\Entity

Code

public function generateCitekey() {
  $pattern = '';
  $type_storage = $this
    ->entityTypeManager()
    ->getStorage('bibcite_reference_type');

  /** @var \Drupal\bibcite_entity\Entity\ReferenceTypeInterface $bundle */
  $bundle = $type_storage
    ->load($this
    ->bundle());
  if ($bundle && !($pattern = $bundle
    ->getCitekeyPattern())) {

    // Fallback to global pattern if it's not configured on bundle level.
    $pattern = \Drupal::config('bibcite_entity.reference.settings')
      ->get('citekey.pattern');
  }
  return \Drupal::token()
    ->replace($pattern, [
    'bibcite_reference' => $this,
  ]);
}