diff --git a/core/lib/Drupal/Core/Entity/EntityNGConfirmFormBase.php b/core/lib/Drupal/Core/Entity/EntityNGConfirmFormBase.php index fd04241..0a7bedd 100644 --- a/core/lib/Drupal/Core/Entity/EntityNGConfirmFormBase.php +++ b/core/lib/Drupal/Core/Entity/EntityNGConfirmFormBase.php @@ -78,6 +78,14 @@ public function buildForm(array $form, array &$form_state, Request $request = NU /** * {@inheritdoc} */ + public function form(array $form, array &$form_state) { + // Do not attach fields to the confirm form. + return $form; + } + + /** + * {@inheritdoc} + */ protected function init(array &$form_state) { parent::init($form_state); diff --git a/core/modules/block/custom_block/custom_block.module b/core/modules/block/custom_block/custom_block.module index 0af9077..20d20ad 100644 --- a/core/modules/block/custom_block/custom_block.module +++ b/core/modules/block/custom_block/custom_block.module @@ -121,14 +121,10 @@ function custom_block_menu() { ); $items['block/%custom_block/delete'] = array( 'title' => 'Delete', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('custom_block_delete_form', 1), - 'access callback' => 'entity_page_access', - 'access arguments' => array(1, 'delete'), 'weight' => 1, 'type' => MENU_LOCAL_TASK, 'context' => MENU_CONTEXT_INLINE, - 'file' => 'custom_block.pages.inc', + 'route_name' => 'custom_block_delete', ); return $items; } diff --git a/core/modules/block/custom_block/custom_block.pages.inc b/core/modules/block/custom_block/custom_block.pages.inc index e50b297..a164c46 100644 --- a/core/modules/block/custom_block/custom_block.pages.inc +++ b/core/modules/block/custom_block/custom_block.pages.inc @@ -36,49 +36,3 @@ function template_preprocess_custom_block_add_list(&$variables) { } } -/** - * Page callback: Form constructor for the custom block deletion form. - * - * @param Drupal\custom_block\Plugin\Core\Entity\CustomBlock $block - * The custom block to be deleted. - * - * @see custom_block_menu() - * @see custom_block_delete_form_submit() - * - * @ingroup forms - */ -function custom_block_delete_form($form, &$form_state, CustomBlock $block) { - $form_state['custom_block'] = $block; - $form['id'] = array( - '#type' => 'value', - '#value' => $block->id(), - ); - - $instances = $block->getInstances(); - - $form['message'] = array( - '#markup' => format_plural(count($instances), 'This will also remove 1 placed block instance.', 'This will also remove @count placed block instances.'), - '#access' => !empty($instances), - ); - - return confirm_form( - $form, - t('Are you sure you want to delete %label?', array('%label' => $block->label())), - 'admin/structure/block', - t('This action cannot be undone.'), - t('Delete') - ); -} - -/** - * Form submission handler for custom_block_delete_form(). - */ -function custom_block_delete_form_submit($form, &$form_state) { - $block = $form_state['custom_block']; - $block->delete(); - - drupal_set_message(t('Custom block %label has been deleted.', array('%label' => $block->label()))); - watchdog('custom_block', 'Custom block %label has been deleted.', array('%label' => $block->label()), WATCHDOG_NOTICE); - - $form_state['redirect'] = 'admin/structure/custom-blocks'; -} diff --git a/core/modules/block/custom_block/custom_block.routing.yml b/core/modules/block/custom_block/custom_block.routing.yml index 52e1575..ac3cf6e 100644 --- a/core/modules/block/custom_block/custom_block.routing.yml +++ b/core/modules/block/custom_block/custom_block.routing.yml @@ -34,6 +34,13 @@ custom_block_edit: _entity_access: 'custom_block.update' custom_block: \d+ +custom_block_delete: + pattern: '/block/{custom_block}/delete' + defaults: + _entity_form: 'custom_block.delete' + requirements: + _entity_access: 'custom_block.delete' + custom_block_type_add: pattern: '/admin/structure/custom-blocks/types/add' defaults: diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Form/CustomBlockDeleteForm.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Form/CustomBlockDeleteForm.php new file mode 100644 index 0000000..e295487 --- /dev/null +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Form/CustomBlockDeleteForm.php @@ -0,0 +1,65 @@ + $this->entity->label())); + } + + /** + * {@inheritdoc} + */ + public function getCancelPath() { + return 'admin/structure/block'; + } + + /** + * {@inheritdoc} + */ + public function getConfirmText() { + return t('Delete'); + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, array &$form_state, Request $request = NULL) { + $form = parent::buildForm($form, $form_state, $request); + $instances = $this->entity->getInstances(); + + $form['message'] = array( + '#type' => 'markup', + '#markup' => format_plural(count($instances), 'This will also remove 1 placed block instance.', 'This will also remove @count placed block instances.'), + '#access' => !empty($instances), + ); + + return $form; + } + + /** + * {@inheritdoc} + */ + public function submit(array $form, array &$form_state) { + $this->entity->delete(); + drupal_set_message(t('Custom block %label has been deleted.', array('%label' => $this->entity->label()))); + watchdog('custom_block', 'Custom block %label has been deleted.', array('%label' => $this->entity->label()), WATCHDOG_NOTICE); + $form_state['redirect'] = 'admin/structure/custom-blocks'; + } + +} diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlock.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlock.php index 97722f6..fbe7d19 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlock.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlock.php @@ -29,6 +29,7 @@ * "form" = { * "add" = "Drupal\custom_block\CustomBlockFormController", * "edit" = "Drupal\custom_block\CustomBlockFormController", + * "delete" = "Drupal\custom_block\Form\CustomBlockDeleteForm", * "default" = "Drupal\custom_block\CustomBlockFormController" * }, * "translation" = "Drupal\custom_block\CustomBlockTranslationController" diff --git a/core/modules/node/lib/Drupal/node/Form/NodeDeleteForm.php b/core/modules/node/lib/Drupal/node/Form/NodeDeleteForm.php index 5a3fdb0..5b65da7 100644 --- a/core/modules/node/lib/Drupal/node/Form/NodeDeleteForm.php +++ b/core/modules/node/lib/Drupal/node/Form/NodeDeleteForm.php @@ -87,14 +87,6 @@ public function getConfirmText() { /** * {@inheritdoc} */ - public function form(array $form, array &$form_state) { - // Do not attach fields to the delete form. - return $form; - } - - /** - * {@inheritdoc} - */ public function submit(array $form, array &$form_state) { $this->entity->delete(); watchdog('content', '@type: deleted %title.', array('@type' => $this->entity->bundle(), '%title' => $this->entity->label()));