diff --git a/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php b/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php index 52c6571..c21954a 100644 --- a/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php +++ b/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php @@ -4,6 +4,7 @@ use Drupal\content_moderation\ModerationInformationInterface; use Drupal\Core\Access\AccessResult; +use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -11,7 +12,6 @@ use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\content_moderation\ContentModerationState; use Drupal\workflows\Plugin\ConfigurableWorkflowTypeBase; -use Drupal\workflows\Plugin\WorkflowTypeBase; use Drupal\workflows\StateInterface; use Drupal\workflows\WorkflowInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -36,6 +36,13 @@ class ContentModeration extends ConfigurableWorkflowTypeBase implements Containe protected $entityTypeManager; /** + * The entity type bundle info service. + * + * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface + */ + protected $entityTypeBundleInfo; + + /** * The moderation information service. * * @var \Drupal\content_moderation\ModerationInformationInterface @@ -56,9 +63,10 @@ class ContentModeration extends ConfigurableWorkflowTypeBase implements Containe * @param \Drupal\content_moderation\ModerationInformationInterface $moderation_info * Moderation information service. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, ModerationInformationInterface $moderation_info) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, ModerationInformationInterface $moderation_info) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->entityTypeManager = $entity_type_manager; + $this->entityTypeBundleInfo = $entity_type_bundle_info; $this->moderationInfo = $moderation_info; } @@ -71,6 +79,7 @@ public static function create(ContainerInterface $container, array $configuratio $plugin_id, $plugin_definition, $container->get('entity_type.manager'), + $container->get('entity_type.bundle.info'), $container->get('content_moderation.moderation_information') ); } @@ -231,36 +240,24 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $entity_types = $this->entityTypeManager->getDefinitions(); foreach ($entity_types as $entity_type) { - if ($this->moderationInfo->canModerateEntitiesOfEntityType($entity_type)) { - $options = []; - $defaults = []; - if ($entity_type->getBundleEntityType()) { - $bundles = $this->entityTypeManager->getStorage($entity_type->getBundleEntityType()) - ->loadMultiple(); - foreach ($bundles as $bundle) { - if (!$this->moderationInfo->shouldModerateEntitiesOfBundle($entity_type, $bundle->id()) || $this->appliesToEntityTypeAndBundle($entity_type->id(), $bundle->id())) { - $options[$bundle->id()] = $bundle->label(); - $defaults[$bundle->id()] = $this->appliesToEntityTypeAndBundle($entity_type->id(), $bundle->id()); - } - } - } - else { - if (!$this->moderationInfo->shouldModerateEntitiesOfBundle($entity_type, $entity_type->id()) || $this->appliesToEntityTypeAndBundle($entity_type->id(), $entity_type->id())) { - $options[$entity_type->id()] = $entity_type->getLabel(); - $defaults[$entity_type->id()] = $this->appliesToEntityTypeAndBundle($entity_type->id(), $entity_type->id()); - } - } + if (!$this->moderationInfo->canModerateEntitiesOfEntityType($entity_type)) { + continue; + } - if (!empty($options)) { - $form['attachments'][$entity_type->id()] = [ - '#type' => 'checkboxes', - '#title' => $entity_type->getLabel()->render(), - '#options' => $options, - '#default_value' => array_keys(array_filter($defaults)), - ]; - } + $options = []; + $defaults = []; + foreach ($this->entityTypeBundleInfo->getBundleInfo($entity_type->id()) as $bundle_id => $bundle) { + $options[$bundle_id] = $bundle['label']; + $defaults[$bundle_id] = $this->appliesToEntityTypeAndBundle($entity_type->id(), $bundle_id); } + $form['attachments'][$entity_type->id()] = [ + '#type' => 'checkboxes', + '#title' => $entity_type->getLabel(), + '#options' => $options, + '#default_value' => array_keys(array_filter($defaults)), + ]; } + return $form; }