class EntityBundle in Chaos Tool Suite (ctools) 8.3
Same name in this branch
- 8.3 src/Plugin/Deriver/EntityBundle.php \Drupal\ctools\Plugin\Deriver\EntityBundle
- 8.3 src/Plugin/Condition/EntityBundle.php \Drupal\ctools\Plugin\Condition\EntityBundle
Deriver that creates a condition for each entity type with bundles.
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\ctools\Plugin\Deriver\EntityDeriverBase implements ContainerDeriverInterface uses StringTranslationTrait
- class \Drupal\ctools\Plugin\Deriver\EntityBundle
- class \Drupal\ctools\Plugin\Deriver\EntityDeriverBase implements ContainerDeriverInterface uses StringTranslationTrait
Expanded class hierarchy of EntityBundle
File
- src/
Plugin/ Deriver/ EntityBundle.php, line 10
Namespace
Drupal\ctools\Plugin\DeriverView source
class EntityBundle extends EntityDeriverBase {
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type
->hasKey('bundle')) {
$this->derivatives[$entity_type_id] = $base_plugin_definition;
$this->derivatives[$entity_type_id]['label'] = $this
->getEntityBundleLabel($entity_type);
$this->derivatives[$entity_type_id]['context_definitions'] = [
"{$entity_type_id}" => new EntityContextDefinition('entity:' . $entity_type_id),
];
}
}
return $this->derivatives;
}
/**
* 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', [
'@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', [
'@label' => $fallback,
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeriverBase:: |
protected | property | List of derivative definitions. | 1 |
DeriverBase:: |
public | function |
Gets the definition of a derivative plugin. Overrides DeriverInterface:: |
|
EntityBundle:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
|
EntityBundle:: |
protected | function | Provides the bundle label with a fallback when not defined. | |
EntityDeriverBase:: |
protected | property | The entity field manager. | |
EntityDeriverBase:: |
protected | property | The entity type manager. | |
EntityDeriverBase:: |
protected | property | The entity type repository. | |
EntityDeriverBase:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
|
EntityDeriverBase:: |
public | function | Constructs new EntityViewDeriver. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |