How to use reset method of storage class

Best Atoum code snippet using storage.reset

Vocabulary.php

Source:Vocabulary.php Github

copy

Full Screen

...21 * "list_builder" = "Drupal\taxonomy\VocabularyListBuilder",22 * "access" = "Drupal\taxonomy\VocabularyAccessControlHandler",23 * "form" = {24 * "default" = "Drupal\taxonomy\VocabularyForm",25 * "reset" = "Drupal\taxonomy\Form\VocabularyResetForm",26 * "delete" = "Drupal\taxonomy\Form\VocabularyDeleteForm",27 * "overview" = "Drupal\taxonomy\Form\OverviewTerms"28 * },29 * "route_provider" = {30 * "html" = "Drupal\taxonomy\Entity\Routing\VocabularyRouteProvider",31 * }32 * },33 * admin_permission = "administer taxonomy",34 * config_prefix = "vocabulary",35 * bundle_of = "taxonomy_term",36 * entity_keys = {37 * "id" = "vid",38 * "label" = "name",39 * "weight" = "weight"40 * },41 * links = {42 * "add-form" = "/admin/structure/taxonomy/add",43 * "delete-form" = "/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/delete",44 * "reset-form" = "/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/reset",45 * "overview-form" = "/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/overview",46 * "edit-form" = "/admin/structure/taxonomy/manage/{taxonomy_vocabulary}",47 * "collection" = "/admin/structure/taxonomy",48 * },49 * config_export = {50 * "name",51 * "vid",52 * "description",53 * "weight",54 * }55 * )56 */57class Vocabulary extends ConfigEntityBundleBase implements VocabularyInterface {58 /**59 * The taxonomy vocabulary ID.60 *61 * @var string62 */63 protected $vid;64 /**65 * Name of the vocabulary.66 *67 * @var string68 */69 protected $name;70 /**71 * Description of the vocabulary.72 *73 * @var string74 */75 protected $description;76 /**77 * The weight of this vocabulary in relation to other vocabularies.78 *79 * @var int80 */81 protected $weight = 0;82 /**83 * {@inheritdoc}84 */85 public function getHierarchy() {86 @trigger_error('\Drupal\taxonomy\VocabularyInterface::getHierarchy() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.x. Use \Drupal\taxonomy\TermStorage::getVocabularyHierarchyType() instead.', E_USER_DEPRECATED);87 return $this->entityTypeManager()->getStorage('taxonomy_term')->getVocabularyHierarchyType($this->id());88 }89 /**90 * {@inheritdoc}91 */92 public function setHierarchy($hierarchy) {93 @trigger_error('\Drupal\taxonomy\VocabularyInterface::setHierarchy() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.x. Reset the cache of the taxonomy_term storage controller instead.', E_USER_DEPRECATED);94 $this->entityTypeManager()->getStorage('taxonomy_term')->resetCache();95 return $this;96 }97 /**98 * {@inheritdoc}99 */100 public function id() {101 return $this->vid;102 }103 /**104 * {@inheritdoc}105 */106 public function getDescription() {107 return $this->description;108 }109 /**110 * {@inheritdoc}111 */112 public static function preDelete(EntityStorageInterface $storage, array $entities) {113 parent::preDelete($storage, $entities);114 // Only load terms without a parent, child terms will get deleted too.115 $term_storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');116 $terms = $term_storage->loadMultiple($storage->getToplevelTids(array_keys($entities)));117 $term_storage->delete($terms);118 }119 /**120 * {@inheritdoc}121 */122 public static function postDelete(EntityStorageInterface $storage, array $entities) {123 parent::postDelete($storage, $entities);124 // Reset caches.125 $storage->resetCache(array_keys($entities));126 if (reset($entities)->isSyncing()) {127 return;128 }129 $vocabularies = [];130 foreach ($entities as $vocabulary) {131 $vocabularies[$vocabulary->id()] = $vocabulary->id();132 }133 // Load all Taxonomy module fields and delete those which use only this134 // vocabulary.135 $field_storages = \Drupal::entityTypeManager()->getStorage('field_storage_config')->loadByProperties(['module' => 'taxonomy']);136 foreach ($field_storages as $field_storage) {137 $modified_storage = FALSE;138 // Term reference fields may reference terms from more than one139 // vocabulary.140 foreach ($field_storage->getSetting('allowed_values') as $key => $allowed_value) {...

Full Screen

Full Screen

VocabularyResetForm.php

Source:VocabularyResetForm.php Github

copy

Full Screen

...8use Drupal\Core\Form\FormStateInterface;9use Drupal\taxonomy\TermStorageInterface;10use Symfony\Component\DependencyInjection\ContainerInterface;11/**12 * Provides confirmation form for resetting a vocabulary to alphabetical order.13 */14class VocabularyResetForm extends EntityConfirmFormBase {15 /**16 * The term storage.17 *18 * @var \Drupal\taxonomy\TermStorageInterface19 */20 protected $termStorage;21 /**22 * Constructs a new VocabularyResetForm object.23 *24 * @param \Drupal\taxonomy\TermStorageInterface $term_storage25 * The term storage.26 */27 public function __construct(TermStorageInterface $term_storage) {28 $this->termStorage = $term_storage;29 }30 /**31 * {@inheritdoc}32 */33 public static function create(ContainerInterface $container) {34 return new static(35 $container->get('entity.manager')->getStorage('taxonomy_term')36 );37 }38 /**39 * {@inheritdoc}40 */41 public function getFormId() {42 return 'taxonomy_vocabulary_confirm_reset_alphabetical';43 }44 /**45 * {@inheritdoc}46 */47 public function getQuestion() {48 return $this->t('Are you sure you want to reset the vocabulary %title to alphabetical order?', array('%title' => $this->entity->label()));49 }50 /**51 * {@inheritdoc}52 */53 public function getCancelUrl() {54 return $this->entity->urlInfo('overview-form');55 }56 /**57 * {@inheritdoc}58 */59 public function getDescription() {60 return $this->t('Resetting a vocabulary will discard all custom ordering and sort items alphabetically.');61 }62 /**63 * {@inheritdoc}64 */65 public function getConfirmText() {66 return $this->t('Reset to alphabetical');67 }68 /**69 * {@inheritdoc}70 */71 public function submitForm(array &$form, FormStateInterface $form_state) {72 parent::submitForm($form, $form_state);73 $this->termStorage->resetWeights($this->entity->id());74 drupal_set_message($this->t('Reset vocabulary %name to alphabetical order.', array('%name' => $this->entity->label())));75 $this->logger('taxonomy')->notice('Reset vocabulary %name to alphabetical order.', array('%name' => $this->entity->label()));76 $form_state->setRedirectUrl($this->getCancelUrl());77 }78}...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Atoum automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger reset code on LambdaTest Cloud Grid

Execute automation tests with reset on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful