diff --git a/core/modules/block/custom_block/custom_block.admin.inc b/core/modules/block/custom_block/custom_block.admin.inc index 02a0767..8cb5c8c 100644 --- a/core/modules/block/custom_block/custom_block.admin.inc +++ b/core/modules/block/custom_block/custom_block.admin.inc @@ -34,53 +34,3 @@ function custom_block_type_add() { function custom_block_type_edit(CustomBlockType $block_type) { return Drupal::entityManager()->getForm($block_type); } - -/** - * Page callback: Form constructor for the custom block type deletion form. - * - * @param \Drupal\custom_block\Plugin\Core\Entity\CustomBlockType $block_type - * The custom block type to be deleted. - * - * @see custom_block_menu() - * @see custom_block_type_delete_form_submit() - * - * @ingroup forms - */ -function custom_block_type_delete_form($form, &$form_state, CustomBlockType $block_type) { - $form_state['custom_block_type'] = $block_type; - $form['id'] = array( - '#type' => 'value', - '#value' => $block_type->id(), - ); - - $message = t('Are you sure you want to delete %label?', array('%label' => $block_type->label())); - - $blocks = Drupal::entityQuery('custom_block')->condition('type', $block_type->id())->execute(); - if (!empty($blocks)) { - drupal_set_title($message, PASS_THROUGH); - $caption = '
' . format_plural(count($blocks), '%label is used by 1 custom block on your site. You can not remove this block type until you have removed all of the %label blocks.', '%label is used by @count custom blocks on your site. You may not remove %label until you have removed all of the %label custom blocks.', array('%label' => $block_type->label())) . '
'; - $form['description'] = array('#markup' => $caption); - return $form; - } - - return confirm_form( - $form, - $message, - 'admin/structure/custom-blocks', - t('This action cannot be undone.'), - t('Delete') - ); -} - -/** - * Form submission handler for custom_block_type_delete_form(). - */ -function custom_block_type_delete_form_submit($form, &$form_state) { - $block_type = $form_state['custom_block_type']; - $block_type->delete(); - - drupal_set_message(t('Custom block type %label has been deleted.', array('%label' => $block_type->label()))); - watchdog('custom_block', 'Custom block type %label has been deleted.', array('%label' => $block_type->label()), WATCHDOG_NOTICE); - - $form_state['redirect'] = 'admin/structure/custom-blocks'; -} diff --git a/core/modules/block/custom_block/custom_block.module b/core/modules/block/custom_block/custom_block.module index e290cd4..0a3efde 100644 --- a/core/modules/block/custom_block/custom_block.module +++ b/core/modules/block/custom_block/custom_block.module @@ -60,14 +60,10 @@ function custom_block_menu() { ); $items['admin/structure/custom-blocks/manage/%custom_block_type/delete'] = array( 'title' => 'Delete', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('custom_block_type_delete_form', 4), - 'access arguments' => array('administer blocks'), 'type' => MENU_LOCAL_TASK, 'weight' => 10, - 'file' => 'custom_block.admin.inc', + 'route_name' => 'custom_block_type_delete', ); - $items['block/add'] = array( 'title' => 'Add custom block', 'route_name' => 'custom_block_add_page', diff --git a/core/modules/block/custom_block/custom_block.routing.yml b/core/modules/block/custom_block/custom_block.routing.yml index 9faf150..2178d91 100644 --- a/core/modules/block/custom_block/custom_block.routing.yml +++ b/core/modules/block/custom_block/custom_block.routing.yml @@ -18,3 +18,10 @@ custom_block_add_form: _content: 'Drupal\custom_block\Controller\CustomBlockController::addForm' requirements: _permission: 'administer blocks' + +custom_block_type_delete: + pattern: '/admin/structure/custom-blocks/manage/{custom_block_type}/delete' + defaults: + _entity_form: 'custom_block_type.delete' + requirements: + _permission: 'administer blocks' diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Form/CustomBlockTypeDeleteForm.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Form/CustomBlockTypeDeleteForm.php new file mode 100644 index 0000000..9db5b1d --- /dev/null +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Form/CustomBlockTypeDeleteForm.php @@ -0,0 +1,93 @@ +queryFactory = $query_factory; + } + + /** + * {@inheritdoc} + */ + public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) { + return new static( + $container->get('entity.query') + ); + } + + /** + * {@inheritdoc} + */ + public function getQuestion() { + return t('Are you sure you want to delete %label?', array('%label' => $this->entity->label())); + } + + /** + * {@inheritdoc} + */ + public function getCancelPath() { + return 'admin/structure/custom-blocks'; + } + + /** + * {@inheritdoc} + */ + public function getConfirmText() { + return t('Delete'); + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, array &$form_state, Request $request = NULL) { + $blocks = $this->queryFactory->get('custom_block')->condition('type', $this->entity->id())->execute(); + if (!empty($blocks)) { + $caption = '' . format_plural(count($blocks), '%label is used by 1 custom block on your site. You can not remove this block type until you have removed all of the %label blocks.', '%label is used by @count custom blocks on your site. You may not remove %label until you have removed all of the %label custom blocks.', array('%label' => $this->entity->label())) . '
'; + $form['description'] = array('#markup' => $caption); + return $form; + } + else { + return parent::buildForm($form, $form_state, $request); + } + } + + /** + * {@inheritdoc} + */ + public function submit(array $form, array &$form_state) { + $this->entity->delete(); + $form_state['redirect'] = 'admin/structure/custom-blocks'; + drupal_set_message(t('Custom block type %label has been deleted.', array('%label' => $this->entity->label()))); + watchdog('custom_block', 'Custom block type %label has been deleted.', array('%label' => $this->entity->label()), WATCHDOG_NOTICE); + } + +} diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlockType.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlockType.php index 6f90e56..4d5f33b 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlockType.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Core/Entity/CustomBlockType.php @@ -23,7 +23,8 @@ * controllers = { * "storage" = "Drupal\Core\Config\Entity\ConfigStorageController", * "form" = { - * "default" = "Drupal\custom_block\CustomBlockTypeFormController" + * "default" = "Drupal\custom_block\CustomBlockTypeFormController", + * "delete" = "Drupal\custom_block\Form\CustomBlockTypeDeleteForm" * }, * "list" = "Drupal\custom_block\CustomBlockTypeListController" * },