示例#1
0
 /**
  * {@inheritdoc}
  */
 public function executeMultiple(array $entities)
 {
     $info = [];
     /** @var \Drupal\tmgmt_local\LocalTaskInterface $task */
     foreach ($entities as $task) {
         $info[$task->id()] = $task;
     }
     $this->tempStore->set($this->currentUser->id(), $info);
 }
 /**
  * {@inheritdoc}
  */
 public function executeMultiple(array $entities)
 {
     $info = [];
     /** @var \Drupal\support_ticket\SupportTicketInterface $support_ticket */
     foreach ($entities as $support_ticket) {
         $langcode = $support_ticket->language()->getId();
         $info[$support_ticket->id()][$langcode] = $langcode;
     }
     $this->tempStore->set($this->currentUser->id(), $info);
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function executeMultiple(array $entities)
 {
     $info = [];
     /** @var \Drupal\node\NodeInterface $node */
     foreach ($entities as $node) {
         $langcode = $node->language()->getId();
         $info[$node->id()][$langcode] = $langcode;
     }
     $this->tempStore->set($this->currentUser->id(), $info);
 }
示例#4
0
 /**
  * {@inheritdoc}
  */
 public function executeMultiple(array $entities)
 {
     $info = [];
     /** @var \Drupal\magic_cards\CardBaseInterface $card */
     foreach ($entities as $card) {
         $langcode = $card->language()->getId();
         $info[$card->id()][$langcode] = $langcode;
     }
     $this->tempStore->set($this->currentUser->id(), $info);
 }
示例#5
0
 /**
  * {@inheritdoc}
  */
 public function executeMultiple(array $entities)
 {
     /** @var \Drupal\Core\Entity\ContentEntityInterface[] $entities */
     $selection = [];
     foreach ($entities as $entity) {
         $langcode = $entity->language()->getId();
         $selection[$entity->id()][$langcode] = $langcode;
     }
     $this->tempStore->set($this->currentUser->id(), $selection);
 }
示例#6
0
 /**
  * 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'));
 }
 /**
  * Loads or creates a Block Plugin instance suitable for rendering or testing.
  *
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  *
  * @return \Drupal\Core\Block\BlockBase
  *   The Block Plugin instance.
  */
 protected function getBlockInstance($form_state)
 {
     /** @var \Drupal\page_manager\PageVariantInterface $page_variant */
     $page_variant = PageVariant::load($form_state->getValue('variant_id'));
     // If a UUID is provided, the Block should already exist.
     if ($uuid = $form_state->getValue('uuid')) {
         /** @var \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $variant_plugin */
         $variant_plugin = $page_variant->getVariantPlugin();
         // 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)) {
             $variant_plugin->setConfiguration($variant_config);
         }
         // Load the existing Block instance.
         $block_instance = $variant_plugin->getBlock($uuid);
     } else {
         // Create an instance of this Block plugin.
         /** @var \Drupal\Core\Block\BlockBase $block_instance */
         $block_instance = $this->blockManager->createInstance($form_state->getValue('plugin_id'));
     }
     // Add context to the block.
     if ($block_instance instanceof ContextAwarePluginInterface) {
         $this->contextHandler->applyContextMapping($block_instance, $page_variant->getContexts());
     }
     return $block_instance;
 }
 /**
  * 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();
 }
 /**
  * Tests the deleteIfOwner() method.
  *
  * @covers ::deleteIfOwner
  */
 public function testDeleteIfOwner()
 {
     $this->lock->expects($this->once())->method('acquire')->with('test_2')->will($this->returnValue(TRUE));
     $this->keyValue->expects($this->at(0))->method('get')->with('test_1')->will($this->returnValue(FALSE));
     $this->keyValue->expects($this->at(1))->method('get')->with('test_2')->will($this->returnValue($this->ownObject));
     $this->keyValue->expects($this->at(2))->method('delete')->with('test_2');
     $this->keyValue->expects($this->at(3))->method('get')->with('test_3')->will($this->returnValue($this->otherObject));
     $this->assertTrue($this->tempStore->deleteIfOwner('test_1'));
     $this->assertTrue($this->tempStore->deleteIfOwner('test_2'));
     $this->assertFalse($this->tempStore->deleteIfOwner('test_3'));
 }
 /**
  * {@inheritdoc}
  */
 public function build(array $regions, array $contexts, LayoutInterface $layout = NULL)
 {
     // Load our PageVariant.
     /** @var \Drupal\page_manager\PageVariantInterface $page_variant */
     $page_variant = \Drupal::request()->attributes->get('page_manager_page_variant');
     // Check to see if the current user has permissions to use the IPE.
     $has_permission = $this->account->hasPermission('access panels in-place editing');
     // Attach the Panels In-place editor library based on permissions.
     if ($page_variant && $has_permission) {
         // This flag tracks whether or not there are unsaved changes.
         $unsaved = FALSE;
         // 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)) {
             // Reload the PageVariant. This is required to set variant plugin
             // configuration correctly.
             $page_variant = PageVariant::load($page_variant->id());
             /** @var \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $variant_plugin */
             $variant_plugin = $page_variant->getVariantPlugin();
             $variant_plugin->setConfiguration($variant_config);
             // Override our initial values with what's in TempStore.
             $layout = $variant_plugin->getLayout();
             $regions = $variant_plugin->getRegionAssignments();
             // Indicate that the user is viewing un-saved changes.
             $unsaved = TRUE;
         }
         $build = parent::build($regions, $contexts, $layout);
         foreach ($regions as $region => $blocks) {
             // Wrap each region with a unique class and data attribute.
             $region_name = Html::getClass("block-region-{$region}");
             $build[$region]['#prefix'] = '<div class="' . $region_name . '" data-region-name="' . $region . '">';
             $build[$region]['#suffix'] = '</div>';
             if ($blocks) {
                 foreach ($blocks as $block_id => $block) {
                     $build[$region][$block_id]['#attributes']['data-block-id'] = $block_id;
                 }
             }
         }
         // Attach the required settings and IPE.
         $build['#attached']['library'][] = 'panels_ipe/panels_ipe';
         $build['#attached']['drupalSettings']['panels_ipe'] = $this->getDrupalSettings($regions, $layout, $page_variant);
         // Add our custom elements to the build.
         $build['#prefix'] = '<div id="panels-ipe-content">';
         // Indicate if the current user is viewing temp store.
         $tray_classes = $unsaved ? 'unsaved' : '';
         $build['#suffix'] = '</div><div id="panels-ipe-tray" class="' . $tray_classes . '"></div>';
     } else {
         $build = parent::build($regions, $contexts, $layout);
     }
     return $build;
 }
