Commit 3172ea41 authored by alexpott's avatar alexpott

Issue #1946456 by andypost, disasm: Convert taxonomy_term_confirm_delete() and...

Issue #1946456 by andypost, disasm: Convert taxonomy_term_confirm_delete() and taxonomy_vocabulary_confirm_delete() to the new form interface.
parent e9ca0d86
<?php
/**
* @file
* Contains \Drupal\taxonomy\Form\TermDeleteForm.
*/
namespace Drupal\taxonomy\Form;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityControllerInterface;
use Drupal\taxonomy\VocabularyStorageControllerInterface;
use Drupal\Core\Entity\EntityNGConfirmFormBase;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Cache\Cache;
/**
* Provides a deletion confirmation form for taxonomy term.
*/
class TermDeleteForm extends EntityNGConfirmFormBase implements EntityControllerInterface {
/**
* The taxonomy vocabulary storage controller.
*
* @var \Drupal\taxonomy\VocabularyStorageControllerInterface
*/
protected $vocabularyStorageController;
/**
* Constructs a new TermDelete object.
*
* @param \Drupal\Core\Entity\EntityStorageControllerInterface $storage_controller
* The Entity manager.
*/
public function __construct(ModuleHandlerInterface $module_handler, VocabularyStorageControllerInterface $storage_controller) {
parent::__construct($module_handler);
$this->vocabularyStorageController = $storage_controller;
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) {
return new static(
$container->get('module_handler'),
$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->vocabularyStorageController->load($this->entity->bundle());
// @todo Move to storage controller http://drupal.org/node/1988712
taxonomy_check_vocabulary_hierarchy($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));
}
}
<?php
/**
* @file
* Contains \Drupal\taxonomy\Form\VocabularyDeleteForm.
*/
namespace Drupal\taxonomy\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Cache\Cache;
/**
* Provides a deletion confirmation form for taxonomy vocabulary.
*/
class VocabularyDeleteForm extends EntityConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'taxonomy_vocabulary_confirm_delete';
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return t('Are you sure you want to delete the vocabulary %title?', array('%title' => $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));
}
}
......@@ -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"
* },
......
......@@ -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",
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\taxonomy\Plugin\Core\Entity\TermInterface.
* Contains \Drupal\taxonomy\TermInterface.
*/
namespace Drupal\taxonomy;
......
......@@ -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');
}
}
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\taxonomy\Plugin\Core\Entity\VocabularyInterface.
* Contains \Drupal\taxonomy\VocabularyInterface.
*/
namespace Drupal\taxonomy;
......
......@@ -397,87 +397,6 @@ function taxonomy_overview_terms_submit($form, &$form_state) {
drupal_set_message(t('The configuration options have been saved.'));
}
/**
* 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.
*
......
......@@ -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;
......@@ -275,14 +276,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',
......@@ -326,6 +323,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',
......@@ -360,7 +364,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.
......@@ -368,7 +372,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) {
......
......@@ -11,3 +11,17 @@ taxonomy_term_add:
_content: '\Drupal\taxonomy\Controller\TaxonomyController::addForm'
requirements:
_access_taxonomy_term_create: 'taxonomy_term'
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'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment