diff --git a/core/modules/block/custom_block/custom_block.module b/core/modules/block/custom_block/custom_block.module index 0a3efde..a35b5ef 100644 --- a/core/modules/block/custom_block/custom_block.module +++ b/core/modules/block/custom_block/custom_block.module @@ -90,14 +90,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 f6c4076..77f2245 100644 --- a/core/modules/block/custom_block/custom_block.pages.inc +++ b/core/modules/block/custom_block/custom_block.pages.inc @@ -45,49 +45,3 @@ function custom_block_edit(CustomBlock $block) { return Drupal::entityManager()->getForm($block); } -/** - * 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/block'; -} diff --git a/core/modules/block/custom_block/custom_block.routing.yml b/core/modules/block/custom_block/custom_block.routing.yml index 2178d91..1d692b1 100644 --- a/core/modules/block/custom_block/custom_block.routing.yml +++ b/core/modules/block/custom_block/custom_block.routing.yml @@ -25,3 +25,10 @@ custom_block_type_delete: _entity_form: 'custom_block_type.delete' requirements: _permission: 'administer blocks' + +custom_block_delete: + pattern: '/block/{custom_block}/delete' + defaults: + _form: '\Drupal\custom_block\Form\CustomBlockDeleteForm' + requirements: + _entity_access: 'custom_block.delete' 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..3088f45 --- /dev/null +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Form/CustomBlockDeleteForm.php @@ -0,0 +1,83 @@ + $this->block->label())); + } + + /** + * {@inheritdoc} + */ + protected function getCancelPath() { + return 'admin/structure/block'; + } + + /** + * {@inheritdoc} + */ + protected function getConfirmText() { + return t('Delete'); + } + + /** + * {@inheritdoc} + * + * @param \Drupal\custom_block\Plugin\Core\Entity\CustomBlock $custom_block + * The custom block entity. + */ + public function buildForm(array $form, array &$form_state, CustomBlock $custom_block = NULL) { + $this->block = $custom_block; + $form = parent::buildForm($form, $form_state); + $instances = $custom_block->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 submitForm(array &$form, array &$form_state) { + $this->block->delete(); + drupal_set_message(t('Custom block %label has been deleted.', array('%label' => $this->block->label()))); + watchdog('custom_block', 'Custom block %label has been deleted.', array('%label' => $this->block->label()), WATCHDOG_NOTICE); + $form_state['redirect'] = 'admin/structure/block'; + } + +}