Commit 29907b06 authored by alexpott's avatar alexpott

Issue #1976296 by jibran, andypost, pcambra, dawehner, tim.plunkett, Gaelan:...

Issue #1976296 by jibran, andypost, pcambra, dawehner, tim.plunkett, Gaelan: Convert taxonomy_vocabulary_confirm_reset_alphabetical() to FormInterface/Controller.
parent dc3ba2b1
<?php
/**
* @file
* Contains \Drupal\taxonomy\Form\VocabularyReset.
*/
namespace Drupal\taxonomy\Form;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Entity\EntityControllerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Provides confirmation form for resetting a vocabulary to alphabetical order.
*/
class VocabularyResetForm extends EntityConfirmFormBase implements EntityControllerInterface {
/**
* The database connection object.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* Constructs a new VocabularyResetForm object.
*/
public function __construct(ModuleHandlerInterface $module_handler, Connection $connection) {
parent::__construct($module_handler);
$this->connection = $connection;
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) {
return new static(
$container->get('module_handler'),
$container->get('database')
);
}
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'taxonomy_vocabulary_confirm_reset_alphabetical';
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return t('Are you sure you want to reset the vocabulary %title to alphabetical order?', array('%title' => $this->entity->label()));
}
/**
* {@inheritdoc}
*/
public function getCancelPath() {
return 'admin/structure/taxonomy/manage/' . $this->entity->id();
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return t('Resetting a vocabulary will discard all custom ordering and sort items alphabetically.');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Reset to alphabetical');
}
/**
* {@inheritdoc}
*/
public function save(array $form, array &$form_state) {
$this->connection->update('taxonomy_term_data')
->fields(array('weight' => 0))
->condition('vid', $this->entity->id())
->execute();
drupal_set_message(t('Reset vocabulary %name to alphabetical order.', array('%name' => $this->entity->label())));
watchdog('taxonomy', 'Reset vocabulary %name to alphabetical order.', array('%name' => $this->entity->label()), WATCHDOG_NOTICE);
$form_state['redirect'] = 'admin/structure/taxonomy/manage/' . $this->entity->id();
}
}
......@@ -26,6 +26,7 @@
* "list" = "Drupal\taxonomy\VocabularyListController",
* "form" = {
* "default" = "Drupal\taxonomy\VocabularyFormController",
* "reset" = "Drupal\taxonomy\Form\VocabularyResetForm",
* "delete" = "Drupal\taxonomy\Form\VocabularyDeleteForm"
* }
* },
......
......@@ -5,7 +5,6 @@
* Administrative page callbacks for the taxonomy module.
*/
use Drupal\taxonomy\Plugin\Core\Entity\Term;
use Drupal\taxonomy\Plugin\Core\Entity\Vocabulary;
/**
......@@ -36,11 +35,6 @@ function taxonomy_vocabulary_add() {
function taxonomy_overview_terms($form, &$form_state, Vocabulary $vocabulary) {
global $pager_page_array, $pager_total, $pager_total_items;
// Check for confirmation forms.
if (isset($form_state['confirm_reset_alphabetical'])) {
return taxonomy_vocabulary_confirm_reset_alphabetical($form, $form_state, $vocabulary->id());
}
$form_state['taxonomy']['vocabulary'] = $vocabulary;
$parent_fields = FALSE;
......@@ -308,13 +302,8 @@ function taxonomy_overview_terms($form, &$form_state, Vocabulary $vocabulary) {
*/
function taxonomy_overview_terms_submit($form, &$form_state) {
if ($form_state['triggering_element']['#value'] == t('Reset to alphabetical')) {
// Execute the reset action.
if ($form_state['values']['reset_alphabetical'] === TRUE) {
return taxonomy_vocabulary_confirm_reset_alphabetical_submit($form, $form_state);
}
// Rebuild the form to confirm the reset action.
$form_state['rebuild'] = TRUE;
$form_state['confirm_reset_alphabetical'] = TRUE;
// Redirect to confirmation form for the reset action.
$form_state['redirect'] = 'admin/structure/taxonomy/manage/' . $form_state['taxonomy']['vocabulary']->id() . '/reset';
return;
}
......@@ -396,40 +385,3 @@ function taxonomy_overview_terms_submit($form, &$form_state) {
}
drupal_set_message(t('The configuration options have been saved.'));
}
/**
* Form builder to confirm resetting a vocabulary to alphabetical order.
*
* @ingroup forms
* @see taxonomy_vocabulary_confirm_reset_alphabetical_submit()
*/
function taxonomy_vocabulary_confirm_reset_alphabetical($form, &$form_state, $vid) {
$vocabulary = entity_load('taxonomy_vocabulary', $vid);
$form['type'] = array('#type' => 'value', '#value' => 'vocabulary');
$form['vid'] = array('#type' => 'value', '#value' => $vid);
$form['name'] = array('#type' => 'value', '#value' => $vocabulary->name);
$form['reset_alphabetical'] = array('#type' => 'value', '#value' => TRUE);
return confirm_form($form,
t('Are you sure you want to reset the vocabulary %title to alphabetical order?',
array('%title' => $vocabulary->label())),
'admin/structure/taxonomy/manage/' . $vocabulary->id(),
t('Resetting a vocabulary will discard all custom ordering and sort items alphabetically.'),
t('Reset to alphabetical'),
t('Cancel'));
}
/**
* Submit handler to reset a vocabulary to alphabetical order after confirmation.
*
* @see taxonomy_vocabulary_confirm_reset_alphabetical()
*/
function taxonomy_vocabulary_confirm_reset_alphabetical_submit($form, &$form_state) {
db_update('taxonomy_term_data')
->fields(array('weight' => 0))
->condition('vid', $form_state['values']['vid'])
->execute();
drupal_set_message(t('Reset vocabulary %name to alphabetical order.', array('%name' => $form_state['values']['name'])));
watchdog('taxonomy', 'Reset vocabulary %name to alphabetical order.', array('%name' => $form_state['values']['name']), WATCHDOG_NOTICE);
$form_state['redirect'] = 'admin/structure/taxonomy/manage/' . $form_state['values']['vid'];
}
......@@ -25,3 +25,10 @@ taxonomy_vocabulary_delete:
_entity_form: 'taxonomy_vocabulary.delete'
requirements:
_entity_access: 'taxonomy_vocabulary.delete'
taxonomy_vocabulary_reset:
pattern: '/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/reset'
defaults:
_entity_form: 'taxonomy_vocabulary.reset'
requirements:
_permission: 'administer taxonomy'
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