You are here

class EntityFieldDeriver in Context entity field 8

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

Hierarchy

Expanded class hierarchy of EntityFieldDeriver

File

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

Namespace

Drupal\context_entity_field\Plugin\Deriver
View source
class EntityFieldDeriver extends EntityBundle {

  /**
   * Provides the bundle label with a fallback when not defined.
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
   *   The entity type we are looking the bundle label for.
   *
   * @return \Drupal\Core\StringTranslation\TranslatableMarkup
   *   The entity bundle label or a fallback label.
   */
  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,
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
EntityBundle::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
EntityDeriverBase::$entityFieldManager protected property The entity field manager.
EntityDeriverBase::$entityTypeManager protected property The entity type manager.
EntityDeriverBase::$entityTypeRepository protected property The entity type repository.
EntityDeriverBase::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
EntityDeriverBase::__construct public function Constructs new EntityViewDeriver.
EntityFieldDeriver::getEntityBundleLabel protected function Provides the bundle label with a fallback when not defined. Overrides EntityBundle::getEntityBundleLabel
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.