Newer
Older
<?php
namespace Drupal\taxonomy\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
Dries Buytaert
committed
use Drupal\Core\Form\FormStateInterface;
catch
committed
use Drupal\taxonomy\TermStorageInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides confirmation form for resetting a vocabulary to alphabetical order.
*
* @internal
*/
Alex Pott
committed
class VocabularyResetForm extends EntityConfirmFormBase {
/**
catch
committed
* The term storage.
*
catch
committed
* @var \Drupal\taxonomy\TermStorageInterface
*/
catch
committed
protected $termStorage;
/**
* Constructs a new VocabularyResetForm object.
catch
committed
*
catch
committed
* @param \Drupal\taxonomy\TermStorageInterface $term_storage
catch
committed
* The term storage.
*/
catch
committed
public function __construct(TermStorageInterface $term_storage) {
catch
committed
$this->termStorage = $term_storage;
}
/**
* {@inheritdoc}
*/
Alex Pott
committed
public static function create(ContainerInterface $container) {
return new static(
catch
committed
$container->get('entity.manager')->getStorage('taxonomy_term')
);
}
/**
* {@inheritdoc}
*/
Alex Pott
committed
public function getFormId() {
return 'taxonomy_vocabulary_confirm_reset_alphabetical';
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to reset the vocabulary %title to alphabetical order?', ['%title' => $this->entity->label()]);
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
Alex Pott
committed
return $this->entity->urlInfo('overview-form');
}
/**
* {@inheritdoc}
*/
public function getDescription() {
Angie Byron
committed
return $this->t('Resetting a vocabulary will discard all custom ordering and sort items alphabetically.');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
Angie Byron
committed
return $this->t('Reset to alphabetical');
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
catch
committed
$this->termStorage->resetWeights($this->entity->id());
drupal_set_message($this->t('Reset vocabulary %name to alphabetical order.', ['%name' => $this->entity->label()]));
$this->logger('taxonomy')->notice('Reset vocabulary %name to alphabetical order.', ['%name' => $this->entity->label()]);
Alex Pott
committed
$form_state->setRedirectUrl($this->getCancelUrl());