Issue #2011018 by tim.plunkett: Reconcile entity forms and confirm forms.

8.0.x
Alex Pott 2013-06-17 23:26:42 +02:00
parent 025aa2a110
commit 73fbcf8072
72 changed files with 1101 additions and 1139 deletions

View File

@ -0,0 +1,108 @@
<?php
/**
* @file
* Contains \Drupal\Core\Entity\EntityConfirmFormBase.
*/
namespace Drupal\Core\Entity;
use Drupal\Core\Form\ConfirmFormInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Provides a generic base class for an entity-based confirmation form.
*/
abstract class EntityConfirmFormBase extends EntityFormController implements ConfirmFormInterface {
/**
* The request object.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request;
/**
* {@inheritdoc}
*/
public function getDescription() {
return t('This action cannot be undone.');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Confirm');
}
/**
* {@inheritdoc}
*/
public function getCancelText() {
return t('Cancel');
}
/**
* {@inheritdoc}
*/
public function getFormName() {
return 'confirm';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, Request $request = NULL) {
$this->request = $request;
$form = parent::buildForm($form, $form_state);
$form['#attributes']['class'][] = 'confirmation';
$form['description'] = array('#markup' => $this->getDescription());
$form[$this->getFormName()] = array('#type' => 'hidden', '#value' => 1);
// By default, render the form using theme_confirm_form().
if (!isset($form['#theme'])) {
$form['#theme'] = 'confirm_form';
}
return $form;
}
/**
* {@inheritdoc}
*/
protected function init(array &$form_state) {
parent::init($form_state);
drupal_set_title($this->getQuestion(), PASS_THROUGH);
}
/**
* {@inheritdoc}
*/
protected function actions(array $form, array &$form_state) {
$actions = parent::actions($form, $form_state);
$actions['submit']['#value'] = $this->getConfirmText();
unset($actions['delete']);
$path = $this->getCancelPath();
// Prepare cancel link.
if ($this->request->query->has('destination')) {
$options = drupal_parse_url($this->request->query->get('destination'));
}
elseif (is_array($path)) {
$options = $path;
}
else {
$options = array('path' => $path);
}
$actions['cancel'] = array(
'#type' => 'link',
'#title' => $this->getCancelText(),
'#href' => $options['path'],
'#options' => $options,
);
return $actions;
}
}

View File

@ -0,0 +1,108 @@
<?php
/**
* @file
* Contains \Drupal\Core\Entity\EntityNGConfirmFormBase.
*/
namespace Drupal\Core\Entity;
use Drupal\Core\Form\ConfirmFormInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Provides a generic base class for an entity-based confirmation form.
*/
abstract class EntityNGConfirmFormBase extends EntityFormControllerNG implements ConfirmFormInterface {
/**
* The request object.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request;
/**
* {@inheritdoc}
*/
public function getDescription() {
return t('This action cannot be undone.');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Confirm');
}
/**
* {@inheritdoc}
*/
public function getCancelText() {
return t('Cancel');
}
/**
* {@inheritdoc}
*/
public function getFormName() {
return 'confirm';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, Request $request = NULL) {
$this->request = $request;
$form = parent::buildForm($form, $form_state);
$form['#attributes']['class'][] = 'confirmation';
$form['description'] = array('#markup' => $this->getDescription());
$form[$this->getFormName()] = array('#type' => 'hidden', '#value' => 1);
// By default, render the form using theme_confirm_form().
if (!isset($form['#theme'])) {
$form['#theme'] = 'confirm_form';
}
return $form;
}
/**
* {@inheritdoc}
*/
protected function init(array &$form_state) {
parent::init($form_state);
drupal_set_title($this->getQuestion(), PASS_THROUGH);
}
/**
* {@inheritdoc}
*/
protected function actions(array $form, array &$form_state) {
$actions = parent::actions($form, $form_state);
$actions['submit']['#value'] = $this->getConfirmText();
unset($actions['delete']);
$path = $this->getCancelPath();
// Prepare cancel link.
if ($this->request->query->has('destination')) {
$options = drupal_parse_url($this->request->query->get('destination'));
}
elseif (is_array($path)) {
$options = $path;
}
else {
$options = array('path' => $path);
}
$actions['cancel'] = array(
'#type' => 'link',
'#title' => $this->getCancelText(),
'#href' => $options['path'],
'#options' => $options,
);
return $actions;
}
}

View File

