diff --git a/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php b/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php index 7e3d512..71213ee 100644 --- a/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php +++ b/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php @@ -4,7 +4,7 @@ use Drupal\content_moderation\ModerationInformationInterface; use Drupal\Core\Access\AccessResult; -use Drupal\Core\Entity\EntityTypeManager; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Session\AccountInterface; @@ -35,7 +35,7 @@ class ContentModeration extends WorkflowTypeBase implements ContainerFactoryPlug protected $entityTypeManager; /** - * The Moderation Information service. + * The moderation information service. * * @var \Drupal\content_moderation\ModerationInformationInterface */ @@ -55,7 +55,7 @@ class ContentModeration extends WorkflowTypeBase implements ContainerFactoryPlug * @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) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, ModerationInformationInterface $moderation_info) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->entityTypeManager = $entity_type_manager; $this->moderationInfo = $moderation_info; @@ -226,33 +226,35 @@ public function editForm(WorkflowInterface $workflow) { foreach ($entity_types as $entity_type) { if ($this->moderationInfo->canModerateEntitiesOfEntityType($entity_type)) { $form['attachments'][$entity_type->id()] = [ - '#markup' => $entity_type->getLabel()->render(), + '#type' => 'checkboxes', + '#title' => $entity_type->getLabel()->render(), + '#options' => [], ]; - + $defaults = []; $bundles = $this->entityTypeManager->getStorage($entity_type->getBundleEntityType())->loadMultiple(); foreach ($bundles as $bundle) { - $form['attachments'][$entity_type->id()][$bundle->id()] = [ - '#type' => 'checkbox', - '#title' => $bundle->label(), - '#default_value' => $this->appliesToEntityTypeAndBundle($entity_type->id(), $bundle->id()), - ]; + $form['attachments'][$entity_type->id()]['#options'][$bundle->id()] = $bundle->label(); + $defaults[$bundle->id()] = $this->appliesToEntityTypeAndBundle($entity_type->id(), $bundle->id()); } + $form['attachments'][$entity_type->id()]['#default_value'] = array_keys(array_filter($defaults)); } } return $form; } + /** + * {@inheritdoc} + */ public function editFormSave(WorkflowInterface &$workflow, array $form, FormStateInterface $formState) { + $type_plugin = $workflow->getTypePlugin(); foreach ($formState->getValues()['attachments'] as $entity_type_id => $bundle_ids) { foreach ($bundle_ids as $bundle_id => $checked) { if ($checked) { - $workflow->getTypePlugin() - ->addEntityTypeAndBundle($entity_type_id, $bundle_id); + $type_plugin->addEntityTypeAndBundle($entity_type_id, $bundle_id); } else { - $workflow->getTypePlugin() - ->removeEntityTypeAndBundle($entity_type_id, $bundle_id); + $type_plugin->removeEntityTypeAndBundle($entity_type_id, $bundle_id); } } } diff --git a/core/modules/workflows/src/WorkflowTypeInterface.php b/core/modules/workflows/src/WorkflowTypeInterface.php index 97c3d65..01c4b92 100644 --- a/core/modules/workflows/src/WorkflowTypeInterface.php +++ b/core/modules/workflows/src/WorkflowTypeInterface.php @@ -118,12 +118,13 @@ public function buildStateConfigurationForm(FormStateInterface $form_state, Work public function buildTransitionConfigurationForm(FormStateInterface $form_state, WorkflowInterface $workflow, TransitionInterface $transition = NULL); /** - * Returns a form array to append to the Workflow entity edit form for - * workflow type specific settings. + * Returns a form array to append to the Workflow entity edit form. * * @param \Drupal\workflows\WorkflowInterface $workflow + * THe workflow the form will be added to. * * @return array + * A form array to be used for type specific workflow settings. * * @see \Drupal\workflows\Form\WorkflowTransitionEditForm::form() */ @@ -133,8 +134,12 @@ public function editForm(WorkflowInterface $workflow); * Save workflow type specific settings. * * @param \Drupal\workflows\WorkflowInterface $workflow + * The workflow the submitting form was added to. * @param array $form + * The form array that was submitted. * @param \Drupal\Core\Form\FormStateInterface $form_state + * The form state for the submitted form. */ public function editFormSave(WorkflowInterface &$workflow, array $form, FormStateInterface $form_state); + }