/** * Form submission handler for the 'cancel' action. * * @param array $form * An associative array containing the structure of the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. */ public function cancel(array $form, FormStateInterface $form_state) { // Remove this view from cache so edits will be lost. $view = $this->entity; $this->tempStore->delete($view->id()); $form_state->setRedirectUrl($this->entity->urlInfo('collection')); }
/** * Tests the delete() method with no lock available. * * @covers ::delete * @expectedException \Drupal\user\TempStoreException */ public function testDeleteWithNoLockAvailable() { $this->lock->expects($this->at(0))->method('acquire')->with('test')->will($this->returnValue(FALSE)); $this->lock->expects($this->at(1))->method('wait')->with('test'); $this->lock->expects($this->at(2))->method('acquire')->with('test')->will($this->returnValue(FALSE)); $this->keyValue->expects($this->once())->method('getCollectionName'); $this->tempStore->delete('test'); }
/** * Removes any temporary changes to the variant. * * @param \Drupal\page_manager\PageVariantInterface $page_variant * The current Page Variant. * * @return \Symfony\Component\HttpFoundation\JsonResponse */ public function cancelPageVariant(PageVariantInterface $page_variant) { // If a temporary configuration for this variant exists, use it. $temp_store_key = 'variant.' . $page_variant->id(); if ($variant_config = $this->tempStore->get($temp_store_key)) { $this->tempStore->delete($temp_store_key); } // Return an empty JSON response. return new JsonResponse(); }
/** * Removes any temporary changes to the variant. * * @param string $panels_display_id * The id of the current Panels display. * @param \Symfony\Component\HttpFoundation\Request $request * The current request. * * @return \Symfony\Component\HttpFoundation\JsonResponse */ public function cancel($panels_storage_type, $panels_storage_id) { $panels_display = $this->loadPanelsDisplay($panels_storage_type, $panels_storage_id); // If a temporary configuration for this variant exists, use it. $temp_store_key = $panels_display->id(); if ($variant_config = $this->tempStore->get($temp_store_key)) { $this->tempStore->delete($temp_store_key); } // Return an empty JSON response. return new JsonResponse(); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $total_count = 0; $delete_entities = []; $delete_translations = []; $storage = $this->entityTypeManager->getStorage($this->entityTypeId); /** @var \Drupal\Core\Entity\ContentEntityInterface[] $entities */ $entities = $storage->loadMultiple(array_keys($this->selection)); foreach ($this->selection as $id => $langcodes) { foreach ($langcodes as $langcode) { $entity = $entities[$id]->getTranslation($langcode); if ($entity->isDefaultTranslation()) { $delete_entities[$id] = $entity; unset($delete_translations[$id]); $total_count += count($entity->getTranslationLanguages()); } elseif (!isset($delete_entities[$id])) { $delete_translations[$id][] = $entity; } } } if ($delete_entities) { $storage->delete($delete_entities); $this->logger('content')->notice('Deleted @count @entity_type items.', ['@count' => count($delete_entities), '@entity_type' => $this->entityTypeId]); } if ($delete_translations) { $count = 0; /** @var \Drupal\Core\Entity\ContentEntityInterface[][] $delete_translations */ foreach ($delete_translations as $id => $translations) { $entity = $entities[$id]->getUntranslated(); foreach ($translations as $translation) { $entity->removeTranslation($translation->language()->getId()); } $entity->save(); $count += count($translations); } if ($count) { $total_count += $count; $this->logger('content')->notice('Deleted @count @entity_type translations.', ['@count' => $count, '@entity_type' => $this->entityTypeId]); } } if ($total_count) { drupal_set_message($this->formatPlural($total_count, 'Deleted 1 item.', 'Deleted @count items.')); } $this->tempStore->delete($this->currentUser->id()); $form_state->setRedirectUrl($this->getCancelUrl()); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->tempStore->delete($this->entity->id()); $form_state->setRedirectUrl($this->entity->urlInfo('edit-form')); drupal_set_message($this->t('The lock has been broken and you may now edit this view.')); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->tempStore->delete($this->entity->id()); $form_state->setRedirectUrl($this->entity->toUrl('fields')); drupal_set_message($this->t('The lock has been broken and you may now edit this search index.')); }
/** * {@inheritdoc} */ public function discardChanges() { $this->tempStore->delete($this->entity->id()); }
/** * Deletes the given Panels Display from TempStore. * * @param \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display * @throws \Drupal\user\TempStoreException */ protected function deletePanelsDisplayTempStore(PanelsDisplayVariant $panels_display) { $this->tempStore->delete($panels_display->id()); }