You are here

protected function AutoEntityLabelManager::generateLabel in Automatic Entity Label 8

Same name and namespace in other branches
  1. 8.3 src/AutoEntityLabelManager.php \Drupal\auto_entitylabel\AutoEntityLabelManager::generateLabel()
  2. 8.2 src/AutoEntityLabelManager.php \Drupal\auto_entitylabel\AutoEntityLabelManager::generateLabel()

Generates the label according to the settings.

@codingStandardsIgnoreStart

Parameters

string $pattern: Label pattern. May contain tokens.

\Drupal\Core\Entity\ContentEntityInterface $entity: Content entity.

Return value

string A label string

1 call to AutoEntityLabelManager::generateLabel()
AutoEntityLabelManager::setLabel in src/AutoEntityLabelManager.php
Sets the automatically generated entity label.

File

src/AutoEntityLabelManager.php, line 238

Class

AutoEntityLabelManager
AutoEntityLabelManager class.

Namespace

Drupal\auto_entitylabel

Code

protected function generateLabel($pattern, $entity) {

  // @codingStandardsIgnoreEnd
  $entity_type = $entity
    ->getEntityType()
    ->id();
  $output = $this->token
    ->replace($pattern, [
    $entity_type => $entity,
  ], [
    'sanitize' => FALSE,
    'clear' => TRUE,
  ]);

  // Evaluate PHP.
  if ($this
    ->getConfig('php')) {
    $output = $this
      ->evalLabel($output, $this->entity);
  }

  // Strip tags.
  $output = preg_replace('/[\\t\\n\\r\\0\\x0B]/', '', strip_tags($output));
  return $output;
}