diff --git a/core/lib/Drupal/Core/Entity/EntityConfirmFormBase.php b/core/lib/Drupal/Core/Entity/EntityConfirmFormBase.php new file mode 100644 index 0000000..97ca949 --- /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 0000000..40dce79 --- /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 2aedb41..e5899c5 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 { - - /** - * Returns the question to ask the user. - * - * @return string - * The form question. The page title will be set to this value. - */ - 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(); +abstract class ConfirmFormBase implements ConfirmFormInterface { /** - * Returns additional text to display as a description. - * - * @return string - * The form description. + * {@inheritdoc} */ - 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 @@ public function buildForm(array $form, array &$form_state) { } /** - * 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 0000000..5c34f9a --- /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 a3d2b3c..0000000 --- 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 6bb3089..ebc45bd 100644 --- a/core/modules/aggregator/aggregator.module +++ b/core/modules/aggregator/aggregator.module @@ -371,27 +371,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. * * @param \Drupal\aggregator\Plugin\Core\Entity\Feed $feed diff --git a/core/modules/aggregator/aggregator.routing.yml b/core/modules/aggregator/aggregator.routing.yml index 6a94734..9a0a070 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.delete_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/Form/FeedDelete.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/FeedDelete.php deleted file mode 100644 index d613c39..0000000 --- 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 0000000..cda6539 --- /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 dbb79cd..0000000 --- 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/FeedItemsDeleteForm.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/FeedItemsDeleteForm.php new file mode 100644 index 0000000..9b713ce --- /dev/null +++ b/core/modules/aggregator/lib/Drupal/aggregator/Form/FeedItemsDeleteForm.php @@ -0,0 +1,84 @@ +manager = $manager; + } + + /** + * {@inheritdoc} + */ + public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) { + return new static( + $container->get('plugin.manager.aggregator.processor') + ); + } + + /** + * {@inheritdoc} + */ + public function getQuestion() { + return t('Are you sure you want to remove all items from the feed %feed?', array('%feed' => $this->entity->label())); + } + + /** + * {@inheritdoc} + */ + public function getCancelPath() { + return 'admin/config/services/aggregator'; + } + + /** + * {@inheritdoc} + */ + public function getConfirmText() { + return t('Remove items'); + } + + /** + * {@inheritdoc} + */ + public function submit(array $form, array &$form_state) { + foreach ($this->manager->getDefinitions() as $id => $definition) { + $this->manager->createInstance($id)->remove($this->entity); + } + // Reset feed. + $this->entity->checked->value = 0; + $this->entity->hash->value = ''; + $this->entity->etag->value = ''; + $this->entity->modified->value = 0; + $this->entity->save(); + + $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 f915caa..fe1c153 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 @@ -23,7 +23,9 @@ * "storage" = "Drupal\aggregator\FeedStorageController", * "render" = "Drupal\aggregator\FeedRenderController", * "form" = { - * "default" = "Drupal\aggregator\FeedFormController" + * "default" = "Drupal\aggregator\FeedFormController", + * "delete" = "Drupal\aggregator\Form\FeedDeleteForm", + * "delete_items" = "Drupal\aggregator\Form\FeedItemsDeleteForm" * } * }, * base_table = "aggregator_feed", diff --git a/core/modules/ban/lib/Drupal/ban/Form/BanDelete.php b/core/modules/ban/lib/Drupal/ban/Form/BanDelete.php index 24655df..ac1aa91 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\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 @@ public function getFormID() { /** * {@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 @@ protected function getCancelPath() { * @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 af247b0..c867bca 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 ba6206a..0000000 --- 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 0000000..3cc4a46 --- /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 3c8b14c..78dddd6 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 @@ -26,7 +26,8 @@ * "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/contact/contact.routing.yml b/core/modules/contact/contact.routing.yml index b46305b..c8ab42c 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 0000000..75988a7 --- /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 237d32e..0000000 --- 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 12a9fc0..afabe44 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 @@ -25,7 +25,8 @@ * "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 d115b7f..fefd9a1 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -244,6 +244,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(). */ function field_ui_entity_bundle_create($entity_type, $bundle) { 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 a35be7f..481cf7c 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\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 @@ public function __construct(EntityManager $entity_manager) { /** * {@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 @@ public static function create(ContainerInterface $container) { /** * {@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'; - } - - /** - * {@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); + public function getCancelPath() { + return $this->entityManager->getAdminPath($this->entity->entity_type, $this->entity->bundle) . '/fields'; } /** * {@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 934a56e..55477a0 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 @@ public function routes(RouteBuildEvent $event) { $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/lib/Drupal/filter/Form/DisableForm.php b/core/modules/filter/lib/Drupal/filter/Form/DisableForm.php index 49b71c8..8899eed 100644 --- a/core/modules/filter/lib/Drupal/filter/Form/DisableForm.php +++ b/core/modules/filter/lib/Drupal/filter/Form/DisableForm.php @@ -32,14 +32,14 @@ public function getFormID() { /** * Implements \Drupal\Core\Form\ConfirmFormBase::getQuestion(). */ - protected function getQuestion() { + public function getQuestion() { return t('Are you sure you want to disable the text format %format?', array('%format' => $this->format->name)); } /** * Implements \Drupal\Core\Form\ConfirmFormBase::getCancelPath(). */ - protected function getCancelPath() { + public function getCancelPath() { return 'admin/config/content/formats'; } diff --git a/core/modules/forum/lib/Drupal/forum/Form/DeleteForm.php b/core/modules/forum/lib/Drupal/forum/Form/DeleteForm.php index 46df2b9..7c4ba56 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 @@ 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 @@ public function getFormID() { /** * {@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 0aa23ba..b178d33 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 c3832c2..50bf2bb 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 @@ 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 @@ public function getFormID() { /** * {@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 9719d38..eb2f9aa 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 @@ public function buildForm(array $form, array &$form_state, ImageStyle $image_sty '#empty_option' => t('No replacement, just delete'), ); - return parent::buildForm($form, $form_state); + return $form; } /** * {@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 60f020e..d17a96e 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 @@ -20,6 +20,9 @@ * 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 0000000..60129fa --- /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 84d0e90..0000000 --- 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 e00dbc7..ffb2af5 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; - - /** - * {@inheritdoc} - */ - protected function getQuestion() { - return t('Are you sure you want to delete the custom menu link %item?', array('%item' => $this->menuLink->link_title)); - } +class MenuLinkDeleteForm extends EntityConfirmFormBase { /** * {@inheritdoc} */ - protected function getCancelPath() { - return 'admin/structure/menu/manage/' . $this->menuLink->menu_name; + public function getQuestion() { + return t('Are you sure you want to delete the custom menu link %item?', array('%item' => $this->entity->link_title)); } /** * {@inheritdoc} */ - public function getFormID() { - return 'menu_link_delete_form'; + public function getCancelPath() { + return 'admin/structure/menu/manage/' . $this->entity->menu_name; } /** * {@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 aa1165c..39b6510 100644 --- a/core/modules/menu/lib/Drupal/menu/Form/MenuLinkResetForm.php +++ b/core/modules/menu/lib/Drupal/menu/Form/MenuLinkResetForm.php @@ -25,28 +25,28 @@ class MenuLinkResetForm extends ConfirmFormBase { /** * {@inheritdoc} */ - protected function getQuestion() { + public function getQuestion() { return t('Are you sure you want to reset the link %item to its default values?', array('%item' => $this->menuLink->link_title)); } /** * {@inheritdoc} */ - protected function getCancelPath() { + public function getCancelPath() { return 'admin/structure/menu/manage/' . $this->menuLink->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'); } diff --git a/core/modules/menu/menu.module b/core/modules/menu/menu.module index 14c41b0..c8a9748 100644 --- a/core/modules/menu/menu.module +++ b/core/modules/menu/menu.module @@ -142,14 +142,17 @@ 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'; } /** diff --git a/core/modules/menu/menu.routing.yml b/core/modules/menu/menu.routing.yml index aafe5c3..e7823a2 100644 --- a/core/modules/menu/menu.routing.yml +++ b/core/modules/menu/menu.routing.yml @@ -15,13 +15,13 @@ menu_link_reset: 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 c11dbd8..5f1e208 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 @@ public function getFormID() { /** * {@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 30161a2..0fa9d95 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1930,6 +1930,10 @@ 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) { + 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 0eb9b88..13fa703 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\Controller\ControllerInterface; use Drupal\Core\Form\ConfirmFormBase; -use Drupal\Core\ControllerInterface; 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 @@ public function getFormID() { /** * 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 index 1038700..651f571 100644 --- a/core/modules/picture/lib/Drupal/picture/Form/PictureMappingActionConfirmForm.php +++ b/core/modules/picture/lib/Drupal/picture/Form/PictureMappingActionConfirmForm.php @@ -22,21 +22,21 @@ class PictureMappingActionConfirmForm extends ConfirmFormBase { /** * {@inheritdoc} */ - protected function getQuestion() { + public function getQuestion() { return t('Are you sure you want to delete the picture_mapping %title?', array('%title' => $this->pictureMapping->label())); } /** * {@inheritdoc} */ - protected function getCancelPath() { + public function getCancelPath() { return 'admin/config/media/picturemapping'; } /** * {@inheritdoc} */ - protected function getConfirmText() { + public function getConfirmText() { return t('Delete'); } diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Form/LinkDelete.php b/core/modules/shortcut/lib/Drupal/shortcut/Form/LinkDelete.php index e61713b..9546e7d 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 @@ 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 @@ public function getFormID() { /** * {@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 66% rename from core/modules/shortcut/lib/Drupal/shortcut/Form/SetDelete.php rename to core/modules/shortcut/lib/Drupal/shortcut/Form/ShortcutDeleteForm.php index 70e4e24..75bab80 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/Form/SetDelete.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/Form/ShortcutDeleteForm.php @@ -2,22 +2,22 @@ /** * @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 Symfony\Component\DependencyInjection\ContainerInterface; -use Drupal\Core\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,17 +34,9 @@ class SetDelete extends ConfirmFormBase implements ControllerInterface { protected $moduleHandler; /** - * The shortcut set being deleted. - * - * @var \Drupal\shortcut\Plugin\Core\Entity\Shortcut - */ - protected $shortcut; - - /** - * Constructs a SetDelete object. + * Constructs a ShortcutDeleteForm object. */ public function __construct(Connection $database, ModuleHandlerInterface $module_handler) { - $this->database = $database; $this->moduleHandler = $module_handler; } @@ -52,7 +44,7 @@ public function __construct(Connection $database, ModuleHandlerInterface $module /** * {@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') @@ -62,40 +54,31 @@ public static function create(ContainerInterface $container) { /** * {@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 = $this->database->query('SELECT COUNT(*) FROM {shortcut_set_users} WHERE set_name = :name', array(':name' => $this->shortcut->id()))->fetchField(); + $number = $this->database->query('SELECT COUNT(*) FROM {shortcut_set_users} WHERE set_name = :name', array(':name' => $this->entity->id()))->fetchField(); $info = ''; if ($number) { $info .= '' . format_plural($number, @@ -113,16 +96,16 @@ public function buildForm(array $form, array &$form_state, Shortcut $shortcut = '#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 95802d8..5d4ecda 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 @@ -25,7 +25,8 @@ * "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 761067f..f4925c3 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 b56f3cf..0af6b61 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\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 @@ public function getFormID() { /** * {@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 @@ protected function getQuestion() { /** * {@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 @@ protected function getCancelPath() { * @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 a3576c5..0008d0c 100644 --- a/core/modules/system/lib/Drupal/system/Form/DateFormatLocalizeResetForm.php +++ b/core/modules/system/lib/Drupal/system/Form/DateFormatLocalizeResetForm.php @@ -57,7 +57,7 @@ public function getFormID() { /** * {@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 +66,21 @@ protected function getQuestion() { /** * {@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.'); } diff --git a/core/modules/system/lib/Drupal/system/Form/ModulesInstallConfirmForm.php b/core/modules/system/lib/Drupal/system/Form/ModulesInstallConfirmForm.php index 2569161..82670de 100644 --- a/core/modules/system/lib/Drupal/system/Form/ModulesInstallConfirmForm.php +++ b/core/modules/system/lib/Drupal/system/Form/ModulesInstallConfirmForm.php @@ -19,28 +19,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?'); } diff --git a/core/modules/system/lib/Drupal/system/Form/ModulesUninstallConfirmForm.php b/core/modules/system/lib/Drupal/system/Form/ModulesUninstallConfirmForm.php index f6a29cc..9d2d9d5 100644 --- a/core/modules/system/lib/Drupal/system/Form/ModulesUninstallConfirmForm.php +++ b/core/modules/system/lib/Drupal/system/Form/ModulesUninstallConfirmForm.php @@ -19,28 +19,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?'); } 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 f0210ae..186fc24 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 @@ public function getFormID() { /** * Overrides \Drupal\form_test\ConfirmFormTestForm::getCancelPath(). */ - protected function getCancelPath() { + public function getCancelPath() { return array( 'path' => 'admin', 'query' => array( @@ -34,7 +34,7 @@ protected function getCancelPath() { /** * 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 eefa436..be45e67 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 @@ -24,35 +24,35 @@ public function getFormID() { /** * Implements \Drupal\Core\Form\ConfirmFormBase::getQuestion(). */ - protected function getQuestion() { + public function getQuestion() { return t('ConfirmFormTestForm::getQuestion().'); } /** * Implements \Drupal\Core\Form\ConfirmFormBase::getCancelPath(). */ - protected function getCancelPath() { + public function getCancelPath() { return 'admin'; } /** * Overrides \Drupal\Core\Form\ConfirmFormBase::getDescription(). */ - protected function getDescription() { + public function getDescription() { return t('ConfirmFormTestForm::getDescription().'); } /** * Overrides \Drupal\Core\Form\ConfirmFormBase::getConfirmText(). */ - protected function getConfirmText() { + public function getConfirmText() { return t('ConfirmFormTestForm::getConfirmText().'); } /** * Overrides \Drupal\Core\Form\ConfirmFormBase::getCancelText(). */ - protected function getCancelText() { + public function getCancelText() { return t('ConfirmFormTestForm::getCancelText().'); } diff --git a/core/modules/user/lib/Drupal/user/Form/UserRoleDelete.php b/core/modules/user/lib/Drupal/user/Form/UserRoleDelete.php index 2108b92..817de06 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 5a288c8..5d2445e 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 @@ -24,7 +24,8 @@ * "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 fb49de3..29df3a0 100644 --- a/core/modules/user/user.routing.yml +++ b/core/modules/user/user.routing.yml @@ -58,6 +58,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 7dc1ee3..af9c554 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 @@ -74,14 +74,14 @@ public function getFormID() { /** * Implements \Drupal\Core\Form\ConfirmFormBase::getQuestion(). */ - protected function getQuestion() { + public function getQuestion() { return t('Do you want to break the lock on view %name?', array('%name' => $this->view->id())); } /** * Implements \Drupal\Core\Form\ConfirmFormBase::getDescription(). */ - protected function getDescription() { + public function getDescription() { $locked = $this->tempStore->getMetadata($this->view->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))))); @@ -90,14 +90,14 @@ protected function getDescription() { /** * Implements \Drupal\Core\Form\ConfirmFormBase::getCancelPath(). */ - protected function getCancelPath() { + public function getCancelPath() { return 'admin/structure/views/view/' . $this->view->id(); } /** * Implements \Drupal\Core\Form\ConfirmFormBase::getConfirmText(). */ - protected function getConfirmText() { + public function getConfirmText() { return t('Break lock'); } 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 e36d7ce..0000000 --- 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 0000000..18e81d0 --- /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 21fdabe..416ee72 100644 --- a/core/modules/views_ui/views_ui.module +++ b/core/modules/views_ui/views_ui.module @@ -108,6 +108,7 @@ 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', ), ); } diff --git a/core/modules/views_ui/views_ui.routing.yml b/core/modules/views_ui/views_ui.routing.yml index f2046f6..e45e963 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'