EntityBundle.php in Chaos Tool Suite (ctools) 8.3
File
src/Plugin/Deriver/EntityBundle.php
View source
<?php
namespace Drupal\ctools\Plugin\Deriver;
use Drupal\Core\Plugin\Context\EntityContextDefinition;
class EntityBundle extends EntityDeriverBase {
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;
}
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()) {
$fallback = $this->entityTypeManager
->getDefinition($bundle_entity_type)
->getLabel();
}
return $this
->t('@label bundle', [
'@label' => $fallback,
]);
}
}
Classes
Name |
Description |
EntityBundle |
Deriver that creates a condition for each entity type with bundles. |