Commit 23fba807 authored by alexpott's avatar alexpott

Issue #1997262 by andypost, nick_schuch, larowlan, tim.plunkett, jibran,...

Issue #1997262 by andypost, nick_schuch, larowlan, tim.plunkett, jibran, chertzog, kim.pepper: Convert custom_block_delete_form() to new form interface.
parent 66a1e0b3
......@@ -67,6 +67,14 @@ public function buildForm(array $form, array &$form_state) {
return $form;
}
/**
* {@inheritdoc}
*/
public function form(array $form, array &$form_state) {
// Do not attach fields to the confirm form.
return $form;
}
/**
* {@inheritdoc}
*/
......
......@@ -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;
}
......
......@@ -35,50 +35,3 @@ function template_preprocess_custom_block_add_list(&$variables) {
$variables['types'][$type->id]['description'] = filter_xss_admin($type->description);
}
}
/**
* Page callback: Form constructor for the custom block deletion form.
*
* @param Drupal\custom_block\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';
}
......@@ -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:
......
......@@ -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"
......
<?php
/**
* @file
* Contains \Drupal\block\Form\CustomBlockDeleteForm.
*/
namespace Drupal\custom_block\Form;
use Drupal\Core\Entity\EntityNGConfirmFormBase;
use Symfony\Component\HttpFoundation\Request;
/**
* Provides a confirmation form for deleting a custom block entity.
*/
class CustomBlockDeleteForm extends EntityNGConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to delete %name?', array('%name' => $this->entity->label()));
}
/**
* {@inheritdoc}
*/
public function getCancelPath() {
return 'admin/structure/block';
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->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($this->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';
}
}
......@@ -76,14 +76,6 @@ public function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
public function form(array $form, array &$form_state) {
// Do not attach fields to the delete form.
return $form;
}
/**
* {@inheritdoc}
*/
......
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