@ -7,80 +7,49 @@
namespace Drupal\Core\Form;
use Symfony\Component\HttpFoundation\Request;
/**
* Provides an generic base class for a confirmation form.
*/
abstract class ConfirmFormBase implements FormInterface {
abstract class ConfirmFormBase implements ConfirmFormInterface {
/**
* Returns the question to ask the user.
*
* @return string
* The form question. The page title will be set to this value.
* {@inheritdoc}
*/
abstract protected function getQuestion();
/**
* Returns the page to go to if the user cancels the action.
*
* @return string|array
* This can be either:
* - A string containing a Drupal path.
* - An associative array with a 'path' key. Additional array values are
* passed as the $options parameter to l().
* If the 'destination' query parameter is set in the URL when viewing a
* confirmation form, that value will be used instead of this path.
*/
abstract protected function getCancelPath();
/**
* Returns additional text to display as a description.
*
* @return string
* The form description.
*/
protected function getDescription() {
public function getDescription() {
return t('This action cannot be undone.');
}
/**
* Returns a caption for the button that confirms the action.
*
* @return string
* The form confirmation text.
* {@inheritdoc}
*/
protected function getConfirmText() {
public function getConfirmText() {
return t('Confirm');
}
/**
* Returns a caption for the link which cancels the action.
*
* @return string
* The form cancellation text.
* {@inheritdoc}
*/
protected function getCancelText() {
public function getCancelText() {
return t('Cancel');
}
/**
* Returns the internal name used to refer to the confirmation item.
*
* @return string
* The internal form name.
* {@inheritdoc}
*/
protected function getFormName() {
public function getFormName() {
return 'confirm';
}
/**
* Implements \Drupal\Core\Form\FormInterface::buildForm().
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
public function buildForm(array $form, array &$form_state, Request $request = NULL) {
$path = $this->getCancelPath();
// Prepare cancel link.
if (isset($_GET['destination'])) {
$options = drupal_parse_url($_GET['destination']);
if ($request->query->has('destination')) {
$options = drupal_parse_url($request->query->get('destination'));
}
elseif (is_array($path)) {
$options = $path;
@ -114,7 +83,7 @@ abstract class ConfirmFormBase implements FormInterface {
}
/**
* Implements \Drupal\Core\Form\FormInterface::validateForm().
* {@inheritdoc}
*/
public function validateForm(array &$form, array &$form_state) {
}

View File

@ -0,0 +1,68 @@
<?php
/**
* @file
* Contains \Drupal\Core\Form\ConfirmFormInterface.
*/
namespace Drupal\Core\Form;
/**
* Defines the behavior a confirmation form.
*/
interface ConfirmFormInterface extends FormInterface {
/**
* Returns the question to ask the user.
*
* @return string
* The form question. The page title will be set to this value.
*/
public function getQuestion();
/**
* Returns the page to go to if the user cancels the action.
*
* @return string|array
* This can be either:
* - A string containing a Drupal path.
* - An associative array with a 'path' key. Additional array values are
* passed as the $options parameter to l().
* If the 'destination' query parameter is set in the URL when viewing a
* confirmation form, that value will be used instead of this path.
*/
public function getCancelPath();
/**
* Returns additional text to display as a description.
*
* @return string
* The form description.
*/
public function getDescription();
/**
* Returns a caption for the button that confirms the action.
*
* @return string
* The form confirmation text.
*/
public function getConfirmText();
/**
* Returns a caption for the link which cancels the action.
*
* @return string
* The form cancellation text.
*/
public function getCancelText();
/**
* Returns the internal name used to refer to the confirmation item.
*
* @return string
* The internal form name.
*/
public function getFormName();
}

View File

@ -73,5 +73,6 @@ function action_menu() {
function action_entity_info(&$entity_info) {
$entity_info['action']['controllers']['form']['add'] = 'Drupal\action\ActionAddFormController';
$entity_info['action']['controllers']['form']['edit'] = 'Drupal\action\ActionEditFormController';
$entity_info['action']['controllers']['form']['delete'] = 'Drupal\action\Form\ActionDeleteForm';
$entity_info['action']['controllers']['list'] = 'Drupal\action\ActionListController';
}

View File

@ -22,7 +22,7 @@ action_admin_configure:
action_delete:
pattern: 'admin/config/system/actions/configure/{action}/delete'
defaults:
_form: '\Drupal\action\Form\DeleteForm'
_entity_form: 'action.delete'
requirements:
_permission: 'administer actions'

View File

@ -0,0 +1,50 @@
<?php
/**
* @file
* Contains \Drupal\action\Form\ActionDeleteForm.
*/
namespace Drupal\action\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
/**
* Builds a form to delete an action.
*/
class ActionDeleteForm extends EntityConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getQuestion() {
return t('Are you sure you want to delete the action %action?', array('%action' => $this->entity->label()));
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
public function getCancelPath() {
return 'admin/config/system/actions';
}
/**
* {@inheritdoc}
*/
public function submit(array $form, array &$form_state) {
$this->entity->delete();
watchdog('user', 'Deleted action %aid (%action)', array('%aid' => $this->entity->id(), '%action' => $this->entity->label()));
drupal_set_message(t('Action %action was deleted', array('%action' => $this->entity->label())));
$form_state['redirect'] = 'admin/config/system/actions';
}
}

View File

@ -1,75 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\action\Form\DeleteForm.
*/
namespace Drupal\action\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\system\ActionConfigEntityInterface;
/**
* Builds a form to delete an action.
*/
class DeleteForm extends ConfirmFormBase {
/**
* The action to be deleted.
*
* @var \Drupal\system\ActionConfigEntityInterface
*/
protected $action;
/**
* {@inheritdoc}
*/
protected function getQuestion() {
return t('Are you sure you want to delete the action %action?', array('%action' => $this->action->label()));
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
return 'admin/config/system/actions';
}
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'action_admin_delete_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, ActionConfigEntityInterface $action = NULL) {
$this->action = $action;
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$this->action->delete();
watchdog('user', 'Deleted action %aid (%action)', array('%aid' => $this->action->id(), '%action' => $this->action->label()));
drupal_set_message(t('Action %action was deleted', array('%action' => $this->action->label())));
$form_state['redirect'] = 'admin/config/system/actions';
}
}

View File

@ -370,27 +370,6 @@ function aggregator_save_category($edit) {
}
}
/**
* Removes all items from a feed.
*
* @param \Drupal\aggregator\Plugin\Core\Entity\Feed $feed
* An object describing the feed to be cleared.
*/
function aggregator_remove(Feed $feed) {
// Call \Drupal\aggregator\Plugin\ProcessorInterface::remove() on all
// processors.
$manager = Drupal::service('plugin.manager.aggregator.processor');
foreach ($manager->getDefinitions() as $id => $definition) {
$manager->createInstance($id)->remove($feed);
}
// Reset feed.
$feed->checked->value = 0;
$feed->hash->value = '';
$feed->etag->value = '';
$feed->modified->value = 0;
$feed->save();
}
/**
* Checks a news feed for new items.
*

View File

@ -15,14 +15,14 @@ aggregator_admin_settings:
aggregator_feed_items_delete:
pattern: '/admin/config/services/aggregator/remove/{aggregator_feed}'
defaults:
_form: '\Drupal\aggregator\Form\FeedItemsDelete'
_entity_form: 'aggregator_feed.remove_items'
requirements:
_permission: 'administer news feeds'
aggregator_feed_delete:
pattern: '/admin/config/services/aggregator/delete/feed/{aggregator_feed}'
defaults:
_form: '\Drupal\aggregator\Form\FeedDelete'
_entity_form: 'aggregator_feed.delete'
requirements:
_permission: 'administer news feeds'

View File

@ -14,4 +14,9 @@ use Drupal\Core\Entity\ContentEntityInterface;
*/
interface FeedInterface extends ContentEntityInterface {
/**
* Removes all items from a feed.
*/
public function removeItems();
}

View File

@ -1,75 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\aggregator\Form\FeedDelete.
*/
namespace Drupal\aggregator\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\aggregator\Plugin\Core\Entity\Feed;
/**
* Provides a form for deleting a feed.
*/
class FeedDelete extends ConfirmFormBase {
/**
* The feed the being deleted.
*
* @var \Drupal\aggregator\Plugin\Core\Entity\Feed
*/
protected $feed;
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'aggregator_feed_delete_form';
}
/**
* {@inheritdoc}
*/
protected function getQuestion() {
return t('Are you sure you want to delete the feed %feed?', array('%feed' => $this->feed->label()));
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
return 'admin/config/services/aggregator';
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, Feed $aggregator_feed = NULL) {
$this->feed = $aggregator_feed;
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$this->feed->delete();
watchdog('aggregator', 'Feed %feed deleted.', array('%feed' => $this->feed->label()));
drupal_set_message(t('The feed %feed has been deleted.', array('%feed' => $this->feed->label())));
if (arg(0) == 'admin') {
$form_state['redirect'] = 'admin/config/services/aggregator';
}
else {
$form_state['redirect'] = 'aggregator/sources';
}
}
}

View File

@ -0,0 +1,52 @@
<?php
/**
* @file
* Contains \Drupal\aggregator\Form\FeedDeleteForm.
*/
namespace Drupal\aggregator\Form;
use Drupal\Core\Entity\EntityNGConfirmFormBase;
/**
* Provides a form for deleting a feed.
*/
class FeedDeleteForm extends EntityNGConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getQuestion() {
return t('Are you sure you want to delete the feed %feed?', array('%feed' => $this->entity->label()));
}
/**
* {@inheritdoc}
*/
public function getCancelPath() {
return 'admin/config/services/aggregator';
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
public function submit(array $form, array &$form_state) {
$this->entity->delete();
watchdog('aggregator', 'Feed %feed deleted.', array('%feed' => $this->entity->label()));
drupal_set_message(t('The feed %feed has been deleted.', array('%feed' => $this->entity->label())));
if (arg(0) == 'admin') {
$form_state['redirect'] = 'admin/config/services/aggregator';
}
else {
$form_state['redirect'] = 'aggregator/sources';
}
}
}

View File

@ -1,70 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\aggregator\Form\FeedItemsDelete.
*/
namespace Drupal\aggregator\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\aggregator\Plugin\Core\Entity\Feed;
/**
* Provides a deletion confirmation form for items that belong to a feed.
*/
class FeedItemsDelete extends ConfirmFormBase {
/**
* The feed the items being deleted belong to.
*
* @var \Drupal\aggregator\Plugin\Core\Entity\Feed
*/
protected $feed;
/**
* Implements \Drupal\Core\Form\FormInterface::getFormID().
*/
public function getFormID() {
return 'aggregator_feed_items_delete_form';
}
/**
* Implements \Drupal\Core\Form\ConfirmFormBase::getQuestion().
*/
protected function getQuestion() {
return t('Are you sure you want to remove all items from the feed %feed?', array('%feed' => $this->feed->label()));
}
/**
* Implements \Drupal\Core\Form\ConfirmFormBase::getCancelPath().
*/
protected function getCancelPath() {
return 'admin/config/services/aggregator';
}
/**
* Implements \Drupal\Core\Form\ConfirmFormBase::getConfirmText().
*/
protected function getConfirmText() {
return t('Remove items');
}
/**
* Implements \Drupal\Core\Form\FormInterface::buildForm().
*/
public function buildForm(array $form, array &$form_state, Feed $aggregator_feed = NULL) {
$this->feed = $aggregator_feed;
return parent::buildForm($form, $form_state);
}
/**
* Implements \Drupal\Core\Form\FormInterface::submitForm().
*/
public function submitForm(array &$form, array &$form_state) {
// @todo Remove once http://drupal.org/node/1930274 is fixed.
aggregator_remove($this->feed);
$form_state['redirect'] = 'admin/config/services/aggregator';
}
}

View File

@ -0,0 +1,47 @@
<?php
/**
* @file
* Contains \Drupal\aggregator\Form\FeedItemsRemoveForm.
*/
namespace Drupal\aggregator\Form;
use Drupal\Core\Entity\EntityNGConfirmFormBase;
/**
* Provides a deletion confirmation form for items that belong to a feed.
*/
class FeedItemsRemoveForm extends EntityNGConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getQuestion() {
return t('Are you sure you want to remove all items from the feed %feed?', array('%feed' => $this->entity->label()));
}
/**
* {@inheritdoc}
*/
public function getCancelPath() {
return 'admin/config/services/aggregator';
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Remove items');
}
/**
* {@inheritdoc}
*/
public function submit(array $form, array &$form_state) {
$this->entity->removeItems();
$form_state['redirect'] = 'admin/config/services/aggregator';
}
}

View File

@ -25,7 +25,9 @@ use Drupal\aggregator\FeedInterface;
* "storage" = "Drupal\aggregator\FeedStorageController",
* "render" = "Drupal\aggregator\FeedRenderController",
* "form" = {
* "default" = "Drupal\aggregator\FeedFormController"
* "default" = "Drupal\aggregator\FeedFormController",
* "delete" = "Drupal\aggregator\Form\FeedDeleteForm",
* "remove_items" = "Drupal\aggregator\Form\FeedItemsRemoveForm"
* }
* },
* base_table = "aggregator_feed",
@ -175,6 +177,22 @@ class Feed extends EntityNG implements FeedInterface {
return $this->get('title')->value;
}
/**
* {@inheritdoc}
*/
public function removeItems() {
$manager = \Drupal::service('plugin.manager.aggregator.processor');
foreach ($manager->getDefinitions() as $id => $definition) {
$manager->createInstance($id)->remove($this);
}
// Reset feed.
$this->checked->value = 0;
$this->hash->value = '';
$this->etag->value = '';
$this->modified->value = 0;
$this->save();
}
/**
* {@inheritdoc}
*/
@ -245,4 +263,5 @@ class Feed extends EntityNG implements FeedInterface {
$block_manager->clearCachedDefinitions();
}
}
}

View File

@ -11,6 +11,7 @@ use Drupal\Core\Controller\ControllerInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\ban\BanIpManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
@ -53,21 +54,21 @@ class BanDelete extends ConfirmFormBase implements ControllerInterface {
/**
* {@inheritdoc}
*/
protected function getQuestion() {
public function getQuestion() {
return t('Are you sure you want to unblock %ip?', array('%ip' => $this->banIp));
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
public function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
public function getCancelPath() {
return 'admin/config/people/ban';
}
@ -77,11 +78,11 @@ class BanDelete extends ConfirmFormBase implements ControllerInterface {
* @param string $ban_id
* The IP address record ID to unban.
*/
public function buildForm(array $form, array &$form_state, $ban_id = '') {
public function buildForm(array $form, array &$form_state, $ban_id = '', Request $request = NULL) {
if (!$this->banIp = $this->ipManager->findById($ban_id)) {
throw new NotFoundHttpException();
}
return parent::buildForm($form, $form_state);
return parent::buildForm($form, $form_state, $request);
}
/**

View File

@ -1,6 +1,6 @@
block_admin_block_delete:
pattern: '/admin/structure/block/manage/{block}/delete'
defaults:
_form: '\Drupal\block\Form\AdminBlockDeleteForm'
_entity_form: 'block.delete'
requirements:
_permission: 'administer blocks'

View File

@ -1,73 +0,0 @@
<?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';
}
}

View File

@ -0,0 +1,47 @@
<?php
/**
* @file
* Contains \Drupal\block\Form\BlockDeleteForm.
*/
namespace Drupal\block\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
/**
* Provides a deletion confirmation form for the block instance deletion form.
*/
class BlockDeleteForm extends EntityConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getQuestion() {
return t('Are you sure you want to delete the block %name?', array('%name' => $this->entity->label()));
}
/**
* {@inheritdoc}
*/
public function getCancelPath() {
return 'admin/structure/block';
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
public function submit(array $form, array &$form_state) {
$this->entity->delete();
drupal_set_message(t('The block %name has been removed.', array('%name' => $this->entity->label())));
$form_state['redirect'] = 'admin/structure/block';
}
}

View File

@ -27,7 +27,8 @@ use Drupal\Core\Entity\EntityStorageControllerInterface;
* "render" = "Drupal\block\BlockRenderController",
* "list" = "Drupal\block\BlockListController",
* "form" = {
* "default" = "Drupal\block\BlockFormController"
* "default" = "Drupal\block\BlockFormController",
* "delete" = "Drupal\block\Form\BlockDeleteForm"
* }
* },
* config_prefix = "block.block",

View File

@ -47,7 +47,7 @@ config_test_entity_disable:
config_test_entity_delete:
pattern: 'admin/structure/config_test/manage/{config_test}/delete'
defaults:
_form: '\Drupal\config_test\Form\ConfigTestDeleteForm'
_entity_form: 'config_test.delete'
entity_type: 'config_test'
requirements:
_access: 'TRUE'

View File

@ -7,67 +7,40 @@
namespace Drupal\config_test\Form;
use Drupal\Component\Utility\String;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\config_test\ConfigTestInterface;
use Drupal\Core\Entity\EntityConfirmFormBase;
/**
* Delete confirmation form for config_test entities.
*/
class ConfigTestDeleteForm extends ConfirmFormBase {
/**
* The config_test entity to be deleted.
*
* @var \Drupal\config_test\Plugin\Core\Entity\ConfigTest.
*/
protected $configTest;
class ConfigTestDeleteForm extends EntityConfirmFormBase {
/**
* {@inheritdoc}
*/
protected function getQuestion() {
return t('Are you sure you want to delete %label', array('%label' => $this->configTest->label()));
public function getQuestion() {
return t('Are you sure you want to delete %label', array('%label' => $this->entity->label()));
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
public function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
public function getCancelPath() {
return 'admin/structure/config_test';
}
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'config_test_delete_form';
}
/**
* Implements \Drupal\Drupal\Core\Form\ConfirmFormBase::buildForm().
*
* @param \Drupal\config_test\ConfigTestInterface $config_test
* (optional) The ConfigTestInterface object to delete.
*/
public function buildForm(array $form, array &$form_state, ConfigTestInterface $config_test = NULL) {
$this->configTest = $config_test;
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$this->configTest->delete();
drupal_set_message(String::format('%label configuration has been deleted.', array('%label' => $this->configTest->label())));
public function submit(array $form, array &$form_state) {
$this->entity->delete();
drupal_set_message(String::format('%label configuration has been deleted.', array('%label' => $this->entity->label())));
$form_state['redirect'] = 'admin/structure/config_test';
}

View File

@ -23,7 +23,8 @@ use Drupal\config_test\ConfigTestInterface;
* "storage" = "Drupal\config_test\ConfigTestStorageController",
* "list" = "Drupal\Core\Config\Entity\ConfigEntityListController",
* "form" = {
* "default" = "Drupal\config_test\ConfigTestFormController"
* "default" = "Drupal\config_test\ConfigTestFormController",
* "delete" = "Drupal\config_test\Form\ConfigTestDeleteForm"
* }
* },
* uri_callback = "config_test_uri",

View File

@ -1,7 +1,7 @@
contact_category_delete:
pattern: 'admin/structure/contact/manage/{contact_category}/delete'
defaults:
_form: '\Drupal\contact\Form\DeleteForm'
_entity_form: contact_category.delete
requirements:
_entity_access: contact_category.delete

View File

@ -0,0 +1,48 @@
<?php
/**
* @file
* Contains \Drupal\contact\Form\CategoryDeleteForm.
*/
namespace Drupal\contact\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
/**
* Builds the form to delete a contact category.
*/
class CategoryDeleteForm extends EntityConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getQuestion() {
return t('Are you sure you want to delete %name?', array('%name' => $this->entity->label()));
}
/**
* {@inheritdoc}
*/
public function getCancelPath() {
return 'admin/structure/contact';
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
public function submit(array $form, array &$form_state) {
$this->entity->delete();
drupal_set_message(t('Category %label has been deleted.', array('%label' => $this->entity->label())));
watchdog('contact', 'Category %label has been deleted.', array('%label' => $this->entity->label()), WATCHDOG_NOTICE);
$form_state['redirect'] = 'admin/structure/contact';
}
}

View File

@ -1,72 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\contact\Form\DeleteForm.
*/
namespace Drupal\contact\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\contact\Plugin\Core\Entity\Category;
/**
* Builds the form to delete a contact category.
*/
class DeleteForm extends ConfirmFormBase {
/**
* The contact category being deleted.
*
* @var \Drupal\contact\Plugin\Core\Entity\Category
*/
protected $contactCategory;
/**
* Implements \Drupal\Core\Form\FormInterface::getFormID().
*/
public function getFormID() {
return 'contact_category_delete_form';
}
/**
* Implements \Drupal\Core\Form\ConfirmFormBase::getQuestion().
*/
protected function getQuestion() {
return t('Are you sure you want to delete %name?', array('%name' => $this->contactCategory->label()));
}
/**
* Implements \Drupal\Core\Form\ConfirmFormBase::getCancelPath().
*/
protected function getCancelPath() {
return 'admin/structure/contact';
}
/**
* Overrides \Drupal\Core\Form\ConfirmFormBase::getConfirmText().
*/
protected function getConfirmText() {
return t('Delete');
}
/**
* Overrides \Drupal\Core\Form\ConfirmFormBase::buildForm().
*/
public function buildForm(array $form, array &$form_state, Category $contact_category = NULL) {
$this->contactCategory = $contact_category;
return parent::buildForm($form, $form_state);
}
/**
* Implements \Drupal\Core\Form\FormInterface::submitForm().
*/
public function submitForm(array &$form, array &$form_state) {
$this->contactCategory->delete();
drupal_set_message(t('Category %label has been deleted.', array('%label' => $this->contactCategory->label())));
watchdog('contact', 'Category %label has been deleted.', array('%label' => $this->contactCategory->label()), WATCHDOG_NOTICE);
$form_state['redirect'] = 'admin/structure/contact';
}
}

View File

@ -26,7 +26,8 @@ use Drupal\contact\CategoryInterface;
* "list" = "Drupal\contact\CategoryListController",
* "form" = {
* "add" = "Drupal\contact\CategoryFormController",
* "edit" = "Drupal\contact\CategoryFormController"
* "edit" = "Drupal\contact\CategoryFormController",
* "delete" = "Drupal\contact\Form\CategoryDeleteForm"
* }
* },
* uri_callback = "contact_category_uri",

View File

@ -243,6 +243,13 @@ function field_ui_element_info() {
);
}
/**
* Implements hook_entity_info().
*/
function field_ui_entity_info(&$entity_info) {
$entity_info['field_instance']['controllers']['form']['delete'] = 'Drupal\field_ui\Form\FieldDeleteForm';
}
/**
* Implements hook_entity_bundle_create().
*/

View File

@ -7,23 +7,15 @@
namespace Drupal\field_ui\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Controller\ControllerInterface;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Entity\EntityControllerInterface;
use Drupal\Core\Entity\EntityManager;
use Drupal\field\Plugin\Core\Entity\FieldInstance;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a form for removing a field instance from a bundle.
*/
class FieldDeleteForm extends ConfirmFormBase implements ControllerInterface {
/**
* The field instance being deleted.
*
* @var \Drupal\field\Plugin\Core\Entity\FieldInstance
*/
protected $instance;
class FieldDeleteForm extends EntityConfirmFormBase implements EntityControllerInterface {
/**
* The entity manager.
@ -45,7 +37,7 @@ class FieldDeleteForm extends ConfirmFormBase implements ControllerInterface {
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) {
return new static(
$container->get('plugin.manager.entity')
);
@ -54,59 +46,43 @@ class FieldDeleteForm extends ConfirmFormBase implements ControllerInterface {
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'field_ui_field_delete_form';
public function getQuestion() {
return t('Are you sure you want to delete the field %field?', array('%field' => $this->entity->label()));
}
/**
* {@inheritdoc}
*/
protected function getQuestion() {
return t('Are you sure you want to delete the field %field?', array('%field' => $this->instance->label()));
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
public function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
return $this->entityManager->getAdminPath($this->instance->entity_type, $this->instance->bundle) . '/fields';
public function getCancelPath() {
return $this->entityManager->getAdminPath($this->entity->entity_type, $this->entity->bundle) . '/fields';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, FieldInstance $field_instance = NULL) {
$this->instance = $form_state['instance'] = $field_instance;
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
public function submit(array $form, array &$form_state) {
form_load_include($form_state, 'inc', 'field_ui', 'field_ui.admin');
$field = $this->instance->getField();
$field = $this->entity->getField();
$bundles = entity_get_bundles();
$bundle_label = $bundles[$this->instance->entity_type][$this->instance->bundle]['label'];
$bundle_label = $bundles[$this->entity->entity_type][$this->entity->bundle]['label'];
if ($field && !$field['locked']) {
$this->instance->delete();
drupal_set_message(t('The field %field has been deleted from the %type content type.', array('%field' => $this->instance->label(), '%type' => $bundle_label)));
$this->entity->delete();
drupal_set_message(t('The field %field has been deleted from the %type content type.', array('%field' => $this->entity->label(), '%type' => $bundle_label)));
}
else {
drupal_set_message(t('There was a problem removing the %field from the %type content type.', array('%field' => $this->instance->label(), '%type' => $bundle_label)), 'error');
drupal_set_message(t('There was a problem removing the %field from the %type content type.', array('%field' => $this->entity->label(), '%type' => $bundle_label)), 'error');
}
$admin_path = $this->entityManager->getAdminPath($this->instance->entity_type, $this->instance->bundle);
$admin_path = $this->entityManager->getAdminPath($this->entity->entity_type, $this->entity->bundle);
$form_state['redirect'] = "$admin_path/fields";
// Fields are purged on cron. However field module prevents disabling modules

View File

@ -76,7 +76,7 @@ class RouteSubscriber implements EventSubscriberInterface {
$route = new Route(
"$path/fields/{field_instance}/delete",
array('_form' => '\Drupal\field_ui\Form\FieldDeleteForm'),
array('_entity_form' => 'field_instance.delete'),
array('_permission' => 'administer ' . $entity_type . ' fields')
);
$collection->add("field_ui.delete.$entity_type", $route);

View File

@ -1,7 +1,7 @@
filter_admin_disable:
pattern: '/admin/config/content/formats/{filter_format}/disable'
defaults:
_form: '\Drupal\filter\Form\DisableForm'
_entity_form: 'filter_format.disable'
requirements:
_filter_disable_format_access: 'TRUE'

View File

@ -1,79 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\filter\Form\DisableForm.
*/
namespace Drupal\filter\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\filter\Plugin\Core\Entity\FilterFormat;
/**
* Provides the filter format disable form.
*/
class DisableForm extends ConfirmFormBase {
/**
* The format being disabled.
*
* @var \Drupal\filter\Plugin\Core\Entity\FilterFormat
*/
protected $format;
/**
* Implements \Drupal\Core\Form\FormInterface::getFormID().
*/
public function getFormID() {
return 'filter_admin_disable';
}
/**
* Implements \Drupal\Core\Form\ConfirmFormBase::getQuestion().
*/
protected function getQuestion() {
return t('Are you sure you want to disable the text format %format?', array('%format' => $this->format->name));
}
/**
* Implements \Drupal\Core\Form\ConfirmFormBase::getCancelPath().
*/
protected function getCancelPath() {
return 'admin/config/content/formats';
}
/**
* Overrides \Drupal\Core\Form\ConfirmFormBase::getConfirmText().
*/
public function getConfirmText() {
return t('Disable');
}
/**
* Overrides \Drupal\Core\Form\ConfirmFormBase::getDescription().
*/
public function getDescription() {
return t('Disabled text formats are completely removed from the administrative interface, and any content stored with that format will not be displayed. This action cannot be undone.');
}
/**
* Overrides \Drupal\Core\Form\FormInterface::buildForm().
*/
public function buildForm(array $form, array &$form_state, FilterFormat $filter_format = NULL) {
$this->format = $filter_format;
return parent::buildForm($form, $form_state);
}
/**
* Implements \Drupal\Core\Form\FormInterface::submitForm().
*/
public function submitForm(array &$form, array &$form_state) {
$this->format->disable()->save();
drupal_set_message(t('Disabled text format %format.', array('%format' => $this->format->name)));
$form_state['redirect'] = 'admin/config/content/formats';
}
}

View File

@ -0,0 +1,55 @@
<?php
/**
* @file
* Contains \Drupal\filter\Form\FilterDisableForm.
*/
namespace Drupal\filter\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
/**
* Provides the filter format disable form.
*/
class FilterDisableForm extends EntityConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getQuestion() {
return t('Are you sure you want to disable the text format %format?', array('%format' => $this->entity->label()));
}
/**
* {@inheritdoc}
*/
public function getCancelPath() {
return 'admin/config/content/formats';
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Disable');
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return t('Disabled text formats are completely removed from the administrative interface, and any content stored with that format will not be displayed. This action cannot be undone.');
}
/**
* {@inheritdoc}
*/
public function submit(array $form, array &$form_state) {
$this->entity->disable()->save();
drupal_set_message(t('Disabled text format %format.', array('%format' => $this->entity->label())));
$form_state['redirect'] = 'admin/config/content/formats';
}
}

View File

@ -22,6 +22,9 @@ use Drupal\filter\FilterBag;
* label = @Translation("Text format"),
* module = "filter",
* controllers = {
* "form" = {
* "disable" = "Drupal\filter\Form\FilterDisableForm"
* },
* "storage" = "Drupal\Core\Config\Entity\ConfigStorageController"
* },
* config_prefix = "filter.format",

View File

@ -9,6 +9,7 @@ namespace Drupal\forum\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\taxonomy\Plugin\Core\Entity\Term;
use Symfony\Component\HttpFoundation\Request;
/**
* Builds the form to delete a forum term.
@ -32,31 +33,31 @@ class DeleteForm extends ConfirmFormBase {
/**
* {@inheritdoc}
*/
protected function getQuestion() {
public function getQuestion() {
return t('Are you sure you want to delete the forum %label?', array('%label' => $this->taxonomyTerm->label()));
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
public function getCancelPath() {
return 'admin/structure/forum';
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
public function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, Term $taxonomy_term = NULL) {
public function buildForm(array $form, array &$form_state, Term $taxonomy_term = NULL, Request $request = NULL) {
$this->taxonomyTerm = $taxonomy_term;
return parent::buildForm($form, $form_state);
return parent::buildForm($form, $form_state, $request);
}
/**

View File

@ -1,7 +1,7 @@
image_style_delete:
pattern: 'admin/config/media/image-styles/manage/{image_style}/delete'
defaults:
_form: '\Drupal\image\Form\ImageStyleDeleteForm'
_entity_form: 'image_style.delete'
requirements:
_permission: 'administer image styles'

View File

@ -9,6 +9,7 @@ namespace Drupal\image\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\image\Plugin\Core\Entity\ImageStyle;
use Symfony\Component\HttpFoundation\Request;
/**
* Form for deleting an image effect.
@ -32,21 +33,21 @@ class ImageEffectDeleteForm extends ConfirmFormBase {
/**
* {@inheritdoc}
*/
protected function getQuestion() {
public function getQuestion() {
return t('Are you sure you want to delete the @effect effect from the %style style?', array('%style' => $this->imageStyle->label(), '@effect' => $this->imageEffect['label']));
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
public function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
public function getCancelPath() {
return 'admin/config/media/image-styles/manage/' . $this->imageStyle->id();
}
@ -60,11 +61,11 @@ class ImageEffectDeleteForm extends ConfirmFormBase {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, $image_style = NULL, $image_effect = NULL) {
public function buildForm(array $form, array &$form_state, $image_style = NULL, $image_effect = NULL, Request $request = NULL) {
$this->imageStyle = $image_style;
$this->imageEffect = image_effect_load($image_effect, $this->imageStyle->id());
return parent::buildForm($form, $form_state);
return parent::buildForm($form, $form_state, $request);
}
/**

View File

@ -7,64 +7,46 @@
namespace Drupal\image\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\image\Plugin\Core\Entity\ImageStyle;
use Drupal\Core\Entity\EntityConfirmFormBase;
/**
* Creates a form to delete an image style.
*/
class ImageStyleDeleteForm extends ConfirmFormBase {
/**
* The image style to be deleted.
*
* @var \Drupal\image\Plugin\Core\Entity\ImageStyle $imageStyle
*/
protected $imageStyle;
class ImageStyleDeleteForm extends EntityConfirmFormBase {
/**
* {@inheritdoc}
*/
protected function getQuestion() {
return t('Optionally select a style before deleting %style', array('%style' => $this->imageStyle->label()));
public function getQuestion() {
return t('Optionally select a style before deleting %style', array('%style' => $this->entity->label()));
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
public function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
public function getCancelPath() {
return 'admin/config/media/image-styles';
}
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'image_style_delete_form';
}
/**
* {@inheritdoc}
*/
protected function getDescription() {
public function getDescription() {
return t('If this style is in use on the site, you may select another style to replace it. All images that have been generated for this style will be permanently deleted.');
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, ImageStyle $image_style = NULL) {
$this->imageStyle = $image_style;
$replacement_styles = array_diff_key(image_style_options(), array($this->imageStyle->id() => ''));
public function form(array $form, array &$form_state) {
$replacement_styles = array_diff_key(image_style_options(), array($this->entity->id() => ''));
$form['replacement'] = array(
'#title' => t('Replacement style'),
'#type' => 'select',
@ -72,16 +54,16 @@ class ImageStyleDeleteForm extends ConfirmFormBase {
'#empty_option' => t('No replacement, just delete'),
);
return parent::buildForm($form, $form_state);
return parent::form($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$this->imageStyle->set('replacementID', $form_state['values']['replacement']);
$this->imageStyle->delete();
drupal_set_message(t('Style %name was deleted.', array('%name' => $this->imageStyle->label())));
public function submit(array $form, array &$form_state) {
$this->entity->set('replacementID', $form_state['values']['replacement']);
$this->entity->delete();
drupal_set_message(t('Style %name was deleted.', array('%name' => $this->entity->label())));
$form_state['redirect'] = 'admin/config/media/image-styles';
}

View File

@ -21,6 +21,9 @@ use Drupal\image\ImageStyleInterface;
* label = @Translation("Image style"),
* module = "image",
* controllers = {
* "form" = {
* "delete" = "Drupal\image\Form\ImageStyleDeleteForm"
* },
* "storage" = "Drupal\image\ImageStyleStorageController"
* },
* uri_callback = "image_style_entity_uri",

View File

@ -0,0 +1,123 @@
<?php
/**
* @file
* Contains \Drupal\menu\Form\MenuDeleteForm.
*/
namespace Drupal\menu\Form;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Entity\EntityControllerInterface;
use Drupal\Core\Entity\EntityStorageControllerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines a confirmation form for deletion of a custom menu.
*/
class MenuDeleteForm extends EntityConfirmFormBase implements EntityControllerInterface {
/**
* The menu link storage controller.
*
* @var \Drupal\Core\Entity\EntityStorageControllerInterface
*/
protected $storageController;
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* Constructs a new MenuDeleteForm.
*
* @param \Drupal\Core\Entity\EntityStorageControllerInterface $storage_controller
* The menu link storage controller.
* @param \Drupal\Core\Database\Connection $connection
* The database connection.
*/
public function __construct(EntityStorageControllerInterface $storage_controller, Connection $connection) {
$this->storageController = $storage_controller;
$this->connection = $connection;
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) {
return new static(
$container->get('plugin.manager.entity')->getStorageController('menu_link'),
$container->get('database')
);
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return t('Are you sure you want to delete the custom menu %title?', array('%title' => $this->entity->label()));
}
/**
* {@inheritdoc}
*/
public function getCancelPath() {
return 'admin/structure/menu/manage/' . $this->entity->id();
}
/**
* {@inheritdoc}
*/
public function getDescription() {
$caption = '';
$num_links = $this->storageController->countMenuLinks($this->entity->id());
if ($num_links) {
$caption .= '<p>' . format_plural($num_links, '<strong>Warning:</strong> There is currently 1 menu link in %title. It will be deleted (system-defined items will be reset).', '<strong>Warning:</strong> There are currently @count menu links in %title. They will be deleted (system-defined links will be reset).', array('%title' => $this->entity->label())) . '</p>';
}
$caption .= '<p>' . t('This action cannot be undone.') . '</p>';
return $caption;
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
public function submit(array $form, array &$form_state) {
$form_state['redirect'] = 'admin/structure/menu';
// System-defined menus may not be deleted - only menus defined by this module.
$system_menus = menu_list_system_menus();
if (isset($system_menus[$this->entity->id()])) {
return;
}
// Reset all the menu links defined by the system via hook_menu().
// @todo Convert this to an EFQ once we figure out 'ORDER BY m.number_parts'.
$result = $this->connection->query("SELECT mlid FROM {menu_links} ml INNER JOIN {menu_router} m ON ml.router_path = m.path WHERE ml.menu_name = :menu AND ml.module = 'system' ORDER BY m.number_parts ASC", array(':menu' => $this->entity->id()), array('fetch' => \PDO::FETCH_ASSOC))->fetchCol();
$menu_links = $this->storageController->load($result);
foreach ($menu_links as $link) {
$link->reset();
}
// Delete all links to the overview page for this menu.
$menu_links = $this->storageController->loadByProperties(array('link_path' => 'admin/structure/menu/manage/' . $this->entity->id()));
menu_link_delete_multiple(array_keys($menu_links));
// Delete the custom menu and all its menu links.
$this->entity->delete();
$t_args = array('%title' => $this->entity->label());
drupal_set_message(t('The custom menu %title has been deleted.', $t_args));
watchdog('menu', 'Deleted custom menu %title and all its menu links.', $t_args, WATCHDOG_NOTICE);
}
}

View File

@ -1,107 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\menu\Form\MenuDeleteMenuForm.
*/
namespace Drupal\menu\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\system\Plugin\Core\Entity\Menu;
/**
* Defines a confirmation form for deletion of a custom menu.
*/
class MenuDeleteMenuForm extends ConfirmFormBase {
/**
* The menu object to be deleted.
*
* @var \Drupal\system\Plugin\Core\Entity\Menu
*/
protected $menu;
/**
* {@inheritdoc}
*/
protected function getQuestion() {
return t('Are you sure you want to delete the custom menu %title?', array('%title' => $this->menu->label()));
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
return 'admin/structure/menu/manage/' . $this->menu->id();
}
/**
* {@inheritdoc}
*/
protected function getDescription() {
$caption = '';
$num_links = \Drupal::entityManager()
->getStorageController('menu_link')->countMenuLinks($this->menu->id());
if ($num_links) {
$caption .= '<p>' . format_plural($num_links, '<strong>Warning:</strong> There is currently 1 menu link in %title. It will be deleted (system-defined items will be reset).', '<strong>Warning:</strong> There are currently @count menu links in %title. They will be deleted (system-defined links will be reset).', array('%title' => $this->menu->label())) . '</p>';
}
$caption .= '<p>' . t('This action cannot be undone.') . '</p>';
return $caption;
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'menu_delete_menu_confirm';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, Menu $menu = NULL) {
$this->menu = $menu;
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$form_state['redirect'] = 'admin/structure/menu';
// System-defined menus may not be deleted - only menus defined by this module.
$system_menus = menu_list_system_menus();
if (isset($system_menus[$this->menu->id()])) {
return;
}
// Reset all the menu links defined by the system via hook_menu().
// @todo Convert this to an EFQ once we figure out 'ORDER BY m.number_parts'.
$result = db_query("SELECT mlid FROM {menu_links} ml INNER JOIN {menu_router} m ON ml.router_path = m.path WHERE ml.menu_name = :menu AND ml.module = 'system' ORDER BY m.number_parts ASC", array(':menu' => $this->menu->id()), array('fetch' => \PDO::FETCH_ASSOC))->fetchCol();
$menu_links = menu_link_load_multiple($result);
foreach ($menu_links as $link) {
$link->reset();
}
// Delete all links to the overview page for this menu.
$menu_links = entity_load_multiple_by_properties('menu_link', array('link_path' => 'admin/structure/menu/manage/' . $this->menu->id()));
menu_link_delete_multiple(array_keys($menu_links));
// Delete the custom menu and all its menu links.
$this->menu->delete();
$t_args = array('%title' => $this->menu->label());
drupal_set_message(t('The custom menu %title has been deleted.', $t_args));
watchdog('menu', 'Deleted custom menu %title and all its menu links.', $t_args, WATCHDOG_NOTICE);
}
}

View File

@ -7,59 +7,36 @@
namespace Drupal\menu\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\menu_link\Plugin\Core\Entity\MenuLink;
use Drupal\Core\Entity\EntityConfirmFormBase;
/**
* Defines a confirmation form for deletion of a single menu link.
*/
class MenuLinkDeleteForm extends ConfirmFormBase {
/**
* The menu link object to be deleted.
*
* @var \Drupal\menu_link\Plugin\Core\Entity\MenuLink
*/
protected $menuLink;
class MenuLinkDeleteForm extends EntityConfirmFormBase {
/**
* {@inheritdoc}
*/
protected function getQuestion() {
return t('Are you sure you want to delete the custom menu link %item?', array('%item' => $this->menuLink->link_title));
public function getQuestion() {
return t('Are you sure you want to delete the custom menu link %item?', array('%item' => $this->entity->link_title));
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
return 'admin/structure/menu/manage/' . $this->menuLink->menu_name;
public function getCancelPath() {
return 'admin/structure/menu/manage/' . $this->entity->menu_name;
}
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'menu_link_delete_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, MenuLink $menu_link = NULL) {
$this->menuLink = $menu_link;
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
menu_link_delete($this->menuLink->id());
$t_args = array('%title' => $this->menuLink->link_title);
public function submit(array $form, array &$form_state) {
menu_link_delete($this->entity->id());
$t_args = array('%title' => $this->entity->link_title);
drupal_set_message(t('The menu link %title has been deleted.', $t_args));
watchdog('menu', 'Deleted menu link %title.', $t_args, WATCHDOG_NOTICE);
$form_state['redirect'] = 'admin/structure/menu/manage/' . $this->menuLink->menu_name;
$form_state['redirect'] = 'admin/structure/menu/manage/' . $this->entity->menu_name;
}
}

View File

@ -7,71 +7,48 @@
namespace Drupal\menu\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\menu_link\Plugin\Core\Entity\MenuLink;
use Drupal\Core\Entity\EntityConfirmFormBase;
/**
* Defines a confirmation form for resetting a single modified menu link.
*/
class MenuLinkResetForm extends ConfirmFormBase {
/**
* The menu link object to be deleted.
*
* @var \Drupal\menu_link\Plugin\Core\Entity\MenuLink
*/
protected $menuLink;
class MenuLinkResetForm extends EntityConfirmFormBase {
/**
* {@inheritdoc}
*/
protected function getQuestion() {
return t('Are you sure you want to reset the link %item to its default values?', array('%item' => $this->menuLink->link_title));
public function getQuestion() {
return t('Are you sure you want to reset the link %item to its default values?', array('%item' => $this->entity->link_title));
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
return 'admin/structure/menu/manage/' . $this->menuLink->menu_name;
public function getCancelPath() {
return 'admin/structure/menu/manage/' . $this->entity->menu_name;
}
/**
* {@inheritdoc}
*/
protected function getDescription() {
public function getDescription() {
return t('Any customizations will be lost. This action cannot be undone.');
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
public function getConfirmText() {
return t('Reset');
}
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'menu_link_reset_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, MenuLink $menu_link = NULL) {
$this->menuLink = $menu_link;
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$new_menu_link = $this->menuLink->reset();
public function submit(array $form, array &$form_state) {
$new_menu_link = $this->entity->reset();
drupal_set_message(t('The menu link was reset to its default settings.'));
$form_state['redirect'] = 'admin/structure/menu/manage/' . $new_menu_link->menu_name;
}
}

View File

@ -142,14 +142,18 @@ function menu_menu() {
}
/**
* Implements hook_entity_info_alter().
* Implements hook_entity_info().
*/
function menu_entity_info_alter(&$entity_info) {
function menu_entity_info(&$entity_info) {
$entity_info['menu']['controllers']['list'] = 'Drupal\menu\MenuListController';
$entity_info['menu']['uri_callback'] = 'menu_uri';
$entity_info['menu']['controllers']['form'] = array(
'default' => 'Drupal\menu\MenuFormController',
'delete' => 'Drupal\menu\Form\MenuDeleteForm',
);
$entity_info['menu_link']['controllers']['form']['delete'] = 'Drupal\menu\Form\MenuLinkDeleteForm';
$entity_info['menu_link']['controllers']['form']['reset'] = 'Drupal\menu\Form\MenuLinkResetForm';
}
/**

View File

@ -8,20 +8,20 @@ menu_settings:
menu_link_reset:
pattern: 'admin/structure/menu/item/{menu_link}/reset'
defaults:
_form: '\Drupal\menu\Form\MenuLinkResetForm'
_entity_form: 'menu_link.reset'
requirements:
_permission: 'administer menu'
menu_link_delete:
pattern: 'admin/structure/menu/item/{menu_link}/delete'
defaults:
_form: '\Drupal\menu\Form\MenuLinkDeleteForm'
_entity_form: 'menu_link.delete'
requirements:
_access_menu_delete_link: 'TRUE'
menu_delete_menu:
pattern: 'admin/structure/menu/manage/{menu}/delete'
defaults:
_form: '\Drupal\menu\Form\MenuDeleteMenuForm'
_entity_form: 'menu.delete'
requirements:
_access_menu_delete_menu: 'TRUE'

View File

@ -73,21 +73,21 @@ class DeleteMultiple extends ConfirmFormBase implements ControllerInterface {
/**
* {@inheritdoc}
*/
protected function getQuestion() {
public function getQuestion() {
return format_plural(count($this->nodes), 'Are you sure you want to delete this item?', 'Are you sure you want to delete these items?');
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
public function getCancelPath() {
return 'admin/content';
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
public function getConfirmText() {
return t('Delete');
}

View File

@ -1919,6 +1919,11 @@ function theme_node_recent_content($variables) {
* Adds node-type specific visibility options to block configuration form.
*/
function node_form_block_form_alter(&$form, &$form_state) {
// These options should be added to most block forms, but not when deleting.
if ($form_state['controller']->getOperation() == 'delete') {
return;
}
$block = $form_state['controller']->getEntity();
$visibility = $block->get('visibility');
$form['visibility']['node_type'] = array(

View File

@ -7,10 +7,11 @@
namespace Drupal\path\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Controller\ControllerInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Path\Path;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Builds the form to delete a path alias.
@ -60,24 +61,24 @@ class DeleteForm extends ConfirmFormBase implements ControllerInterface {
/**
* Implements \Drupal\Core\Form\ConfirmFormBase::getQuestion().
*/
protected function getQuestion() {
public function getQuestion() {
return t('Are you sure you want to delete path alias %title?', array('%title' => $this->pathAlias['alias']));
}
/**
* Implements \Drupal\Core\Form\ConfirmFormBase::getCancelPath().
*/
protected function getCancelPath() {
public function getCancelPath() {
return 'admin/config/search/path';
}
/**
* Overrides \Drupal\Core\Form\ConfirmFormBase::buildForm().
*/
public function buildForm(array $form, array &$form_state, $pid = NULL) {
public function buildForm(array $form, array &$form_state, $pid = NULL, Request $request = NULL) {
$this->pathAlias = $this->path->load(array('pid' => $pid));
return parent::buildForm($form, $form_state);
return parent::buildForm($form, $form_state, $request);
}
/**

View File

@ -1,68 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\picture\Form\PictureMappingActionConfirm.
*/
namespace Drupal\picture\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Entity\EntityInterface;
class PictureMappingActionConfirmForm extends ConfirmFormBase {
/**
* The picture mapping object to be deleted.
*
* @var type \Drupal\Core\Entity\EntityInterface
*/
protected $pictureMapping;
/**
* {@inheritdoc}
*/
protected function getQuestion() {
return t('Are you sure you want to delete the picture_mapping %title?', array('%title' => $this->pictureMapping->label()));
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
return 'admin/config/media/picturemapping';
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'picture_mapping_action_confirm';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, EntityInterface $picture_mapping = NULL) {
$this->pictureMapping = $picture_mapping;
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$this->pictureMapping->delete();
drupal_set_message(t('Picture mapping %label has been deleted.', array('%label' => $this->pictureMapping->label())));
watchdog('picture', 'Picture mapping %label has been deleted.', array('%label' => $this->pictureMapping->label()), WATCHDOG_NOTICE);
$form_state['redirect'] = 'admin/config/media/picturemapping';
}
}

View File

@ -0,0 +1,45 @@
<?php
/**
* @file
* Contains \Drupal\picture\Form\PictureMappingActionConfirm.
*/
namespace Drupal\picture\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
class PictureMappingDeleteForm extends EntityConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getQuestion() {
return t('Are you sure you want to delete the picture_mapping %title?', array('%title' => $this->entity->label()));
}
/**
* {@inheritdoc}
*/
public function getCancelPath() {
return 'admin/config/media/picturemapping';
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
public function submit(array $form, array &$form_state) {
$this->entity->delete();
drupal_set_message(t('Picture mapping %label has been deleted.', array('%label' => $this->entity->label())));
watchdog('picture', 'Picture mapping %label has been deleted.', array('%label' => $this->entity->label()), WATCHDOG_NOTICE);
$form_state['redirect'] = 'admin/config/media/picturemapping';
}
}

View File

@ -25,6 +25,7 @@ use Drupal\picture\PictureMappingInterface;
* "form" = {
* "edit" = "Drupal\picture\PictureMappingFormController",
* "add" = "Drupal\picture\PictureMappingFormController",
* "delete" = "Drupal\picture\Form\PictureMappingDeleteForm",
* "duplicate" = "Drupal\picture\PictureMappingFormController"
* }
* },

View File

@ -29,6 +29,6 @@ picture_mapping_page_duplicate:
picture_mapping_action_confirm:
pattern: '/admin/config/media/picturemapping/{picture_mapping}/delete'
defaults:
_form: '\Drupal\picture\Form\PictureMappingActionConfirmForm'
_entity_form: 'picture_mapping.delete'
requirements:
_permission: 'administer pictures'

View File

@ -9,6 +9,7 @@ namespace Drupal\shortcut\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\menu_link\Plugin\Core\Entity\MenuLink;
use Symfony\Component\HttpFoundation\Request;
/**
* Builds the shortcut link deletion form.
@ -32,31 +33,31 @@ class LinkDelete extends ConfirmFormBase {
/**
* {@inheritdoc}
*/
protected function getQuestion() {
public function getQuestion() {
return t('Are you sure you want to delete the shortcut %title?', array('%title' => $this->menuLink->link_title));
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
public function getCancelPath() {
return 'admin/config/user-interface/shortcut/manage/' . $this->menuLink->menu_name;
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
public function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, MenuLink $menu_link = NULL) {
public function buildForm(array $form, array &$form_state, MenuLink $menu_link = NULL, Request $request = NULL) {
$this->menuLink = $menu_link;
return parent::buildForm($form, $form_state);
return parent::buildForm($form, $form_state, $request);
}
/**

View File

@ -2,22 +2,23 @@
/**
* @file
* Contains \Drupal\shortcut\Form\SetDelete.
* Contains \Drupal\shortcut\Form\ShortcutDeleteForm.
*/
namespace Drupal\shortcut\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Entity\EntityControllerInterface;
use Drupal\shortcut\ShortcutStorageControllerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Controller\ControllerInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Database\Connection;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\shortcut\Plugin\Core\Entity\Shortcut;
use Symfony\Component\HttpFoundation\Request;
/**
* Builds the shortcut set deletion form.
*/
class SetDelete extends ConfirmFormBase implements ControllerInterface {
class ShortcutDeleteForm extends EntityConfirmFormBase implements EntityControllerInterface {
/**
* The database connection.
@ -34,68 +35,60 @@ class SetDelete extends ConfirmFormBase implements ControllerInterface {
protected $moduleHandler;
/**
* The shortcut set being deleted.
* The shortcut storage controller.
*
* @var \Drupal\shortcut\Plugin\Core\Entity\Shortcut
* @var \Drupal\shortcut\ShortcutStorageControllerInterface
*/
protected $shortcut;
protected $storageController;
/**
* Constructs a SetDelete object.
* Constructs a ShortcutDeleteForm object.
*/
public function __construct(Connection $database, ModuleHandlerInterface $module_handler) {
public function __construct(Connection $database, ModuleHandlerInterface $module_handler, ShortcutStorageControllerInterface $storage_controller) {
$this->database = $database;
$this->moduleHandler = $module_handler;
$this->storageController = $storage_controller;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) {
return new static(
$container->get('database'),
$container->get('module_handler')
$container->get('module_handler'),
$container->get('plugin.manager.entity')->getStorageController('shortcut')
);
}
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'shortcut_set_delete_form';
public function getQuestion() {
return t('Are you sure you want to delete the shortcut set %title?', array('%title' => $this->entity->label()));
}
/**
* {@inheritdoc}
*/
protected function getQuestion() {
return t('Are you sure you want to delete the shortcut set %title?', array('%title' => $this->shortcut->label()));
public function getCancelPath() {
return 'admin/config/user-interface/shortcut/manage/' . $this->entity->id();
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
return 'admin/config/user-interface/shortcut/manage/' . $this->shortcut->id();
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
public function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, Shortcut $shortcut = NULL) {
$this->shortcut = $shortcut;
public function buildForm(array $form, array &$form_state, Request $request = NULL) {
// Find out how many users are directly assigned to this shortcut set, and
// make a message.
$number = \Drupal::entityManager()->getStorageController('shortcut')->countAssignedUsers($shortcut);
$number = $this->storageController->countAssignedUsers($this->entity);
$info = '';
if ($number) {
$info .= '<p>' . format_plural($number,
@ -113,16 +106,16 @@ class SetDelete extends ConfirmFormBase implements ControllerInterface {
'#markup' => $info,
);
return parent::buildForm($form, $form_state);
return parent::buildForm($form, $form_state, $request);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$this->shortcut->delete();
public function submit(array $form, array &$form_state) {
$this->entity->delete();
$form_state['redirect'] = 'admin/config/user-interface/shortcut';
drupal_set_message(t('The shortcut set %title has been deleted.', array('%title' => $this->shortcut->label())));
drupal_set_message(t('The shortcut set %title has been deleted.', array('%title' => $this->entity->label())));
}
}

View File

@ -26,7 +26,8 @@ use Drupal\shortcut\ShortcutInterface;
* "list" = "Drupal\shortcut\ShortcutListController",
* "form" = {
* "default" = "Drupal\shortcut\ShortcutFormController",
* "edit" = "Drupal\shortcut\ShortcutFormController"
* "edit" = "Drupal\shortcut\ShortcutFormController",
* "delete" = "Drupal\shortcut\Form\ShortcutDeleteForm"
* }
* },
* config_prefix = "shortcut.set",

View File

@ -8,7 +8,7 @@ shortcut_link_delete:
shortcut_set_delete:
pattern: '/admin/config/user-interface/shortcut/manage/{shortcut}/delete'
defaults:
_form: 'Drupal\shortcut\Form\SetDelete'
_entity_form: 'shortcut.delete'
requirements:
_entity_access: 'shortcut.delete'
@ -18,6 +18,7 @@ shortcut_set_admin:
_content: 'Drupal\shortcut\Controller\ShortcutController::shortcutSetAdmin'
requirements:
_permission: 'administer shortcuts'
shortcut_set_edit:
pattern: '/admin/config/user-interface/shortcut/manage/{shortcut}/edit'
defaults:

View File

@ -11,6 +11,7 @@ use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Controller\ControllerInterface;
use Drupal\Core\Config\ConfigFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Builds a form to delete a date format.
@ -64,7 +65,7 @@ class DateFormatDeleteForm extends ConfirmFormBase implements ControllerInterfac
/**
* {@inheritdoc}
*/
protected function getQuestion() {
public function getQuestion() {
return t('Are you sure you want to remove the format %name : %format?', array(
'%name' => $this->format['name'],
'%format' => format_date(REQUEST_TIME, $this->formatID))
@ -74,14 +75,14 @@ class DateFormatDeleteForm extends ConfirmFormBase implements ControllerInterfac
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
public function getConfirmText() {
return t('Remove');
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
public function getCancelPath() {
return 'admin/config/regional/date-time/formats';
}
@ -91,12 +92,12 @@ class DateFormatDeleteForm extends ConfirmFormBase implements ControllerInterfac
* @param string $format_id
* The date format ID.
*/
public function buildForm(array $form, array &$form_state, $format_id = NULL) {
public function buildForm(array $form, array &$form_state, $format_id = NULL, Request $request = NULL) {
// We don't get the format ID in the returned format array.
$this->formatID = $format_id;
$this->format = $this->configFactory->get('system.date')->get("formats.$format_id");
return parent::buildForm($form, $form_state);
return parent::buildForm($form, $form_state, $request);
}
/**

View File

@ -7,10 +7,11 @@
namespace Drupal\system\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Controller\ControllerInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Config\ConfigFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Builds a form for enabling a module.
@ -57,7 +58,7 @@ class DateFormatLocalizeResetForm extends ConfirmFormBase implements ControllerI
/**
* {@inheritdoc}
*/
protected function getQuestion() {
public function getQuestion() {
return t('Are you sure you want to reset the date formats for %language to the global defaults?', array(
'%language' => $this->language->name,
));
@ -66,21 +67,21 @@ class DateFormatLocalizeResetForm extends ConfirmFormBase implements ControllerI
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
public function getConfirmText() {
return t('Reset');
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
public function getCancelPath() {
return 'admin/config/regional/date-time/locale';
}
/**
* {@inheritdoc}
*/
protected function getDescription() {
public function getDescription() {
return t('Resetting will remove all localized date formats for this language. This action cannot be undone.');
}
@ -91,10 +92,10 @@ class DateFormatLocalizeResetForm extends ConfirmFormBase implements ControllerI
* The language code.
*
*/
public function buildForm(array $form, array &$form_state, $langcode = NULL) {
public function buildForm(array $form, array &$form_state, $langcode = NULL, Request $request = NULL) {
$this->language = language_load($langcode);
return parent::buildForm($form, $form_state);
return parent::buildForm($form, $form_state, $request);
}
/**

View File

@ -8,6 +8,7 @@
namespace Drupal\system\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Symfony\Component\HttpFoundation\Request;
/**
* Builds a confirmation form for required modules.
@ -19,28 +20,28 @@ class ModulesInstallConfirmForm extends ConfirmFormBase {
/**
* {@inheritdoc}
*/
protected function getQuestion() {
public function getQuestion() {
return t('Some required modules must be enabled');
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
public function getConfirmText() {
return t('Continue');
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
public function getCancelPath() {
return 'admin/modules';
}
/**
* {@inheritdoc}
*/
protected function getDescription() {
public function getDescription() {
return t('Would you like to continue with the above?');
}
@ -58,7 +59,7 @@ class ModulesInstallConfirmForm extends ConfirmFormBase {
* @param array $storage
* Temporary storage of module dependency information.
*/
public function buildForm(array $form, array &$form_state, $modules = array(), $storage = array()) {
public function buildForm(array $form, array &$form_state, $modules = array(), $storage = array(), Request $request = NULL) {
$items = array();
$form['validation_modules'] = array('#type' => 'value', '#value' => $modules);
@ -82,7 +83,7 @@ class ModulesInstallConfirmForm extends ConfirmFormBase {
$form['modules'] = array('#theme' => 'item_list', '#items' => $items);
return parent::buildForm($form, $form_state);
return parent::buildForm($form, $form_state, $request);
}
/**

View File

@ -8,6 +8,7 @@
namespace Drupal\system\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Symfony\Component\HttpFoundation\Request;
/**
* Builds a confirmation form to uninstall selected modules.
@ -19,28 +20,28 @@ class ModulesUninstallConfirmForm extends ConfirmFormBase {
/**
* {@inheritdoc}
*/
protected function getQuestion() {
public function getQuestion() {
return t('Confirm uninstall');
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
public function getConfirmText() {
return t('Uninstall');
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
public function getCancelPath() {
return 'admin/modules/uninstall';
}
/**
* {@inheritdoc}
*/
protected function getDescription() {
public function getDescription() {
return t('Would you like to continue with uninstalling the above?');
}
@ -57,7 +58,7 @@ class ModulesUninstallConfirmForm extends ConfirmFormBase {
* @param array $modules
* The array of modules.
*/
public function buildForm(array $form, array &$form_state, $modules = array()) {
public function buildForm(array $form, array &$form_state, $modules = array(), Request $request = NULL) {
$uninstall = array();
// Construct the hidden form elements and list items.
foreach ($modules as $module => $value) {
@ -71,7 +72,7 @@ class ModulesUninstallConfirmForm extends ConfirmFormBase {
$form['text'] = array('#markup' => '<p>' . t('The following modules will be completely uninstalled from your site, and <em>all data from these modules will be lost</em>!') . '</p>');
$form['modules'] = array('#theme' => 'item_list', '#items' => $uninstall);
return parent::buildForm($form, $form_state);
return parent::buildForm($form, $form_state, $request);
}
/**

View File

@ -750,7 +750,7 @@ function system_modules($form, $form_state = array()) {
// Contents of confirm form is injected here because already in form
// building function.
$confirm_form = new ModulesInstallConfirmForm();
return $confirm_form->buildForm($form, $form_state, $visible_files, $form_state['storage']);
return $confirm_form->buildForm($form, $form_state, $visible_files, $form_state['storage'], Drupal::request());
}
// JS-only table filters.
@ -1163,7 +1163,7 @@ function system_modules_uninstall($form, $form_state = NULL) {
// Contents of confirm form is injected here because already in form
// building function.
$confirm_form = new ModulesUninstallConfirmForm();
return $confirm_form->buildForm($form, $form_state, $modules);
return $confirm_form->buildForm($form, $form_state, $modules, Drupal::request());
}
// Get a list of disabled, installed modules.

View File

@ -22,7 +22,7 @@ class ConfirmFormArrayPathTestForm extends ConfirmFormTestForm {
/**
* Overrides \Drupal\form_test\ConfirmFormTestForm::getCancelPath().
*/
protected function getCancelPath() {
public function getCancelPath() {
return array(
'path' => 'admin',
'query' => array(
@ -34,7 +34,7 @@ class ConfirmFormArrayPathTestForm extends ConfirmFormTestForm {
/**
* Overrides \Drupal\form_test\ConfirmFormTestForm::getCancelText().
*/
protected function getCancelText() {
public function getCancelText() {
return t('ConfirmFormArrayPathTestForm::getCancelText().');
}

View File

@ -8,6 +8,7 @@
namespace Drupal\form_test;
use Drupal\Core\Form\ConfirmFormBase;
use Symfony\Component\HttpFoundation\Request;
/**
* Provides a test confirmation form.
@ -15,58 +16,58 @@ use Drupal\Core\Form\ConfirmFormBase;
class ConfirmFormTestForm extends ConfirmFormBase {
/**
* Implements \Drupal\Core\Form\FormInterface::getFormID().
* {@inheritdoc}
*/
public function getFormID() {
return 'form_test_confirm_test_form';
}
/**
* Implements \Drupal\Core\Form\ConfirmFormBase::getQuestion().
* {@inheritdoc}
*/
protected function getQuestion() {
public function getQuestion() {
return t('ConfirmFormTestForm::getQuestion().');
}
/**
* Implements \Drupal\Core\Form\ConfirmFormBase::getCancelPath().
* {@inheritdoc}
*/
protected function getCancelPath() {
public function getCancelPath() {
return 'admin';
}
/**
* Overrides \Drupal\Core\Form\ConfirmFormBase::getDescription().
* {@inheritdoc}
*/
protected function getDescription() {
public function getDescription() {
return t('ConfirmFormTestForm::getDescription().');
}
/**
* Overrides \Drupal\Core\Form\ConfirmFormBase::getConfirmText().
* {@inheritdoc}
*/
protected function getConfirmText() {
public function getConfirmText() {
return t('ConfirmFormTestForm::getConfirmText().');
}
/**
* Overrides \Drupal\Core\Form\ConfirmFormBase::getCancelText().
* {@inheritdoc}
*/
protected function getCancelText() {
public function getCancelText() {
return t('ConfirmFormTestForm::getCancelText().');
}
/**
* Overrides \Drupal\Core\Form\ConfirmFormBase::buildForm().
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
public function buildForm(array $form, array &$form_state, Request $request = NULL) {
$form['element'] = array('#markup' => '<p>The ConfirmFormTestForm::buildForm() method was used for this form.</p>');
return parent::buildForm($form, $form_state);
return parent::buildForm($form, $form_state, $request);
}
/**
* Implements \Drupal\Core\Form\FormInterface::submitForm().
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
drupal_set_message(t('The ConfirmFormTestForm::submitForm() method was used for this form.'));

View File

@ -7,66 +7,41 @@
namespace Drupal\user\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\user\RoleInterface;
use Drupal\Core\Entity\EntityConfirmFormBase;
/**
* Provides a deletion confirmation form for Role entity.
*/
class UserRoleDelete extends ConfirmFormBase {
/**
* The role being deleted.
*
* @var \Drupal\user\RoleInterface
*/
protected $role;
class UserRoleDelete extends EntityConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'user_admin_role_delete_confirm';
public function getQuestion() {
return t('Are you sure you want to delete the role %name?', array('%name' => $this->entity->label()));
}
/**
* {@inheritdoc}
*/
protected function getQuestion() {
return t('Are you sure you want to delete the role %name?', array('%name' => $this->role->label()));
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
public function getCancelPath() {
return 'admin/people/roles';
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
public function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
* @param \Drupal\user\RoleInterface $user_role
* The role being deleted.
*/
public function buildForm(array $form, array &$form_state, RoleInterface $user_role = NULL) {
$this->role = $user_role;
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$this->role->delete();
watchdog('user', 'Role %name has been deleted.', array('%name' => $this->role->label()));
drupal_set_message(t('Role %name has been deleted.', array('%name' => $this->role->label())));
public function submit(array $form, array &$form_state) {
$this->entity->delete();
watchdog('user', 'Role %name has been deleted.', array('%name' => $this->entity->label()));
drupal_set_message(t('Role %name has been deleted.', array('%name' => $this->entity->label())));
$form_state['redirect'] = 'admin/people/roles';
}

View File

@ -25,7 +25,8 @@ use Drupal\user\RoleInterface;
* "access" = "Drupal\user\RoleAccessController",
* "list" = "Drupal\user\RoleListController",
* "form" = {
* "default" = "Drupal\user\RoleFormController"
* "default" = "Drupal\user\RoleFormController",
* "delete" = "Drupal\user\Form\UserRoleDelete"
* }
* },
* config_prefix = "user.role",

View File

@ -64,6 +64,6 @@ user_role_edit:
user_role_delete:
pattern: '/admin/people/roles/manage/{user_role}/delete'
defaults:
_form: '\Drupal\user\Form\UserRoleDelete'
_entity_form: user_role.delete
requirements:
_entity_access: user_role.delete

View File

@ -7,18 +7,17 @@
namespace Drupal\views_ui\Form;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Controller\ControllerInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\views\ViewStorageInterface;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Entity\EntityControllerInterface;
use Drupal\Core\Entity\EntityManager;
use Drupal\user\TempStoreFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Builds the form to break the lock of an edited view.
*/
class BreakLockForm extends ConfirmFormBase implements ControllerInterface {
class BreakLockForm extends EntityConfirmFormBase implements EntityControllerInterface {
/**
* Stores the Entity manager.
@ -34,13 +33,6 @@ class BreakLockForm extends ConfirmFormBase implements ControllerInterface {
*/
protected $tempStore;
/**
* The view being deleted.
*
* @var \Drupal\views\ViewStorageInterface
*/
protected $view;
/**
* Constructs a \Drupal\views_ui\Form\BreakLockForm object.
*
@ -57,7 +49,7 @@ class BreakLockForm extends ConfirmFormBase implements ControllerInterface {
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) {
return new static(
$container->get('plugin.manager.entity'),
$container->get('user.tempstore')
@ -65,60 +57,59 @@ class BreakLockForm extends ConfirmFormBase implements ControllerInterface {
}
/**
* Implements \Drupal\Core\Form\FormInterface::getFormID().
* {@inheritdoc}
*/
public function getFormID() {
return 'views_ui_break_lock_confirm';
}
/**
* Implements \Drupal\Core\Form\ConfirmFormBase::getQuestion().
* {@inheritdoc}
*/
protected function getQuestion() {
return t('Do you want to break the lock on view %name?', array('%name' => $this->view->id()));
public function getQuestion() {
return t('Do you want to break the lock on view %name?', array('%name' => $this->entity->id()));
}
/**
* Implements \Drupal\Core\Form\ConfirmFormBase::getDescription().
* {@inheritdoc}
*/
protected function getDescription() {
$locked = $this->tempStore->getMetadata($this->view->id());
public function getDescription() {
$locked = $this->tempStore->getMetadata($this->entity->id());
$accounts = $this->entityManager->getStorageController('user')->load(array($locked->owner));
return t('By breaking this lock, any unsaved changes made by !user will be lost.', array('!user' => theme('username', array('account' => reset($accounts)))));
}
/**
* Implements \Drupal\Core\Form\ConfirmFormBase::getCancelPath().
* {@inheritdoc}
*/
protected function getCancelPath() {
return 'admin/structure/views/view/' . $this->view->id();
public function getCancelPath() {
return 'admin/structure/views/view/' . $this->entity->id();
}
/**
* Implements \Drupal\Core\Form\ConfirmFormBase::getConfirmText().
* {@inheritdoc}
*/
protected function getConfirmText() {
public function getConfirmText() {
return t('Break lock');
}
/**
* Implements \Drupal\Core\Form\FormInterface::buildForm().
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, ViewStorageInterface $view = NULL) {
$this->view = $view;
if (!$this->tempStore->getMetadata($this->view->id())) {
$form['message']['#markup'] = t('There is no lock on view %name to break.', array('%name' => $this->view->id()));
public function buildForm(array $form, array &$form_state, Request $request = NULL) {
if (!$this->tempStore->getMetadata($this->entity->id())) {
$form['message']['#markup'] = t('There is no lock on view %name to break.', array('%name' => $this->entity->id()));
return $form;
}
return parent::buildForm($form, $form_state);
return parent::buildForm($form, $form_state, $request);
}
/**
* Implements \Drupal\Core\Form\FormInterface::submitForm().
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$this->tempStore->delete($this->view->id());
$form_state['redirect'] = 'admin/structure/views/view/' . $this->view->id();
public function submit(array $form, array &$form_state) {
$this->tempStore->delete($this->entity->id());
$form_state['redirect'] = 'admin/structure/views/view/' . $this->entity->id();
drupal_set_message(t('The lock has been broken and you may now edit this view.'));
}

View File

@ -1,75 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\views_ui\Form\DeleteForm.
*/
namespace Drupal\views_ui\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\views\ViewStorageInterface;
/**
* Builds the form to delete a view.
*/
class DeleteForm extends ConfirmFormBase {
/**
* The view being deleted.
*
* @var \Drupal\views\ViewStorageInterface
*/
protected $view;
/**
* Implements \Drupal\Core\Form\ConfirmFormBase::getQuestion().
*/
protected function getQuestion() {
return t('Are you sure you want to delete the %name view?', array('%name' => $this->view->label()));
}
/**
* Implements \Drupal\Core\Form\ConfirmFormBase::getCancelPath().
*/
protected function getCancelPath() {
return 'admin/structure/views';
}
/**
* Implements \Drupal\Core\Form\ConfirmFormBase::getConfirmText().
*/
protected function getConfirmText() {
return t('Delete');
}
/**
* Implements \Drupal\Core\Form\FormInterface::getFormID().
*/
public function getFormID() {
return 'views_ui_confirm_delete';
}
/**
* Implements \Drupal\Core\Form\FormInterface::buildForm().
*/
public function buildForm(array $form, array &$form_state, ViewStorageInterface $view = NULL) {
$this->view = $view;
return parent::buildForm($form, $form_state);
}
/**
* Implements \Drupal\Core\Form\FormInterface::validateForm().
*/
public function validateForm(array &$form, array &$form_state) {
}
/**
* Implements \Drupal\Core\Form\FormInterface::submitForm().
*/
public function submitForm(array &$form, array &$form_state) {
$this->view->delete();
$form_state['redirect'] = 'admin/structure/views';
}
}

View File

@ -0,0 +1,48 @@
<?php
/**
* @file
* Contains \Drupal\views_ui\ViewDeleteFormController.
*/
namespace Drupal\views_ui;
use Drupal\Core\Entity\EntityConfirmFormBase;
/**
* Provides a delete form for a view.
*/
class ViewDeleteFormController extends EntityConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getQuestion() {
return t('Are you sure you want to delete the %name view?', array('%name' => $this->entity->label()));
}
/**
* {@inheritdoc}
*/
public function getCancelPath() {
return 'admin/structure/views';
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
public function submit(array $form, array &$form_state) {
parent::submit($form, $form_state);
$this->entity->delete();
$form_state['redirect'] = 'admin/structure/views';
}
}

View File

@ -108,6 +108,8 @@ function views_ui_entity_info(&$entity_info) {
'add' => 'Drupal\views_ui\ViewAddFormController',
'preview' => 'Drupal\views_ui\ViewPreviewFormController',
'clone' => 'Drupal\views_ui\ViewCloneFormController',
'delete' => 'Drupal\views_ui\ViewDeleteFormController',
'break_lock' => 'Drupal\views_ui\Form\BreakLockForm',
),
);
}

View File

@ -58,7 +58,7 @@ views_ui.clone:
views_ui.delete:
pattern: '/admin/structure/views/view/{view}/delete'
defaults:
_form: 'Drupal\views_ui\Form\DeleteForm'
_entity_form: 'view.delete'
requirements:
_permission: 'administer views'
@ -104,8 +104,7 @@ views_ui.preview:
views_ui.breakLock:
pattern: '/admin/structure/views/view/{view}/break-lock'
defaults:
_form: '\Drupal\views_ui\Form\BreakLockForm'
display_id: NULL
_entity_form: 'view.break_lock'
requirements:
_permission: 'administer views'