示例#12
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Return early if there are any errors.
     if ($form_state->hasAnyErrors()) {
         return $form;
     }
     $panels_display = $this->panelsDisplay;
     // Submit the layout form.
     $layout_form_state = (new FormState())->setValues($form_state->getValue('settings', []));
     $this->layout->submitConfigurationForm($form, $layout_form_state);
     $layout_config = $this->layout->getConfiguration();
     // Shift our blocks to the first available region. The IPE can control
     // re-assigning blocks in a smarter way.
     $region_definitions = $this->layout->getRegionDefinitions();
     $first_region = reset(array_keys($region_definitions));
     // For each block, set the region to match the new layout.
     foreach ($panels_display->getRegionAssignments() as $region => $region_assignment) {
         /** @var \Drupal\Core\Block\BlockPluginInterface $block */
         foreach ($region_assignment as $block_id => $block) {
             $block_config = $block->getConfiguration();
             // If the new layout does not have a region with the same name, use the
             // first available region.
             if (!isset($region_definitions[$block_config['region']])) {
                 $block_config['region'] = $first_region;
                 $panels_display->updateBlock($block_id, $block_config);
             }
         }
     }
     // Have our panels display use the new layout.
     $this->panelsDisplay->setLayout($this->layout, $layout_config);
     // Update tempstore.
     $this->tempStore->set($panels_display->id(), $panels_display->getConfiguration());
     $region_data = [];
     $region_content = [];
     // Compile region content and metadata.
     $regions = $panels_display->getRegionAssignments();
     foreach ($regions as $id => $label) {
         // Wrap the region with a class/data attribute that our app can use.
         $region_name = Html::getClass("block-region-{$id}");
         $region_content[$id] = ['#prefix' => '<div class="' . $region_name . '" data-region-name="' . $id . '">', '#suffix' => '</div>'];
         // Format region metadata.
         $region_data[] = ['name' => $id, 'label' => $label];
     }
     $build = $panels_display->getLayout()->build($region_content);
     $form['build'] = $build;
     $data = ['id' => $this->layout->getPluginId(), 'label' => $layout_config['label'], 'current' => TRUE, 'html' => $this->renderer->render($build), 'regions' => $region_data];
     // Add Block metadata and HTML as a drupalSetting.
     $form['#attached']['drupalSettings']['panels_ipe']['updated_layout'] = $data;
     return $form;
 }
