diff --git a/core/modules/workflows/src/Form/WorkflowStateAddForm.php b/core/modules/workflows/src/Form/WorkflowStateAddForm.php index 1827dd3..7b55995 100644 --- a/core/modules/workflows/src/Form/WorkflowStateAddForm.php +++ b/core/modules/workflows/src/Form/WorkflowStateAddForm.php @@ -5,6 +5,7 @@ use Drupal\Core\Entity\EntityForm; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\workflows\WorkflowTypeFormInterface; /** * Class WorkflowStateAddForm. @@ -43,10 +44,13 @@ public function form(array $form, FormStateInterface $form_state) { ]; // Add additional form fields from the workflow type plugin. - $form['type_settings'] = [ - $workflow->get('type') => $workflow->getTypePlugin()->buildStateConfigurationForm($form_state, $workflow), - '#tree' => TRUE, - ]; + $workflow_type = $workflow->getTypePlugin(); + if ($workflow_type instanceof WorkflowTypeFormInterface) { + $form['type_settings'] = [ + $workflow->get('type') => $workflow_type->buildStateConfigurationForm($form_state, $workflow), + '#tree' => TRUE, + ]; + } return $form; } diff --git a/core/modules/workflows/src/Form/WorkflowStateEditForm.php b/core/modules/workflows/src/Form/WorkflowStateEditForm.php index f21508f..d87cb64 100644 --- a/core/modules/workflows/src/Form/WorkflowStateEditForm.php +++ b/core/modules/workflows/src/Form/WorkflowStateEditForm.php @@ -6,6 +6,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; +use Drupal\workflows\WorkflowTypeFormInterface; /** * Class WorkflowStateEditForm. @@ -62,10 +63,13 @@ public function form(array $form, FormStateInterface $form_state) { ]; // Add additional form fields from the workflow type plugin. - $form['type_settings'] = [ - $workflow->get('type') => $workflow->getTypePlugin()->buildStateConfigurationForm($form_state, $workflow, $state), - '#tree' => TRUE, - ]; + $workflow_type = $workflow->getTypePlugin(); + if ($workflow_type instanceof WorkflowTypeFormInterface) { + $form['type_settings'] = [ + $workflow->get('type') => $workflow_type->buildStateConfigurationForm($form_state, $workflow, $state), + '#tree' => TRUE, + ]; + } $header = [ 'label' => $this->t('Transition'), diff --git a/core/modules/workflows/src/Form/WorkflowTransitionAddForm.php b/core/modules/workflows/src/Form/WorkflowTransitionAddForm.php index fe3a406..4761f58 100644 --- a/core/modules/workflows/src/Form/WorkflowTransitionAddForm.php +++ b/core/modules/workflows/src/Form/WorkflowTransitionAddForm.php @@ -6,6 +6,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\workflows\State; +use Drupal\workflows\WorkflowTypeFormInterface; /** * Class WorkflowTransitionAddForm. @@ -62,10 +63,13 @@ public function form(array $form, FormStateInterface $form_state) { ]; // Add additional form fields from the workflow type plugin. - $form['type_settings'] = [ - $workflow->get('type') => $workflow->getTypePlugin()->buildTransitionConfigurationForm($form_state, $workflow), - '#tree' => TRUE, - ]; + $workflow_type = $workflow->getTypePlugin(); + if ($workflow_type instanceof WorkflowTypeFormInterface) { + $form['type_settings'] = [ + $workflow->get('type') => $workflow_type->buildTransitionConfigurationForm($form_state, $workflow), + '#tree' => TRUE, + ]; + } return $form; } diff --git a/core/modules/workflows/src/Form/WorkflowTransitionEditForm.php b/core/modules/workflows/src/Form/WorkflowTransitionEditForm.php index 5bbabae..1fbc0a2 100644 --- a/core/modules/workflows/src/Form/WorkflowTransitionEditForm.php +++ b/core/modules/workflows/src/Form/WorkflowTransitionEditForm.php @@ -7,6 +7,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; use Drupal\workflows\State; +use Drupal\workflows\WorkflowTypeFormInterface; /** * Class WorkflowTransitionEditForm. @@ -78,10 +79,13 @@ public function form(array $form, FormStateInterface $form_state) { ]; // Add additional form fields from the workflow type plugin. - $form['type_settings'] = [ - $workflow->get('type') => $workflow->getTypePlugin()->buildTransitionConfigurationForm($form_state, $workflow, $transition), - '#tree' => TRUE, - ]; + $workflow_type = $workflow->getTypePlugin(); + if ($workflow_type instanceof WorkflowTypeFormInterface) { + $form['type_settings'] = [ + $workflow->get('type') => $workflow_type->buildTransitionConfigurationForm($form_state, $workflow, $transition), + '#tree' => TRUE, + ]; + } return $form; } diff --git a/core/modules/workflows/src/Plugin/WorkflowTypeBase.php b/core/modules/workflows/src/Plugin/WorkflowTypeBase.php index 34af735..66702d0 100644 --- a/core/modules/workflows/src/Plugin/WorkflowTypeBase.php +++ b/core/modules/workflows/src/Plugin/WorkflowTypeBase.php @@ -86,20 +86,6 @@ public function deleteTransition($transition_id) { /** * {@inheritdoc} */ - public function buildStateConfigurationForm(FormStateInterface $form_state, WorkflowInterface $workflow, StateInterface $state = NULL) { - return []; - } - - /** - * {@inheritdoc} - */ - public function buildTransitionConfigurationForm(FormStateInterface $form_state, WorkflowInterface $workflow, TransitionInterface $transition = NULL) { - return []; - } - - /** - * {@inheritdoc} - */ public function getConfiguration() { return $this->configuration; } diff --git a/core/modules/workflows/src/Plugin/WorkflowTypeFormBase.php b/core/modules/workflows/src/Plugin/WorkflowTypeFormBase.php index 942c2d6..69f0e8c 100644 --- a/core/modules/workflows/src/Plugin/WorkflowTypeFormBase.php +++ b/core/modules/workflows/src/Plugin/WorkflowTypeFormBase.php @@ -3,6 +3,9 @@ namespace Drupal\workflows\Plugin; use Drupal\Core\Form\FormStateInterface; +use Drupal\workflows\StateInterface; +use Drupal\workflows\TransitionInterface; +use Drupal\workflows\WorkflowInterface; use Drupal\workflows\WorkflowTypeFormInterface; /** @@ -27,4 +30,18 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { } + /** + * {@inheritdoc} + */ + public function buildStateConfigurationForm(FormStateInterface $form_state, WorkflowInterface $workflow, StateInterface $state = NULL) { + return []; + } + + /** + * {@inheritdoc} + */ + public function buildTransitionConfigurationForm(FormStateInterface $form_state, WorkflowInterface $workflow, TransitionInterface $transition = NULL) { + return []; + } + } diff --git a/core/modules/workflows/src/WorkflowTypeFormInterface.php b/core/modules/workflows/src/WorkflowTypeFormInterface.php index 7da4bd9..d5c957b 100644 --- a/core/modules/workflows/src/WorkflowTypeFormInterface.php +++ b/core/modules/workflows/src/WorkflowTypeFormInterface.php @@ -2,6 +2,7 @@ namespace Drupal\workflows; +use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginFormInterface; /** @@ -13,4 +14,44 @@ * @see plugin_api */ interface WorkflowTypeFormInterface extends PluginFormInterface, WorkflowTypeInterface { + + /** + * Builds a form to be added to the Workflow state edit form. + * + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The form state. + * @param \Drupal\workflows\WorkflowInterface $workflow + * The workflow the state is attached to. + * @param \Drupal\workflows\StateInterface|null $state + * The workflow state being edited. If NULL, a new state is being added. + * + * @return array + * Form elements to add to a workflow state form for customisations to the + * workflow. + * + * @see \Drupal\workflows\Form\WorkflowStateAddForm::form() + * @see \Drupal\workflows\Form\WorkflowStateEditForm::form() + */ + public function buildStateConfigurationForm(FormStateInterface $form_state, WorkflowInterface $workflow, StateInterface $state = NULL); + + /** + * Builds a form to be added to the Workflow transition edit form. + * + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The form state. + * @param \Drupal\workflows\WorkflowInterface $workflow + * The workflow the state is attached to. + * @param \Drupal\workflows\TransitionInterface|null $transition + * The workflow transition being edited. If NULL, a new transition is being + * added. + * + * @return array + * Form elements to add to a workflow transition form for customisations to + * the workflow. + * + * @see \Drupal\workflows\Form\WorkflowTransitionAddForm::form() + * @see \Drupal\workflows\Form\WorkflowTransitionEditForm::form() + */ + public function buildTransitionConfigurationForm(FormStateInterface $form_state, WorkflowInterface $workflow, TransitionInterface $transition = NULL); + } diff --git a/core/modules/workflows/src/WorkflowTypeInterface.php b/core/modules/workflows/src/WorkflowTypeInterface.php index 2412bf9..7519cb1 100644 --- a/core/modules/workflows/src/WorkflowTypeInterface.php +++ b/core/modules/workflows/src/WorkflowTypeInterface.php @@ -105,45 +105,6 @@ public function deleteTransition($transition_id); public function getInitialState(WorkflowInterface $workflow); /** - * Builds a form to be added to the Workflow state edit form. - * - * @param \Drupal\Core\Form\FormStateInterface $form_state - * The form state. - * @param \Drupal\workflows\WorkflowInterface $workflow - * The workflow the state is attached to. - * @param \Drupal\workflows\StateInterface|null $state - * The workflow state being edited. If NULL, a new state is being added. - * - * @return array - * Form elements to add to a workflow state form for customisations to the - * workflow. - * - * @see \Drupal\workflows\Form\WorkflowStateAddForm::form() - * @see \Drupal\workflows\Form\WorkflowStateEditForm::form() - */ - public function buildStateConfigurationForm(FormStateInterface $form_state, WorkflowInterface $workflow, StateInterface $state = NULL); - - /** - * Builds a form to be added to the Workflow transition edit form. - * - * @param \Drupal\Core\Form\FormStateInterface $form_state - * The form state. - * @param \Drupal\workflows\WorkflowInterface $workflow - * The workflow the state is attached to. - * @param \Drupal\workflows\TransitionInterface|null $transition - * The workflow transition being edited. If NULL, a new transition is being - * added. - * - * @return array - * Form elements to add to a workflow transition form for customisations to - * the workflow. - * - * @see \Drupal\workflows\Form\WorkflowTransitionAddForm::form() - * @see \Drupal\workflows\Form\WorkflowTransitionEditForm::form() - */ - public function buildTransitionConfigurationForm(FormStateInterface $form_state, WorkflowInterface $workflow, TransitionInterface $transition = NULL); - - /** * Gets the required states of workflow type. * * This are usually configured in the workflow type annotation. diff --git a/core/modules/workflows/tests/modules/workflow_type_test/src/Plugin/WorkflowType/TestType.php b/core/modules/workflows/tests/modules/workflow_type_test/src/Plugin/WorkflowType/TestType.php index 2ff68a8..6b35266 100644 --- a/core/modules/workflows/tests/modules/workflow_type_test/src/Plugin/WorkflowType/TestType.php +++ b/core/modules/workflows/tests/modules/workflow_type_test/src/Plugin/WorkflowType/TestType.php @@ -2,6 +2,7 @@ namespace Drupal\workflow_type_test\Plugin\WorkflowType; +use Drupal\Core\Form\FormStateInterface; use Drupal\workflows\Plugin\WorkflowTypeBase; /**