You are here

public function BackgroundImage::label in Background Image 2.0.x

Same name and namespace in other branches
  1. 8 src/Entity/BackgroundImage.php \Drupal\background_image\Entity\BackgroundImage::label()
  2. 2.x src/Entity/BackgroundImage.php \Drupal\background_image\Entity\BackgroundImage::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

1 call to BackgroundImage::label()
BackgroundImage::getTypeLabel in src/Entity/BackgroundImage.php
The type label.

File

src/Entity/BackgroundImage.php, line 645

Class

BackgroundImage
Defines the Background Image entity.

Namespace

Drupal\background_image\Entity

Code

public function label($link = FALSE) {
  if ($entity = $this
    ->getTargetEntity()) {
    return $this
      ->t('%entity_type (@entity_id): @entity_label', [
      '%entity_type' => $this
        ->getBackgroundImageManager()
        ->getEntityBundleLabel($entity) ?: $entity
        ->getEntityType()
        ->getLabel(),
      '@entity_label' => $link ? $entity
        ->toLink()
        ->toString() : $entity
        ->label(),
      '@entity_id' => $entity
        ->id(),
    ]);
  }
  else {
    if ($entity_bundle = $this
      ->getTargetEntityBundle()) {
      if ($entity_bundle instanceof EntityInterface) {
        return $this
          ->t('%entity_type (@entity_id): @entity_label', [
          '%entity_type' => $entity_bundle
            ->getEntityType()
            ->getLabel(),
          '@entity_label' => $link && $entity_bundle
            ->hasLinkTemplate('edit-form') ? $entity_bundle
            ->toLink(NULL, 'edit-form')
            ->toString() : $entity_bundle
            ->label(),
          '@entity_id' => $entity_bundle
            ->id(),
        ]);
      }
      else {
        if ($entity_bundle instanceof EntityTypeInterface) {
          return $this
            ->t('%entity_type (@entity_id)', [
            '%entity_type' => $entity_bundle
              ->getLabel(),
            '@entity_id' => $entity_bundle
              ->id(),
          ]);
        }
      }
    }
    else {
      if ($view = $this
        ->getTargetView()) {
        $executable = $view
          ->getExecutable();
        $display = $executable
          ->getDisplay();
        $path = FALSE;
        if ($display
          ->hasPath()) {
          $path = '/' . $display
            ->getPath();
          if ($view
            ->status() && strpos($path, '%') === FALSE) {
            $path = Link::fromTextAndUrl($path, Url::fromUserInput($path));
          }
        }
        return $this
          ->t('View (@entity_id): @entity_label', [
          '@entity_label' => $link && $path ? $path : $view
            ->label(),
          '@entity_id' => "{$view->id()}:{$executable->current_display}",
        ]);
      }
    }
  }
  $label = parent::label();
  return isset($label) ? trim($label) : NULL;
}