diff --git a/core/lib/Drupal/Core/Entity/EntityConfirmFormBase.php b/core/lib/Drupal/Core/Entity/EntityConfirmFormBase.php new file mode 100644 index 00000000000..8e0292b18cb --- /dev/null +++ b/core/lib/Drupal/Core/Entity/EntityConfirmFormBase.php @@ -0,0 +1,108 @@ +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; + } + +} diff --git a/core/lib/Drupal/Core/Entity/EntityNGConfirmFormBase.php b/core/lib/Drupal/Core/Entity/EntityNGConfirmFormBase.php new file mode 100644 index 00000000000..1c345a0a6fa --- /dev/null +++ b/core/lib/Drupal/Core/Entity/EntityNGConfirmFormBase.php @@ -0,0 +1,108 @@ +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; + } + +} diff --git a/core/lib/Drupal/Core/Form/ConfirmFormBase.php b/core/lib/Drupal/Core/Form/ConfirmFormBase.php index 2aedb4116fe..e5899c519f4 100644 --- a/core/lib/Drupal/Core/Form/ConfirmFormBase.php +++ b/core/lib/Drupal/Core/Form/ConfirmFormBase.php @@ -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) { } diff --git a/core/lib/Drupal/Core/Form/ConfirmFormInterface.php b/core/lib/Drupal/Core/Form/ConfirmFormInterface.php new file mode 100644 index 00000000000..5c34f9a4cc6 --- /dev/null +++ b/core/lib/Drupal/Core/Form/ConfirmFormInterface.php @@ -0,0 +1,68 @@ + $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'; + } + +} diff --git a/core/modules/action/lib/Drupal/action/Form/DeleteForm.php b/core/modules/action/lib/Drupal/action/Form/DeleteForm.php deleted file mode 100644 index a3d2b3c3a5f..00000000000 --- a/core/modules/action/lib/Drupal/action/Form/DeleteForm.php +++ /dev/null @@ -1,75 +0,0 @@ - $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'; - } - -} diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module index 6bb308917e5..ebc45bd159a 100644 --- a/core/modules/aggregator/aggregator.module +++ b/core/modules/aggregator/aggregator.module @@ -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. * diff --git a/core/modules/aggregator/aggregator.routing.yml b/core/modules/aggregator/aggregator.routing.yml index 311ff42828d..e25527c4c9d 100644 --- a/core/modules/aggregator/aggregator.routing.yml +++ b/core/modules/aggregator/aggregator.routing.yml @@ -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' diff --git a/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.php b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.php index 1f56021c450..a01f20a93d5 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.php @@ -14,4 +14,9 @@ use Drupal\Core\Entity\ContentEntityInterface; */ interface FeedInterface extends ContentEntityInterface { + /** + * Removes all items from a feed. + */ + public function removeItems(); + } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Form/FeedDelete.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/FeedDelete.php deleted file mode 100644 index d613c398aeb..00000000000 --- a/core/modules/aggregator/lib/Drupal/aggregator/Form/FeedDelete.php +++ /dev/null @@ -1,75 +0,0 @@ - $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'; - } - } -} diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Form/FeedDeleteForm.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/FeedDeleteForm.php new file mode 100644 index 00000000000..cda6539c293 --- /dev/null +++ b/core/modules/aggregator/lib/Drupal/aggregator/Form/FeedDeleteForm.php @@ -0,0 +1,52 @@ + $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'; + } + } + +} diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Form/FeedItemsDelete.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/FeedItemsDelete.php deleted file mode 100644 index dbb79cd2115..00000000000 --- a/core/modules/aggregator/lib/Drupal/aggregator/Form/FeedItemsDelete.php +++ /dev/null @@ -1,70 +0,0 @@ - $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'; - } - -} diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Form/FeedItemsRemoveForm.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/FeedItemsRemoveForm.php new file mode 100644 index 00000000000..e374ca86c29 --- /dev/null +++ b/core/modules/aggregator/lib/Drupal/aggregator/Form/FeedItemsRemoveForm.php @@ -0,0 +1,47 @@ + $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'; + } + +} diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Core/Entity/Feed.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Core/Entity/Feed.php index 69c8e3469c4..9d06667ec46 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Core/Entity/Feed.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Core/Entity/Feed.php @@ -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(); } } + } diff --git a/core/modules/ban/lib/Drupal/ban/Form/BanDelete.php b/core/modules/ban/lib/Drupal/ban/Form/BanDelete.php index 24655dfb68a..ac1aa917efd 100644 --- a/core/modules/ban/lib/Drupal/ban/Form/BanDelete.php +++ b/core/modules/ban/lib/Drupal/ban/Form/BanDelete.php @@ -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); } /** diff --git a/core/modules/block/block.routing.yml b/core/modules/block/block.routing.yml index af247b074a3..c867bcae935 100644 --- a/core/modules/block/block.routing.yml +++ b/core/modules/block/block.routing.yml @@ -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' diff --git a/core/modules/block/lib/Drupal/block/Form/AdminBlockDeleteForm.php b/core/modules/block/lib/Drupal/block/Form/AdminBlockDeleteForm.php deleted file mode 100644 index ba6206a3023..00000000000 --- a/core/modules/block/lib/Drupal/block/Form/AdminBlockDeleteForm.php +++ /dev/null @@ -1,73 +0,0 @@ - $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'; - } - -} diff --git a/core/modules/block/lib/Drupal/block/Form/BlockDeleteForm.php b/core/modules/block/lib/Drupal/block/Form/BlockDeleteForm.php new file mode 100644 index 00000000000..3cc4a469a38 --- /dev/null +++ b/core/modules/block/lib/Drupal/block/Form/BlockDeleteForm.php @@ -0,0 +1,47 @@ + $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'; + } + +} diff --git a/core/modules/block/lib/Drupal/block/Plugin/Core/Entity/Block.php b/core/modules/block/lib/Drupal/block/Plugin/Core/Entity/Block.php index eb9b8a7d82f..1d3cca8d7a7 100644 --- a/core/modules/block/lib/Drupal/block/Plugin/Core/Entity/Block.php +++ b/core/modules/block/lib/Drupal/block/Plugin/Core/Entity/Block.php @@ -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", diff --git a/core/modules/config/tests/config_test/config_test.routing.yml b/core/modules/config/tests/config_test/config_test.routing.yml index 058b730d628..c26a438ede0 100644 --- a/core/modules/config/tests/config_test/config_test.routing.yml +++ b/core/modules/config/tests/config_test/config_test.routing.yml @@ -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' diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/Form/ConfigTestDeleteForm.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/Form/ConfigTestDeleteForm.php index 56798037229..c4e3d53af2a 100644 --- a/core/modules/config/tests/config_test/lib/Drupal/config_test/Form/ConfigTestDeleteForm.php +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/Form/ConfigTestDeleteForm.php @@ -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'; } diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/Plugin/Core/Entity/ConfigTest.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/Plugin/Core/Entity/ConfigTest.php index 7afb306729e..12a033bdf52 100644 --- a/core/modules/config/tests/config_test/lib/Drupal/config_test/Plugin/Core/Entity/ConfigTest.php +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/Plugin/Core/Entity/ConfigTest.php @@ -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", diff --git a/core/modules/contact/contact.routing.yml b/core/modules/contact/contact.routing.yml index fb5ce930b58..ba47a6aca97 100644 --- a/core/modules/contact/contact.routing.yml +++ b/core/modules/contact/contact.routing.yml @@ -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 diff --git a/core/modules/contact/lib/Drupal/contact/Form/CategoryDeleteForm.php b/core/modules/contact/lib/Drupal/contact/Form/CategoryDeleteForm.php new file mode 100644 index 00000000000..75988a7fb66 --- /dev/null +++ b/core/modules/contact/lib/Drupal/contact/Form/CategoryDeleteForm.php @@ -0,0 +1,48 @@ + $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'; + } + +} diff --git a/core/modules/contact/lib/Drupal/contact/Form/DeleteForm.php b/core/modules/contact/lib/Drupal/contact/Form/DeleteForm.php deleted file mode 100644 index 237d32e965b..00000000000 --- a/core/modules/contact/lib/Drupal/contact/Form/DeleteForm.php +++ /dev/null @@ -1,72 +0,0 @@ - $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'; - } - -} diff --git a/core/modules/contact/lib/Drupal/contact/Plugin/Core/Entity/Category.php b/core/modules/contact/lib/Drupal/contact/Plugin/Core/Entity/Category.php index f1aca0d870a..0b3323f3523 100644 --- a/core/modules/contact/lib/Drupal/contact/Plugin/Core/Entity/Category.php +++ b/core/modules/contact/lib/Drupal/contact/Plugin/Core/Entity/Category.php @@ -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", diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module index d115b7fc331..fefd9a198a0 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -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(). */ diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php index d5a42af520b..481cf7c2f96 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php @@ -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 diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php b/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php index 934a56e2f62..55477a04575 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php @@ -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); diff --git a/core/modules/filter/filter.routing.yml b/core/modules/filter/filter.routing.yml index a8f418649fd..0b9d357d0f6 100644 --- a/core/modules/filter/filter.routing.yml +++ b/core/modules/filter/filter.routing.yml @@ -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' diff --git a/core/modules/filter/lib/Drupal/filter/Form/DisableForm.php b/core/modules/filter/lib/Drupal/filter/Form/DisableForm.php deleted file mode 100644 index 49b71c874ca..00000000000 --- a/core/modules/filter/lib/Drupal/filter/Form/DisableForm.php +++ /dev/null @@ -1,79 +0,0 @@ - $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'; - } - -} diff --git a/core/modules/filter/lib/Drupal/filter/Form/FilterDisableForm.php b/core/modules/filter/lib/Drupal/filter/Form/FilterDisableForm.php new file mode 100644 index 00000000000..2759b2babd4 --- /dev/null +++ b/core/modules/filter/lib/Drupal/filter/Form/FilterDisableForm.php @@ -0,0 +1,55 @@ + $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'; + } + +} diff --git a/core/modules/filter/lib/Drupal/filter/Plugin/Core/Entity/FilterFormat.php b/core/modules/filter/lib/Drupal/filter/Plugin/Core/Entity/FilterFormat.php index 09b4df999c1..b3224b981e1 100644 --- a/core/modules/filter/lib/Drupal/filter/Plugin/Core/Entity/FilterFormat.php +++ b/core/modules/filter/lib/Drupal/filter/Plugin/Core/Entity/FilterFormat.php @@ -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", diff --git a/core/modules/forum/lib/Drupal/forum/Form/DeleteForm.php b/core/modules/forum/lib/Drupal/forum/Form/DeleteForm.php index 46df2b93bfa..7c4ba56bd19 100644 --- a/core/modules/forum/lib/Drupal/forum/Form/DeleteForm.php +++ b/core/modules/forum/lib/Drupal/forum/Form/DeleteForm.php @@ -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); } /** diff --git a/core/modules/image/image.routing.yml b/core/modules/image/image.routing.yml index 0aa23ba584f..b178d3307fe 100644 --- a/core/modules/image/image.routing.yml +++ b/core/modules/image/image.routing.yml @@ -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' diff --git a/core/modules/image/lib/Drupal/image/Form/ImageEffectDeleteForm.php b/core/modules/image/lib/Drupal/image/Form/ImageEffectDeleteForm.php index c3832c23b9a..50bf2bb9c98 100644 --- a/core/modules/image/lib/Drupal/image/Form/ImageEffectDeleteForm.php +++ b/core/modules/image/lib/Drupal/image/Form/ImageEffectDeleteForm.php @@ -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); } /** diff --git a/core/modules/image/lib/Drupal/image/Form/ImageStyleDeleteForm.php b/core/modules/image/lib/Drupal/image/Form/ImageStyleDeleteForm.php index 9719d38f535..681add90b54 100644 --- a/core/modules/image/lib/Drupal/image/Form/ImageStyleDeleteForm.php +++ b/core/modules/image/lib/Drupal/image/Form/ImageStyleDeleteForm.php @@ -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'; } diff --git a/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php b/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php index 1145c1b0540..c37778193ba 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php +++ b/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php @@ -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", diff --git a/core/modules/menu/lib/Drupal/menu/Form/MenuDeleteForm.php b/core/modules/menu/lib/Drupal/menu/Form/MenuDeleteForm.php new file mode 100644 index 00000000000..60129fafb35 --- /dev/null +++ b/core/modules/menu/lib/Drupal/menu/Form/MenuDeleteForm.php @@ -0,0 +1,123 @@ +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 .= '

' . format_plural($num_links, 'Warning: There is currently 1 menu link in %title. It will be deleted (system-defined items will be reset).', 'Warning: There are currently @count menu links in %title. They will be deleted (system-defined links will be reset).', array('%title' => $this->entity->label())) . '

'; + } + $caption .= '

' . t('This action cannot be undone.') . '

'; + 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); + } +} diff --git a/core/modules/menu/lib/Drupal/menu/Form/MenuDeleteMenuForm.php b/core/modules/menu/lib/Drupal/menu/Form/MenuDeleteMenuForm.php deleted file mode 100644 index 84d0e902e24..00000000000 --- a/core/modules/menu/lib/Drupal/menu/Form/MenuDeleteMenuForm.php +++ /dev/null @@ -1,107 +0,0 @@ - $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 .= '

' . format_plural($num_links, 'Warning: There is currently 1 menu link in %title. It will be deleted (system-defined items will be reset).', 'Warning: There are currently @count menu links in %title. They will be deleted (system-defined links will be reset).', array('%title' => $this->menu->label())) . '

'; - } - $caption .= '

' . t('This action cannot be undone.') . '

'; - 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); - } -} diff --git a/core/modules/menu/lib/Drupal/menu/Form/MenuLinkDeleteForm.php b/core/modules/menu/lib/Drupal/menu/Form/MenuLinkDeleteForm.php index e00dbc73892..ffb2af574ef 100644 --- a/core/modules/menu/lib/Drupal/menu/Form/MenuLinkDeleteForm.php +++ b/core/modules/menu/lib/Drupal/menu/Form/MenuLinkDeleteForm.php @@ -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; } + } diff --git a/core/modules/menu/lib/Drupal/menu/Form/MenuLinkResetForm.php b/core/modules/menu/lib/Drupal/menu/Form/MenuLinkResetForm.php index aa1165c2edc..d079b51cc5a 100644 --- a/core/modules/menu/lib/Drupal/menu/Form/MenuLinkResetForm.php +++ b/core/modules/menu/lib/Drupal/menu/Form/MenuLinkResetForm.php @@ -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; } + } diff --git a/core/modules/menu/menu.module b/core/modules/menu/menu.module index b2e36a1f087..68c31258402 100644 --- a/core/modules/menu/menu.module +++ b/core/modules/menu/menu.module @@ -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'; } /** diff --git a/core/modules/menu/menu.routing.yml b/core/modules/menu/menu.routing.yml index aafe5c3525a..62c54f2c43c 100644 --- a/core/modules/menu/menu.routing.yml +++ b/core/modules/menu/menu.routing.yml @@ -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' diff --git a/core/modules/node/lib/Drupal/node/Form/DeleteMultiple.php b/core/modules/node/lib/Drupal/node/Form/DeleteMultiple.php index c47c6838a58..3cb38bf008e 100644 --- a/core/modules/node/lib/Drupal/node/Form/DeleteMultiple.php +++ b/core/modules/node/lib/Drupal/node/Form/DeleteMultiple.php @@ -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'); } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 0a7073d1958..9904f0df489 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -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( diff --git a/core/modules/path/lib/Drupal/path/Form/DeleteForm.php b/core/modules/path/lib/Drupal/path/Form/DeleteForm.php index a7100902f01..2d4bcff6e8d 100644 --- a/core/modules/path/lib/Drupal/path/Form/DeleteForm.php +++ b/core/modules/path/lib/Drupal/path/Form/DeleteForm.php @@ -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); } /** diff --git a/core/modules/picture/lib/Drupal/picture/Form/PictureMappingActionConfirmForm.php b/core/modules/picture/lib/Drupal/picture/Form/PictureMappingActionConfirmForm.php deleted file mode 100644 index 10387007b8b..00000000000 --- a/core/modules/picture/lib/Drupal/picture/Form/PictureMappingActionConfirmForm.php +++ /dev/null @@ -1,68 +0,0 @@ - $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'; - } -} diff --git a/core/modules/picture/lib/Drupal/picture/Form/PictureMappingDeleteForm.php b/core/modules/picture/lib/Drupal/picture/Form/PictureMappingDeleteForm.php new file mode 100644 index 00000000000..ef3389fa17f --- /dev/null +++ b/core/modules/picture/lib/Drupal/picture/Form/PictureMappingDeleteForm.php @@ -0,0 +1,45 @@ + $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'; + } + +} diff --git a/core/modules/picture/lib/Drupal/picture/Plugin/Core/Entity/PictureMapping.php b/core/modules/picture/lib/Drupal/picture/Plugin/Core/Entity/PictureMapping.php index 887dddffd77..98bfe6fbddf 100644 --- a/core/modules/picture/lib/Drupal/picture/Plugin/Core/Entity/PictureMapping.php +++ b/core/modules/picture/lib/Drupal/picture/Plugin/Core/Entity/PictureMapping.php @@ -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" * } * }, diff --git a/core/modules/picture/picture.routing.yml b/core/modules/picture/picture.routing.yml index 66a3689e840..c9530291f4b 100644 --- a/core/modules/picture/picture.routing.yml +++ b/core/modules/picture/picture.routing.yml @@ -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' diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Form/LinkDelete.php b/core/modules/shortcut/lib/Drupal/shortcut/Form/LinkDelete.php index e61713be8f3..9546e7d021f 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/Form/LinkDelete.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/Form/LinkDelete.php @@ -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); } /** diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Form/SetDelete.php b/core/modules/shortcut/lib/Drupal/shortcut/Form/ShortcutDeleteForm.php similarity index 58% rename from core/modules/shortcut/lib/Drupal/shortcut/Form/SetDelete.php rename to core/modules/shortcut/lib/Drupal/shortcut/Form/ShortcutDeleteForm.php index 105b382a32d..296ae9bdc0b 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/Form/SetDelete.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/Form/ShortcutDeleteForm.php @@ -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 .= '

' . 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()))); } } diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Plugin/Core/Entity/Shortcut.php b/core/modules/shortcut/lib/Drupal/shortcut/Plugin/Core/Entity/Shortcut.php index 5f599e453ff..5b3f17a1f29 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/Plugin/Core/Entity/Shortcut.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/Plugin/Core/Entity/Shortcut.php @@ -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", diff --git a/core/modules/shortcut/shortcut.routing.yml b/core/modules/shortcut/shortcut.routing.yml index 761067fec6a..f4925c31129 100644 --- a/core/modules/shortcut/shortcut.routing.yml +++ b/core/modules/shortcut/shortcut.routing.yml @@ -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: diff --git a/core/modules/system/lib/Drupal/system/Form/DateFormatDeleteForm.php b/core/modules/system/lib/Drupal/system/Form/DateFormatDeleteForm.php index 7a796795a37..327fb3f4ade 100644 --- a/core/modules/system/lib/Drupal/system/Form/DateFormatDeleteForm.php +++ b/core/modules/system/lib/Drupal/system/Form/DateFormatDeleteForm.php @@ -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); } /** diff --git a/core/modules/system/lib/Drupal/system/Form/DateFormatLocalizeResetForm.php b/core/modules/system/lib/Drupal/system/Form/DateFormatLocalizeResetForm.php index 3392b76c56d..cbce81f0e7d 100644 --- a/core/modules/system/lib/Drupal/system/Form/DateFormatLocalizeResetForm.php +++ b/core/modules/system/lib/Drupal/system/Form/DateFormatLocalizeResetForm.php @@ -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); } /** diff --git a/core/modules/system/lib/Drupal/system/Form/ModulesInstallConfirmForm.php b/core/modules/system/lib/Drupal/system/Form/ModulesInstallConfirmForm.php index 2569161216b..23d3ada7f61 100644 --- a/core/modules/system/lib/Drupal/system/Form/ModulesInstallConfirmForm.php +++ b/core/modules/system/lib/Drupal/system/Form/ModulesInstallConfirmForm.php @@ -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); } /** diff --git a/core/modules/system/lib/Drupal/system/Form/ModulesUninstallConfirmForm.php b/core/modules/system/lib/Drupal/system/Form/ModulesUninstallConfirmForm.php index f6a29cc8003..77c841c536b 100644 --- a/core/modules/system/lib/Drupal/system/Form/ModulesUninstallConfirmForm.php +++ b/core/modules/system/lib/Drupal/system/Form/ModulesUninstallConfirmForm.php @@ -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' => '

' . t('The following modules will be completely uninstalled from your site, and all data from these modules will be lost!') . '

'); $form['modules'] = array('#theme' => 'item_list', '#items' => $uninstall); - return parent::buildForm($form, $form_state); + return parent::buildForm($form, $form_state, $request); } /** diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index 878741c177f..583dc986d56 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -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. diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/ConfirmFormArrayPathTestForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/ConfirmFormArrayPathTestForm.php index f0210ae429f..186fc244b03 100644 --- a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/ConfirmFormArrayPathTestForm.php +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/ConfirmFormArrayPathTestForm.php @@ -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().'); } diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/ConfirmFormTestForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/ConfirmFormTestForm.php index eefa436286b..f18ffa24f1a 100644 --- a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/ConfirmFormTestForm.php +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/ConfirmFormTestForm.php @@ -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' => '

The ConfirmFormTestForm::buildForm() method was used for this 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) { drupal_set_message(t('The ConfirmFormTestForm::submitForm() method was used for this form.')); diff --git a/core/modules/user/lib/Drupal/user/Form/UserRoleDelete.php b/core/modules/user/lib/Drupal/user/Form/UserRoleDelete.php index 2108b92c409..817de060b60 100644 --- a/core/modules/user/lib/Drupal/user/Form/UserRoleDelete.php +++ b/core/modules/user/lib/Drupal/user/Form/UserRoleDelete.php @@ -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'; } diff --git a/core/modules/user/lib/Drupal/user/Plugin/Core/Entity/Role.php b/core/modules/user/lib/Drupal/user/Plugin/Core/Entity/Role.php index f24f7e9f4d4..8d1bf0a696b 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/Core/Entity/Role.php +++ b/core/modules/user/lib/Drupal/user/Plugin/Core/Entity/Role.php @@ -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", diff --git a/core/modules/user/user.routing.yml b/core/modules/user/user.routing.yml index b751bbb5702..a4c59838b91 100644 --- a/core/modules/user/user.routing.yml +++ b/core/modules/user/user.routing.yml @@ -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 diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Form/BreakLockForm.php b/core/modules/views_ui/lib/Drupal/views_ui/Form/BreakLockForm.php index 936103cb174..e33b3f55cc6 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/Form/BreakLockForm.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/Form/BreakLockForm.php @@ -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.')); } diff --git a/core/modules/views_ui/lib/Drupal/views_ui/Form/DeleteForm.php b/core/modules/views_ui/lib/Drupal/views_ui/Form/DeleteForm.php deleted file mode 100644 index e36d7cef507..00000000000 --- a/core/modules/views_ui/lib/Drupal/views_ui/Form/DeleteForm.php +++ /dev/null @@ -1,75 +0,0 @@ - $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'; - } - -} diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewDeleteFormController.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewDeleteFormController.php new file mode 100644 index 00000000000..18e81d00ed4 --- /dev/null +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewDeleteFormController.php @@ -0,0 +1,48 @@ + $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'; + } + +} diff --git a/core/modules/views_ui/views_ui.module b/core/modules/views_ui/views_ui.module index 98ca5892dee..269bdcddd82 100644 --- a/core/modules/views_ui/views_ui.module +++ b/core/modules/views_ui/views_ui.module @@ -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', ), ); } diff --git a/core/modules/views_ui/views_ui.routing.yml b/core/modules/views_ui/views_ui.routing.yml index 46f2965b436..0d44630e1e7 100644 --- a/core/modules/views_ui/views_ui.routing.yml +++ b/core/modules/views_ui/views_ui.routing.yml @@ -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'