You are here

protected function EntityFieldDeriver::getEntityBundleLabel in Context entity field 8

Provides the bundle label with a fallback when not defined.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type we are looking the bundle label for.

Return value

\Drupal\Core\StringTranslation\TranslatableMarkup The entity bundle label or a fallback label.

Overrides EntityBundle::getEntityBundleLabel

File

src/Plugin/Deriver/EntityFieldDeriver.php, line 21

Class

EntityFieldDeriver
Deriver that creates a condition for each entity type with bundles.

Namespace

Drupal\context_entity_field\Plugin\Deriver

Code

protected function getEntityBundleLabel($entity_type) {
  if ($label = $entity_type
    ->getBundleLabel()) {
    return $this
      ->t('@label field', [
      '@label' => $label,
    ]);
  }
  $fallback = $entity_type
    ->getLabel();
  if ($bundle_entity_type = $entity_type
    ->getBundleEntityType()) {

    // This is a better fallback.
    $fallback = $this->entityTypeManager
      ->getDefinition($bundle_entity_type)
      ->getLabel();
  }
  return $this
    ->t('@label bundle field', [
    '@label' => $fallback,
  ]);
}