diff --git a/core/lib/Drupal/Core/Entity/EntityConfirmFormBase.php b/core/lib/Drupal/Core/Entity/EntityConfirmFormBase.php index 8e0292b..ef05717 100644 --- a/core/lib/Drupal/Core/Entity/EntityConfirmFormBase.php +++ b/core/lib/Drupal/Core/Entity/EntityConfirmFormBase.php @@ -25,6 +25,13 @@ /** * {@inheritdoc} */ + public function getBaseFormID() { + return $this->entity->entityType() . '_confirm_form'; + } + + /** + * {@inheritdoc} + */ public function getDescription() { return t('This action cannot be undone.'); } diff --git a/core/lib/Drupal/Core/Entity/EntityNGConfirmFormBase.php b/core/lib/Drupal/Core/Entity/EntityNGConfirmFormBase.php index 1c345a0..fd04241 100644 --- a/core/lib/Drupal/Core/Entity/EntityNGConfirmFormBase.php +++ b/core/lib/Drupal/Core/Entity/EntityNGConfirmFormBase.php @@ -25,6 +25,13 @@ /** * {@inheritdoc} */ + public function getBaseFormID() { + return $this->entity->entityType() . '_confirm_form'; + } + + /** + * {@inheritdoc} + */ public function getDescription() { return t('This action cannot be undone.'); } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 1d90683..fbdf07d 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1919,11 +1919,6 @@ 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/taxonomy/lib/Drupal/taxonomy/Form/TermDeleteForm.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/TermDeleteForm.php new file mode 100644 index 0000000..6d3b693 --- /dev/null +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/TermDeleteForm.php @@ -0,0 +1,96 @@ +storageController = $storage_controller; + } + + /** + * {@inheritdoc} + */ + public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) { + return new static( + $container->get('plugin.manager.entity')->getStorageController('taxonomy_vocabulary') + ); + } + + /** + * {@inheritdoc} + */ + public function getFormID() { + return 'taxonomy_term_confirm_delete'; + } + + /** + * {@inheritdoc} + */ + public function getQuestion() { + return t('Are you sure you want to delete the term %title?', array('%title' => $this->entity->label())); + } + + /** + * {@inheritdoc} + */ + public function getCancelPath() { + return 'admin/structure/taxonomy'; + } + + /** + * {@inheritdoc} + */ + public function getDescription() { + return t('Deleting a term will delete all its children if there are any. This action cannot be undone.'); + } + + /** + * {@inheritdoc} + */ + public function getConfirmText() { + return t('Delete'); + } + + /** + * {@inheritdoc} + */ + public function submit(array $form, array &$form_state) { + $this->entity->delete(); + $vocabulary = $this->storageController->load(array($this->entity->bundle())); + // @todo Move to storage controller http://drupal.org/node/1988712 + taxonomy_check_vocabulary_hierarchy(reset($vocabulary), array('tid' => $this->entity->id())); + drupal_set_message(t('Deleted term %name.', array('%name' => $this->entity->label()))); + watchdog('taxonomy', 'Deleted term %name.', array('%name' => $this->entity->label()), WATCHDOG_NOTICE); + $form_state['redirect'] = 'admin/structure/taxonomy'; + Cache::invalidateTags(array('content' => TRUE)); + } + +} diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Form/VocabularyDeleteForm.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/VocabularyDeleteForm.php new file mode 100644 index 0000000..77c38a5 --- /dev/null +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Form/VocabularyDeleteForm.php @@ -0,0 +1,64 @@ + $this->entity->label())); + } + + /** + * {@inheritdoc} + */ + public function getCancelPath() { + return 'admin/structure/taxonomy'; + } + + /** + * {@inheritdoc} + */ + public function getDescription() { + return t('Deleting a vocabulary will delete all the terms in it. This action cannot be undone.'); + } + + /** + * {@inheritdoc} + */ + public function getConfirmText() { + return t('Delete'); + } + + /** + * {@inheritdoc} + */ + public function submit(array $form, array &$form_state) { + $this->entity->delete(); + drupal_set_message(t('Deleted vocabulary %name.', array('%name' => $this->entity->label()))); + watchdog('taxonomy', 'Deleted vocabulary %name.', array('%name' => $this->entity->label()), WATCHDOG_NOTICE); + $form_state['redirect'] = 'admin/structure/taxonomy'; + Cache::invalidateTags(array('content' => TRUE)); + } + +} diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Term.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Term.php index 0bf0aac..2ad4d4d 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Term.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Term.php @@ -27,7 +27,8 @@ * "render" = "Drupal\taxonomy\TermRenderController", * "access" = "Drupal\taxonomy\TermAccessController", * "form" = { - * "default" = "Drupal\taxonomy\TermFormController" + * "default" = "Drupal\taxonomy\TermFormController", + * "delete" = "Drupal\taxonomy\Form\TermDeleteForm" * }, * "translation" = "Drupal\taxonomy\TermTranslationController" * }, diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Vocabulary.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Vocabulary.php index 9d55435..ea9eda6 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Vocabulary.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/Core/Entity/Vocabulary.php @@ -25,7 +25,8 @@ * "access" = "Drupal\taxonomy\VocabularyAccessController", * "list" = "Drupal\taxonomy\VocabularyListController", * "form" = { - * "default" = "Drupal\taxonomy\VocabularyFormController" + * "default" = "Drupal\taxonomy\VocabularyFormController", + * "delete" = "Drupal\taxonomy\Form\VocabularyDeleteForm" * } * }, * config_prefix = "taxonomy.vocabulary", diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermInterface.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermInterface.php index 20169e8..f9bb432 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermInterface.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermInterface.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\taxonomy\Plugin\Core\Entity\TermInterface. + * Contains \Drupal\taxonomy\TermInterface. */ namespace Drupal\taxonomy; diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php index f6d7f42..5b0a6d9 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\taxonomy\VocabularyFormController. + * Contains \Drupal\taxonomy\VocabularyFormController. */ namespace Drupal\taxonomy; @@ -16,15 +16,11 @@ class VocabularyFormController extends EntityFormController { /** - * Overrides Drupal\Core\Entity\EntityFormController::form(). + * {@inheritdoc} */ public function form(array $form, array &$form_state) { $vocabulary = $this->entity; - // Check whether we need a deletion confirmation form. - if (isset($form_state['confirm_delete']) && isset($form_state['values']['vid'])) { - return taxonomy_vocabulary_confirm_delete($form, $form_state, $form_state['values']['vid']); - } $form['name'] = array( '#type' => 'textfield', '#title' => t('Name'), @@ -88,7 +84,6 @@ protected function actions(array $form, array &$form_state) { // If we are displaying the delete confirmation skip the regular actions. if (empty($form_state['confirm_delete'])) { $actions = parent::actions($form, $form_state); - array_unshift($actions['delete']['#submit'], array($this, 'submit')); // Add the language configuration submit handler. This is needed because // the submit button has custom submit handlers. if (module_exists('language')) { @@ -125,24 +120,7 @@ public function languageConfigurationSubmit(array &$form, array &$form_state) { } /** - * Overrides Drupal\Core\Entity\EntityFormController::submit(). - */ - public function submit(array $form, array &$form_state) { - // @todo We should not be calling taxonomy_vocabulary_confirm_delete() from - // within the form builder. - if ($form_state['triggering_element']['#value'] == t('Delete')) { - // Rebuild the form to confirm vocabulary deletion. - $form_state['rebuild'] = TRUE; - $form_state['confirm_delete'] = TRUE; - return NULL; - } - else { - return parent::submit($form, $form_state); - } - } - - /** - * Overrides Drupal\Core\Entity\EntityFormController::save(). + * {@inheritdoc} */ public function save(array $form, array &$form_state) { $vocabulary = $this->entity; @@ -167,4 +145,13 @@ public function save(array $form, array &$form_state) { $form_state['values']['vid'] = $vocabulary->id(); $form_state['vid'] = $vocabulary->id(); } + + /** + * {@inheritdoc} + */ + public function delete(array $form, array &$form_state) { + $vocabulary = $this->getEntity($form_state); + $form_state['redirect'] = array('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/delete'); + } + } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyInterface.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyInterface.php index 51ec34f..80c7781 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyInterface.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyInterface.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\taxonomy\Plugin\Core\Entity\VocabularyInterface. + * Contains \Drupal\taxonomy\VocabularyInterface. */ namespace Drupal\taxonomy; diff --git a/core/modules/taxonomy/taxonomy.admin.inc b/core/modules/taxonomy/taxonomy.admin.inc index 24b71f9..5712a73 100644 --- a/core/modules/taxonomy/taxonomy.admin.inc +++ b/core/modules/taxonomy/taxonomy.admin.inc @@ -402,87 +402,6 @@ function taxonomy_term_add($vocabulary) { } /** - * Form builder for the term delete form. - * - * @ingroup forms - * @see taxonomy_term_confirm_delete_submit() - */ -function taxonomy_term_confirm_delete($form, &$form_state, Term $term) { - // Always provide entity id in the same form key as in the entity edit form. - $form['tid'] = array('#type' => 'value', '#value' => $term->id()); - - $form_state['taxonomy']['vocabulary'] = taxonomy_vocabulary_load($term->bundle()); - $form['type'] = array('#type' => 'value', '#value' => 'term'); - $form['name'] = array('#type' => 'value', '#value' => $term->label()); - $form['vid'] = array('#type' => 'value', '#value' => $term->bundle()); - $form['delete'] = array('#type' => 'value', '#value' => TRUE); - return confirm_form($form, - t('Are you sure you want to delete the term %title?', - array('%title' => $term->label())), - 'admin/structure/taxonomy', - t('Deleting a term will delete all its children if there are any. This action cannot be undone.'), - t('Delete'), - t('Cancel')); -} - -/** - * Submit handler to delete a term after confirmation. - * - * @see taxonomy_term_confirm_delete() - */ -function taxonomy_term_confirm_delete_submit($form, &$form_state) { - entity_delete_multiple('taxonomy_term', array($form_state['values']['tid'])); - taxonomy_check_vocabulary_hierarchy($form_state['taxonomy']['vocabulary'], $form_state['values']); - drupal_set_message(t('Deleted term %name.', array('%name' => $form_state['values']['name']))); - watchdog('taxonomy', 'Deleted term %name.', array('%name' => $form_state['values']['name']), WATCHDOG_NOTICE); - if (!isset($_GET['destination'])) { - $form_state['redirect'] = 'admin/structure/taxonomy'; - } - cache_invalidate_tags(array('content' => TRUE)); - return; -} - -/** - * Form builder for the vocabulary delete confirmation form. - * - * @ingroup forms - * @see taxonomy_vocabulary_confirm_delete_submit() - */ -function taxonomy_vocabulary_confirm_delete($form, &$form_state, $vid) { - $vocabulary = taxonomy_vocabulary_load($vid); - - // Always provide entity id in the same form key as in the entity edit form. - $form['vid'] = array('#type' => 'value', '#value' => $vid); - - $form_state['taxonomy']['vocabulary'] = $vocabulary; - $form['#id'] = 'taxonomy_vocabulary_confirm_delete'; - $form['type'] = array('#type' => 'value', '#value' => 'vocabulary'); - $form['name'] = array('#type' => 'value', '#value' => $vocabulary->name); - $form['#submit'] = array('taxonomy_vocabulary_confirm_delete_submit'); - return confirm_form($form, - t('Are you sure you want to delete the vocabulary %title?', - array('%title' => $vocabulary->label())), - 'admin/structure/taxonomy', - t('Deleting a vocabulary will delete all the terms in it. This action cannot be undone.'), - t('Delete'), - t('Cancel')); -} - -/** - * Submit handler to delete a vocabulary after confirmation. - * - * @see taxonomy_vocabulary_confirm_delete() - */ -function taxonomy_vocabulary_confirm_delete_submit($form, &$form_state) { - $form_state['taxonomy']['vocabulary']->delete(); - drupal_set_message(t('Deleted vocabulary %name.', array('%name' => $form_state['values']['name']))); - watchdog('taxonomy', 'Deleted vocabulary %name.', array('%name' => $form_state['values']['name']), WATCHDOG_NOTICE); - $form_state['redirect'] = 'admin/structure/taxonomy'; - cache_invalidate_tags(array('content' => TRUE)); - return; -} - -/** * Form builder to confirm resetting a vocabulary to alphabetical order. * * @ingroup forms diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index 980ad00..9f13bb4 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -5,6 +5,7 @@ * Enables the organization of content into categories. */ +use Drupal\taxonomy\VocabularyInterface; use Drupal\node\Plugin\Core\Entity\Node; use Drupal\taxonomy\Plugin\Core\Entity\Term; use Drupal\taxonomy\Plugin\Core\Entity\Vocabulary; @@ -277,14 +278,10 @@ function taxonomy_menu() { ); $items['taxonomy/term/%taxonomy_term/delete'] = array( 'title' => 'Delete', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('taxonomy_term_confirm_delete', 2), - 'access callback' => 'entity_page_access', - 'access arguments' => array(2, 'delete'), 'type' => MENU_LOCAL_TASK, 'context' => MENU_CONTEXT_INLINE, 'weight' => 20, - 'file' => 'taxonomy.admin.inc', + 'route_name' => 'taxonomy_term_delete', ); $items['taxonomy/term/%taxonomy_term/feed'] = array( 'title' => 'Taxonomy term', @@ -328,6 +325,13 @@ function taxonomy_menu() { 'type' => MENU_LOCAL_TASK, 'file' => 'taxonomy.admin.inc', ); + $items['admin/structure/taxonomy/%taxonomy_vocabulary/delete'] = array( + 'title' => 'Delete', + 'type' => MENU_LOCAL_TASK, + 'context' => MENU_CONTEXT_INLINE, + 'weight' => 20, + 'route_name' => 'taxonomy_vocabulary_delete', + ); $items['admin/structure/taxonomy/manage/%taxonomy_vocabulary/add'] = array( 'title' => 'Add term', @@ -379,7 +383,7 @@ function taxonomy_admin_paths() { * term has multiple parents then the vocabulary will be given a hierarchy of * TAXONOMY_HIERARCHY_MULTIPLE. * - * @param Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary + * @param \Drupal\taxonomy\VocabularyInterface $vocabulary * A taxonomy vocabulary entity. * @param $changed_term * An array of the term structure that was updated. @@ -387,7 +391,7 @@ function taxonomy_admin_paths() { * @return * An integer that represents the level of the vocabulary's hierarchy. */ -function taxonomy_check_vocabulary_hierarchy(Vocabulary $vocabulary, $changed_term) { +function taxonomy_check_vocabulary_hierarchy(VocabularyInterface $vocabulary, $changed_term) { $tree = taxonomy_get_tree($vocabulary->id()); $hierarchy = TAXONOMY_HIERARCHY_DISABLED; foreach ($tree as $term) { diff --git a/core/modules/taxonomy/taxonomy.routing.yml b/core/modules/taxonomy/taxonomy.routing.yml index 8715476..728a68e 100644 --- a/core/modules/taxonomy/taxonomy.routing.yml +++ b/core/modules/taxonomy/taxonomy.routing.yml @@ -1,6 +1,21 @@ +taxonomy_term_delete: + pattern: '/taxonomy/term/{taxonomy_term}/delete' + defaults: + _entity_form: taxonomy_term.delete + requirements: + _entity_access: taxonomy_term.delete + +taxonomy_vocabulary_delete: + pattern: '/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/delete' + defaults: + _entity_form: taxonomy_vocabulary.delete + requirements: + _entity_access: taxonomy_vocabulary.delete + taxonomy_vocabulary_list: pattern: '/admin/structure/taxonomy' defaults: _entity_list: 'taxonomy_vocabulary' requirements: _permission: 'administer taxonomy' +