diff --git a/core/modules/content_moderation/content_moderation.module b/core/modules/content_moderation/content_moderation.module index 3686710313..7161d21d3b 100644 --- a/core/modules/content_moderation/content_moderation.module +++ b/core/modules/content_moderation/content_moderation.module @@ -243,11 +243,3 @@ function content_moderation_workflow_insert(WorkflowInterface $entity) { function content_moderation_workflow_update(WorkflowInterface $entity) { content_moderation_workflow_insert($entity); } - -/** - * Implements hook_entity_type_build(). - */ -function content_moderation_entity_type_build(array &$entity_types) { - /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ - $entity_types['workflow']->setFormClass('edit-type', WorkflowTypeEditForm::class); -} diff --git a/core/modules/content_moderation/content_moderation.routing.yml b/core/modules/content_moderation/content_moderation.routing.yml index 3fa3a2e9b0..5154b5ea78 100644 --- a/core/modules/content_moderation/content_moderation.routing.yml +++ b/core/modules/content_moderation/content_moderation.routing.yml @@ -1,7 +1,7 @@ entity.workflow.edit_type_form: path: '/admin/config/workflow/workflows/manage/{workflow}/type/{entity_type}' defaults: - _entity_form: 'workflow.edit-type' + _form: '\Drupal\content_moderation\Form\WorkflowTypeEditForm' _title: 'Add / remove type' requirements: - _entity_access: 'workflow.edit' + _permission: 'administer workflows' diff --git a/core/modules/content_moderation/src/Form/WorkflowTypeEditForm.php b/core/modules/content_moderation/src/Form/WorkflowTypeEditForm.php index 98466963f4..1af0ac0ea7 100644 --- a/core/modules/content_moderation/src/Form/WorkflowTypeEditForm.php +++ b/core/modules/content_moderation/src/Form/WorkflowTypeEditForm.php @@ -6,15 +6,23 @@ use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\CloseDialogCommand; use Drupal\Core\Ajax\HtmlCommand; -use Drupal\Core\Entity\EntityForm; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * The form for editing entity types associated with a workflow. */ -class WorkflowTypeEditForm extends EntityForm { +class WorkflowTypeEditForm extends FormBase { + + /** + * The entity type manager service. + * + * @var \Drupal\Core\Entity\EntityTypeManagerInterface + */ + protected $entityTypeManager; /** * The entity type bundle information service. @@ -49,6 +57,7 @@ class WorkflowTypeEditForm extends EntityForm { */ public static function create(ContainerInterface $container) { return new static( + $container->get('entity_type.manager'), $container->get('entity_type.bundle.info'), $container->get('content_moderation.moderation_information') ); @@ -57,7 +66,8 @@ public static function create(ContainerInterface $container) { /** * {@inheritdoc} */ - public function __construct(EntityTypeBundleInfoInterface $bundle_info , ModerationInformationInterface $moderation_information) { + public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $bundle_info , ModerationInformationInterface $moderation_information) { + $this->entityTypeManager = $entity_type_manager; $this->bundleInfo = $bundle_info; $this->moderationInformation = $moderation_information; } @@ -65,17 +75,16 @@ public function __construct(EntityTypeBundleInfoInterface $bundle_info , Moderat /** * {@inheritdoc} */ - public function buildForm(array $form, FormStateInterface $form_state, $workflow = NULL, $entity_type = NULL) { - $this->workflow = $workflow; - $this->entityType = $this->entityTypeManager->getDefinition($entity_type); - return parent::buildForm($form, $form_state); + public function getFormId() { + return 'workflow_type_edit_form'; } /** * {@inheritdoc} */ - public function form(array $form, FormStateInterface $form_state) { - $form = parent::form($form, $form_state); + public function buildForm(array $form, FormStateInterface $form_state, $workflow = NULL, $entity_type = NULL) { + $this->workflow = $this->entityTypeManager->getStorage('workflow')->load($workflow); + $this->entityType = $this->entityTypeManager->getDefinition($entity_type); $options = []; $defaults =[]; @@ -103,21 +112,24 @@ public function form(array $form, FormStateInterface $form_state) { ]; } - return $form; - } - - /** - * {@inheritdoc} - */ - public function actions(array $form, FormStateInterface $form_state) { - $actions['submit'] = [ + $form['actions'] = ['#type' => 'actions']; + $form['actions']['submit'] = [ '#type' => 'submit', + '#button_type' => 'primary', '#value' => $this->t('Save'), '#ajax' => [ - 'callback' => [$this, 'ajaxSave'], + 'callback' => [$this, 'ajaxcallback'], + ], + ]; + $form['actions']['cancel'] = [ + '#type' => 'button', + '#value' => $this->t('Cancel'), + '#ajax' => [ + 'callback' => [$this, 'ajaxcallback'], ], ]; - return $actions; + + return $form; } /** @@ -138,15 +150,10 @@ public function submitForm(array &$form, FormStateInterface $form_state) { /** * Ajax callback. * - * @param array $form - * The form array. - * @param \Drupal\Core\Form\FormStateInterface $form_state - * The form state object. - * * @return \Drupal\Core\Ajax\AjaxResponse * An ajax response object. */ - public function ajaxSave(array $form, FormStateInterface $form_state) { + public function ajaxcallback() { $selected_bundles = []; foreach (\Drupal::service('entity_type.bundle.info')->getBundleInfo($this->entityType->id()) as $bundle_id => $bundle) { if ($this->workflow->getTypePlugin()->appliesToEntityTypeAndBundle($this->entityType->id(), $bundle_id)) {