function PageContext::getBadgeLabel

Retrieves the badge label for the given entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for which the label is being retrieved.

Return value

string|null The translated status if available. NULL otherwise. The status if available. NULL otherwise.

1 call to PageContext::getBadgeLabel()
PageContext::build in core/modules/navigation/src/Plugin/TopBarItem/PageContext.php
Builds and returns the renderable array for this top bar item plugin.

File

core/modules/navigation/src/Plugin/TopBarItem/PageContext.php, line 128

Class

PageContext
Provides the Page Context top bar item.

Namespace

Drupal\navigation\Plugin\TopBarItem

Code

protected function getBadgeLabel(EntityInterface $entity) : ?string {
  if ($entity instanceof ContentEntityInterface && $this->moderationInformation && $this->moderationInformation
    ->isModeratedEntity($entity)) {
    $state_label = $this->moderationInformation
      ->getWorkflowForEntity($entity)
      ->getTypePlugin()
      ->getState($entity->get('moderation_state')->value)
      ->label();
    if ($this->moderationInformation
      ->hasPendingRevision($entity) && $entity->isDefaultRevision()) {
      $active_revision = $this->entityRepository
        ->getActive($entity->getEntityTypeId(), $entity->id());
      $active_state_label = $this->moderationInformation
        ->getWorkflowForEntity($entity)
        ->getTypePlugin()
        ->getState($active_revision->get('moderation_state')->value)
        ->label();
      $state_label = $this->t('@state_label (@active_state_label available)', [
        '@state_label' => $state_label,
        '@active_state_label' => $active_state_label,
      ]);
    }
    return (string) $state_label;
  }
  if (!$entity instanceof EntityPublishedInterface) {
    return NULL;
  }
  return (string) ($entity->isPublished() ? $this->t('Published') : $this->t('Unpublished'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.