You are here

public function Registrant::label in RNG - Events and Registrations 3.x

Same name and namespace in other branches
  1. 8.2 src/Entity/Registrant.php \Drupal\rng\Entity\Registrant::label()
  2. 8 src/Entity/Registrant.php \Drupal\rng\Entity\Registrant::label()

Gets the label of the entity.

Return value

string|null The label of the entity, or NULL if there is no label defined.

Overrides ContentEntityBase::label

File

src/Entity/Registrant.php, line 181

Class

Registrant
Defines the registrant entity class.

Namespace

Drupal\rng\Entity

Code

public function label() {
  $identity = $this
    ->getIdentity();
  if ($identity) {
    return t('@type @id', [
      '@type' => $identity
        ->getEntityTypeId(),
      '@id' => $identity
        ->label(),
    ]);
  }
  $registration = $this
    ->getRegistration();
  $pattern = $this->type->entity->label_pattern;
  if (!empty($pattern)) {
    $label = \Drupal::token()
      ->replace($pattern, [
      'registrant' => $this,
      'registration' => $registration,
    ]);
    if (!empty(trim($label))) {
      if (strstr($label, '[') != FALSE) {
        return t(' ');
      }
      return $label;
    }
  }
  if ($registration) {
    return $registration
      ->label();
  }
  return t('New registrant');
}