Commit 2141c28c authored by webchick's avatar webchick

Issue #1946334 by mtift: Convert confirm_form() in block.admin.inc to the new form interface.

parent 6f2f1b73
......@@ -83,33 +83,6 @@ function block_admin_edit(Block $entity) {
return entity_get_form($entity);
}
/**
* Form constructor for the block instance deletion form.
*
* @param \Drupal\block\Plugin\Core\Entity\Block $entity
* The block instance.
*
* @see block_menu()
* @see block_admin_block_delete_submit()
*/
function block_admin_block_delete(array $form, array &$form_state, Block $entity) {
$form['id'] = array('#type' => 'value', '#value' => $entity->id());
return confirm_form($form, t('Are you sure you want to delete the block %name?', array('%name' => $entity->label())), 'admin/structure/block', '', t('Delete'), t('Cancel'));
}
/**
* Form submission handler for block_admin_block_delete().
*
* @see block_admin_block_delete()
*/
function block_admin_block_delete_submit($form, &$form_state) {
$entity = entity_load('block', $form_state['values']['id']);
drupal_set_message(t('The block %name has been removed.', array('%name' => $entity->label())));
$form_state['redirect'] = 'admin/structure/block/list/block_plugin_ui:' . $entity->get('theme');
$entity->delete();
}
/**
* Processes variables for block-admin-display-form.tpl.php.
*
......
......@@ -147,12 +147,9 @@ function block_menu() {
);
$items['admin/structure/block/manage/%block/delete'] = array(
'title' => 'Delete block',
'page callback' => 'drupal_get_form',
'page arguments' => array('block_admin_block_delete', 4),
'access arguments' => array('administer blocks'),
'type' => MENU_LOCAL_TASK,
'context' => MENU_CONTEXT_NONE,
'file' => 'block.admin.inc',
'route_name' => 'block_admin_block_delete',
);
// Block administration is tied to the theme and plugin definition so
// that the plugin can appropriately attach to this URL structure.
......
block_admin_block_delete:
pattern: '/admin/structure/block/manage/{block}/delete'
defaults:
_form: '\Drupal\block\Form\AdminBlockDeleteForm'
requirements:
_permission: 'administer blocks'
<?php
/**
* @file
* Contains \Drupal\block\Form\AdminBlockDeleteForm.
*/
namespace Drupal\block\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\block\Plugin\Core\Entity\Block;
/**
* Provides a deletion confirmation form for the block instance deletion form.
*/
class AdminBlockDeleteForm extends ConfirmFormBase {
/**
* The block being deleted.
*
* @var \Drupal\block\Plugin\Core\Entity\Block
*/
protected $block;
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'block_admin_block_delete_form';
}
/**
* {@inheritdoc}
*/
protected function getQuestion() {
return t('Are you sure you want to delete the block %name?', array('%name' => $this->block->label));
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
return 'admin/structure/block';
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
return t('Delete');
}
/**
* Implements \Drupal\Core\Form\FormInterface::buildForm().
*
* @param \Drupal\block\Plugin\Core\Entity\Block $block
* The block instance.
*/
public function buildForm(array $form, array &$form_state, Block $block = null) {
$this->block = $block;
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$this->block->delete();
drupal_set_message(t('The block %name has been removed.', array('%name' => $this->block->label())));
$form_state['redirect'] = 'admin/structure/block';
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment