diff --git a/core/lib/Drupal/Core/Entity/Plugin/Condition/Deriver/EntityBundle.php b/core/lib/Drupal/Core/Entity/Plugin/Condition/Deriver/EntityBundle.php index e9b6a75..b2c100b 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/Condition/Deriver/EntityBundle.php +++ b/core/lib/Drupal/Core/Entity/Plugin/Condition/Deriver/EntityBundle.php @@ -26,10 +26,10 @@ class EntityBundle extends DeriverBase implements ContainerDeriverInterface { protected $entityTypeManager; /** - * Constructs new EntityViewDeriver. + * Constructs a new EntityBundle. * * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity manager. + * The entity type manager. * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation * The string translation service. */ @@ -43,7 +43,7 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, Tra */ public static function create(ContainerInterface $container, $base_plugin_id) { return new static( - $container->get('entity.manager'), + $container->get('entity_type.manager'), $container->get('string_translation') ); } @@ -53,7 +53,7 @@ public static function create(ContainerInterface $container, $base_plugin_id) { */ public function getDerivativeDefinitions($base_plugin_definition) { foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { - if ($this->useEntityType($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'] = [ @@ -73,35 +73,17 @@ public function getDerivativeDefinitions($base_plugin_definition) { * @return \Drupal\Core\StringTranslation\TranslatableMarkup * The entity bundle label or a fallback label. */ - protected function getEntityBundleLabel($entity_type) { + protected function getEntityBundleLabel(EntityTypeInterface $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(); + $fallback = $this->entityTypeManager->getDefinition($bundle_entity_type)->getLabel(); } return $this->t('@label bundle', ['@label' => $fallback]); } - /** - * Determines if an entity type should be used to make a derivative. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $enity_type - * The entity type. - * @return bool - * True if the entity type should be used. - */ - protected function useEntityType(EntityTypeInterface $entity_type) { - if ($entity_type->hasKey('bundle')) { - $links = $entity_type->getLinkTemplates(); - // Only use if canonical link exists and is not the same as the edit form. - return !empty($links['canonical']) && (empty($links['edit-form']) || $links['canonical'] != $links['edit-form']); - } - return FALSE; - } - } diff --git a/core/lib/Drupal/Core/Entity/Plugin/Condition/EntityBundle.php b/core/lib/Drupal/Core/Entity/Plugin/Condition/EntityBundle.php index 8b91888..42734db 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/Condition/EntityBundle.php +++ b/core/lib/Drupal/Core/Entity/Plugin/Condition/EntityBundle.php @@ -14,7 +14,7 @@ * * @Condition( * id = "entity_bundle", - * deriver = "\Drupal\Core\Entity\Plugin\Condition\Deriver\EntityBundle" + * deriver = "\Drupal\Core\Entity\Plugin\Condition\Deriver\EntityBundle", * ) */ class EntityBundle extends ConditionPluginBase implements ContainerFactoryPluginInterface { @@ -27,9 +27,11 @@ class EntityBundle extends ConditionPluginBase implements ContainerFactoryPlugin protected $entityTypeBundleInfo; /** - * @var \Drupal\Core\Entity\EntityTypeInterface|null + * The entity type containing the bundles. + * + * @var \Drupal\Core\Entity\EntityTypeInterface */ - protected $bundleOf; + protected $entityType; /** * Creates a new EntityBundle instance. @@ -51,7 +53,7 @@ class EntityBundle extends ConditionPluginBase implements ContainerFactoryPlugin public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, array $configuration, $plugin_id, $plugin_definition) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->entityTypeBundleInfo = $entity_type_bundle_info; - $this->bundleOf = $entity_type_manager->getDefinition($this->getDerivativeId()); + $this->entityType = $entity_type_manager->getDefinition($this->getDerivativeId()); } /** @@ -72,7 +74,7 @@ public static function create(ContainerInterface $container, array $configuratio */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $options = []; - $bundles = $this->entityTypeBundleInfo->getBundleInfo($this->bundleOf->id()); + $bundles = $this->entityTypeBundleInfo->getBundleInfo($this->entityType->id()); foreach ($bundles as $id => $info) { $options[$id] = $info['label']; } @@ -101,7 +103,7 @@ public function evaluate() { return TRUE; } /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ - $entity = $this->getContextValue($this->bundleOf->id()); + $entity = $this->getContextValue($this->entityType->id()); return !empty($this->configuration['bundles'][$entity->bundle()]); } @@ -114,14 +116,14 @@ public function summary() { $last = array_pop($bundles); $bundles = implode(', ', $bundles); return $this->t('@bundle_type is @bundles or @last', [ - '@bundle_type' => $this->bundleOf->getBundleLabel(), + '@bundle_type' => $this->entityType->getBundleLabel(), '@bundles' => $bundles, '@last' => $last, ]); } $bundle = reset($this->configuration['bundles']); return $this->t('@bundle_type is @bundle', [ - '@bundle_type' => $this->bundleOf->getBundleLabel(), + '@bundle_type' => $this->entityType->getBundleLabel(), '@bundle' => $bundle, ]); }