diff --git a/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php b/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php index b5ff27bb14..7e3d51237b 100644 --- a/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php +++ b/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php @@ -2,14 +2,18 @@ namespace Drupal\content_moderation\Plugin\WorkflowType; +use Drupal\content_moderation\ModerationInformationInterface; use Drupal\Core\Access\AccessResult; +use Drupal\Core\Entity\EntityTypeManager; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\content_moderation\ContentModerationState; use Drupal\workflows\Plugin\WorkflowTypeBase; use Drupal\workflows\StateInterface; use Drupal\workflows\WorkflowInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Attaches workflows to content entity types and their bundles. @@ -19,11 +23,58 @@ * label = @Translation("Content moderation"), * ) */ -class ContentModeration extends WorkflowTypeBase { +class ContentModeration extends WorkflowTypeBase implements ContainerFactoryPluginInterface { use StringTranslationTrait; /** + * The entity type manager. + * + * @var \Drupal\Core\Entity\EntityTypeManagerInterface + */ + protected $entityTypeManager; + + /** + * The Moderation Information service. + * + * @var \Drupal\content_moderation\ModerationInformationInterface + */ + protected $moderationInfo; + + /** + * Constructs an ContentModeration object. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin_id for the plugin instance. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager + * The entity type manager. + * @param \Drupal\content_moderation\ModerationInformationInterface $moderation_info + * Moderation information service. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManager $entity_type_manager, ModerationInformationInterface $moderation_info) { + parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->entityTypeManager = $entity_type_manager; + $this->moderationInfo = $moderation_info; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('entity_type.manager'), + $container->get('content_moderation.moderation_information') + ); + } + + /** * {@inheritdoc} */ public function checkWorkflowAccess(WorkflowInterface $entity, $operation, AccountInterface $account) { @@ -171,16 +222,14 @@ public function editForm(WorkflowInterface $workflow) { '#tree' => TRUE, ]; - $entity_type_manager = \Drupal::entityTypeManager(); - $entity_types = $entity_type_manager->getDefinitions(); + $entity_types = $this->entityTypeManager->getDefinitions(); foreach ($entity_types as $entity_type) { - if (\Drupal::service('content_moderation.moderation_information')->canModerateEntitiesOfEntityType($entity_type)) { + if ($this->moderationInfo->canModerateEntitiesOfEntityType($entity_type)) { $form['attachments'][$entity_type->id()] = [ - '#type' => 'checkboxes', - '#title' => $entity_type->getLabel()->render(), + '#markup' => $entity_type->getLabel()->render(), ]; - $bundles = $entity_type_manager->getStorage($entity_type->getBundleEntityType())->loadMultiple(); + $bundles = $this->entityTypeManager->getStorage($entity_type->getBundleEntityType())->loadMultiple(); foreach ($bundles as $bundle) { $form['attachments'][$entity_type->id()][$bundle->id()] = [ '#type' => 'checkbox',