diff --git a/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php b/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php index e61f25e..b5ff27b 100644 --- a/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php +++ b/core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php @@ -145,7 +145,7 @@ public function addEntityTypeAndBundle($entity_type_id, $bundle_id) { } /** - * {@inheritDoc} + * {@inheritdoc} */ public function defaultConfiguration() { // This plugin does not store anything per transition. @@ -156,11 +156,57 @@ public function defaultConfiguration() { } /** - * @inheritDoc + * {@inheritdoc} */ public function calculateDependencies() { // @todo : Implement calculateDependencies() method. return []; } + public function editForm(WorkflowInterface $workflow) { + $form['attachments'] = [ + '#type' => 'details', + '#title' => $this->t('Select types to use this workflow'), + '#open' => TRUE, + '#tree' => TRUE, + ]; + + $entity_type_manager = \Drupal::entityTypeManager(); + $entity_types = $entity_type_manager->getDefinitions(); + foreach ($entity_types as $entity_type) { + if (\Drupal::service('content_moderation.moderation_information')->canModerateEntitiesOfEntityType($entity_type)) { + $form['attachments'][$entity_type->id()] = [ + '#type' => 'checkboxes', + '#title' => $entity_type->getLabel()->render(), + ]; + + $bundles = $entity_type_manager->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()), + ]; + } + } + } + + return $form; + } + + public function editFormSave(WorkflowInterface &$workflow, array $form, FormStateInterface $formState) { + 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); + } + else { + $workflow->getTypePlugin() + ->removeEntityTypeAndBundle($entity_type_id, $bundle_id); + } + } + } + } + } diff --git a/core/modules/workflows/src/Form/WorkflowEditForm.php b/core/modules/workflows/src/Form/WorkflowEditForm.php index d8f99f9..8d2e398 100644 --- a/core/modules/workflows/src/Form/WorkflowEditForm.php +++ b/core/modules/workflows/src/Form/WorkflowEditForm.php @@ -179,6 +179,8 @@ public function form(array $form, FormStateInterface $form_state) { '#markup' => $workflow->toLink($this->t('Add a new transition'), 'add-transition-form')->toString(), ]; + $form += $workflow->getTypePlugin()->editForm($workflow); + return $form; } @@ -188,6 +190,7 @@ public function form(array $form, FormStateInterface $form_state) { public function save(array $form, FormStateInterface $form_state) { /* @var \Drupal\workflows\WorkflowInterface $workflow */ $workflow = $this->entity; + $workflow->getTypePlugin()->editFormSave($workflow, $form, $form_state); $workflow->save(); drupal_set_message($this->t('Saved the %label Workflow.', ['%label' => $workflow->label()])); $form_state->setRedirectUrl($workflow->toUrl('collection')); diff --git a/core/modules/workflows/src/Plugin/WorkflowTypeBase.php b/core/modules/workflows/src/Plugin/WorkflowTypeBase.php index 1ed9fca..5f303fc 100644 --- a/core/modules/workflows/src/Plugin/WorkflowTypeBase.php +++ b/core/modules/workflows/src/Plugin/WorkflowTypeBase.php @@ -49,28 +49,28 @@ public function checkWorkflowAccess(WorkflowInterface $entity, $operation, Accou } /** - * {@inheritDoc} + * {@inheritdoc} */ public function decorateState(StateInterface $state) { return $state; } /** - * {@inheritDoc} + * {@inheritdoc} */ public function deleteState($state_id) { unset($this->configuration['states'][$state_id]); } /** - * {@inheritDoc} + * {@inheritdoc} */ public function decorateTransition(TransitionInterface $transition) { return $transition; } /** - * {@inheritDoc} + * {@inheritdoc} */ public function deleteTransition($transition_id) { unset($this->configuration['transitions'][$transition_id]); @@ -91,14 +91,14 @@ public function buildTransitionConfigurationForm(FormStateInterface $form_state, } /** - * {@inheritDoc} + * {@inheritdoc} */ public function getConfiguration() { return $this->configuration; } /** - * {@inheritDoc} + * {@inheritdoc} */ public function setConfiguration(array $configuration) { $this->configuration = NestedArray::mergeDeep( @@ -108,7 +108,7 @@ public function setConfiguration(array $configuration) { } /** - * {@inheritDoc} + * {@inheritdoc} */ public function defaultConfiguration() { return [ @@ -118,10 +118,24 @@ public function defaultConfiguration() { } /** - * {@inheritDoc} + * {@inheritdoc} */ public function calculateDependencies() { return []; } + + /** + * {@inheritdoc} + */ + public function editForm(WorkflowInterface $workflow) { + return []; + } + + /** + * {@inheritdoc} + */ + public function editFormSave(WorkflowInterface &$workflow, array $form, FormStateInterface $form_state) { + + } } diff --git a/core/modules/workflows/src/WorkflowTypeInterface.php b/core/modules/workflows/src/WorkflowTypeInterface.php index 17fddec..97c3d65 100644 --- a/core/modules/workflows/src/WorkflowTypeInterface.php +++ b/core/modules/workflows/src/WorkflowTypeInterface.php @@ -117,4 +117,24 @@ 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. + * + * @param \Drupal\workflows\WorkflowInterface $workflow + * + * @return array + * + * @see \Drupal\workflows\Form\WorkflowTransitionEditForm::form() + */ + public function editForm(WorkflowInterface $workflow); + + /** + * Save workflow type specific settings. + * + * @param \Drupal\workflows\WorkflowInterface $workflow + * @param array $form + * @param \Drupal\Core\Form\FormStateInterface $form_state + */ + public function editFormSave(WorkflowInterface &$workflow, array $form, FormStateInterface $form_state); }