class VocabularyResetForm
Same name and namespace in other branches
- 11.x core/modules/taxonomy/src/Form/VocabularyResetForm.php \Drupal\taxonomy\Form\VocabularyResetForm
Provides confirmation form for resetting a vocabulary to alphabetical order.
@internal
Hierarchy
- class \Drupal\Core\Form\FormBase extends \Drupal\Core\Form\FormInterface, \Drupal\Core\DependencyInjection\ContainerInjectionInterface uses \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Logger\LoggerChannelTrait, \Drupal\Core\Messenger\MessengerTrait, \Drupal\Core\Routing\RedirectDestinationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait
- class \Drupal\Core\Entity\EntityForm extends \Drupal\Core\Entity\EntityFormInterface implements \Drupal\Core\Form\FormBase
- class \Drupal\Core\Entity\EntityConfirmFormBase extends \Drupal\Core\Form\ConfirmFormInterface implements \Drupal\Core\Entity\EntityForm
- class \Drupal\taxonomy\Form\VocabularyResetForm implements \Drupal\Core\Entity\EntityConfirmFormBase
- class \Drupal\Core\Entity\EntityConfirmFormBase extends \Drupal\Core\Form\ConfirmFormInterface implements \Drupal\Core\Entity\EntityForm
- class \Drupal\Core\Entity\EntityForm extends \Drupal\Core\Entity\EntityFormInterface implements \Drupal\Core\Form\FormBase
Expanded class hierarchy of VocabularyResetForm
File
-
core/
modules/ taxonomy/ src/ Form/ VocabularyResetForm.php, line 15
Namespace
Drupal\taxonomy\FormView source
class VocabularyResetForm extends EntityConfirmFormBase {
/**
* The term storage.
*
* @var \Drupal\taxonomy\TermStorageInterface
*/
protected $termStorage;
/**
* Constructs a new VocabularyResetForm object.
*
* @param \Drupal\taxonomy\TermStorageInterface $term_storage
* The term storage.
*/
public function __construct(TermStorageInterface $term_storage) {
$this->termStorage = $term_storage;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container->get('entity_type.manager')
->getStorage('taxonomy_term'));
}
/**
* {@inheritdoc}
*/
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() {
return $this->entity
->toUrl('overview-form');
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this->t('Resetting a vocabulary will discard all custom ordering and sort items alphabetically.');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->t('Reset to alphabetical');
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$this->termStorage
->resetWeights($this->entity
->id());
$this->messenger()
->addStatus($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(),
]);
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.