示例#13
0
 /**
  * {@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());
 }
 /**
  * Loads or creates a Block Plugin instance suitable for rendering or testing.
  *
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  *
  * @return \Drupal\Core\Block\BlockPluginInterface
  *   The Block Plugin instance.
  */
 protected function getBlockInstance(FormStateInterface $form_state)
 {
     // If a UUID is provided, the Block should already exist.
     if ($uuid = $form_state->getValue('uuid')) {
         // If a temporary configuration for this variant exists, use it.
         $temp_store_key = $this->panelsDisplay->id();
         if ($variant_config = $this->tempStore->get($temp_store_key)) {
             $this->panelsDisplay->setConfiguration($variant_config);
         }
         // Load the existing Block instance.
         $block_instance = $this->panelsDisplay->getBlock($uuid);
     } else {
         // Create an instance of this Block plugin.
         /** @var \Drupal\Core\Block\BlockBase $block_instance */
         $block_instance = $this->blockManager->createInstance($form_state->getValue('plugin_id'));
     }
     return $block_instance;
 }
 /**
  * {@inheritdoc}
  */
 public function build(PanelsDisplayVariant $panels_display)
 {
     // Check to see if the current user has permissions to use the IPE.
     $has_permission = $this->account->hasPermission('access panels in-place editing');
     // Attach the Panels In-place editor library based on permissions.
     if ($has_permission) {
         // This flag tracks whether or not there are unsaved changes.
         $unsaved = FALSE;
         // 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)) {
             unset($variant_config['id']);
             $panels_display->setConfiguration($variant_config);
             // Indicate that the user is viewing un-saved changes.
             $unsaved = TRUE;
         }
         $build = parent::build($panels_display);
         $regions = $panels_display->getRegionAssignments();
         $layout = $panels_display->getLayout();
         foreach ($regions as $region => $blocks) {
             // Wrap each region with a unique class and data attribute.
             $region_name = Html::getClass("block-region-{$region}");
             $build[$region]['#prefix'] = '<div class="' . $region_name . '" data-region-name="' . $region . '">';
             $build[$region]['#suffix'] = '</div>';
             if ($blocks) {
                 foreach ($blocks as $block_id => $block) {
                     $build[$region][$block_id]['#attributes']['data-block-id'] = $block_id;
                 }
             }
         }
         // Attach the required settings and IPE.
         $build['#attached']['library'][] = 'panels_ipe/panels_ipe';
         $build['#attached']['drupalSettings']['panels_ipe'] = $this->getDrupalSettings($regions, $layout, $panels_display, $unsaved);
         // Add our custom elements to the build.
         $build['#prefix'] = '<div id="panels-ipe-content">';
         $build['#suffix'] = '</div><div id="panels-ipe-tray"></div>';
     } else {
         $build = parent::build($panels_display);
     }
     return $build;
 }
示例#16
0
 /**
  * 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());
 }
示例#17
0
 /**
  * {@inheritdoc}
  */
 public function executeMultiple(array $entities)
 {
     $this->tempStore->set($this->currentUser->id(), $entities);
 }
示例#18
0
 /**
  * {@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.'));
 }
示例#19
0
 /**
  * {@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 save()
 {
     return $this->tempStore->setIfOwner($this->entity->id(), $this->entity);
 }