/** * {@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\node\NodeInterface $node */ foreach ($entities as $node) { $langcode = $node->language()->getId(); $info[$node->id()][$langcode] = $langcode; } $this->tempStore->set($this->currentUser->id(), $info); }
/** * {@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); }
/** * {@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); }
/** * {@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); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $block_instance = $this->getBlockInstance($form_state); // Submit the block configuration form. $block_form_state = (new FormState())->setValues($form_state->getValue('settings')); $block_instance->submitConfigurationForm($form, $block_form_state); // Update the original form values. $form_state->setValue('settings', $block_form_state->getValues()); // 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); } // Set the block region appropriately. $block_config = $block_instance->getConfiguration(); $block_config['region'] = $form_state->getValue(array('settings', 'region')); // Determine if we need to update or add this block. if ($uuid = $form_state->getValue('uuid')) { $this->panelsDisplay->updateBlock($uuid, $block_config); } else { $uuid = $this->panelsDisplay->addBlock($block_config); } // Set the tempstore value. $this->tempStore->set($this->panelsDisplay->id(), $this->panelsDisplay->getConfiguration()); // Assemble data required for our App. $build = $this->buildBlockInstance($block_instance); $form['build'] = $build; // Add our data attribute for the Backbone app. $build['#attributes']['data-block-id'] = $uuid; $block_model = ['uuid' => $uuid, 'label' => $block_instance->label(), 'id' => $block_instance->getPluginId(), 'region' => $block_config['region'], 'html' => $this->renderer->render($build)]; // Add Block metadata and HTML as a drupalSetting. $form['#attached']['drupalSettings']['panels_ipe']['updated_block'] = $block_model; return $form; }
/** * Tests a successful set() call. * * @covers ::set */ public function testSet() { $this->lock->expects($this->once())->method('acquire')->with('test')->will($this->returnValue(TRUE)); $this->lock->expects($this->never())->method('wait'); $this->lock->expects($this->once())->method('release')->with('test'); $this->keyValue->expects($this->once())->method('setWithExpire')->with('test', $this->ownObject, 604800); $this->tempStore->set('test', 'test_data'); }
/** * {@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; }
/** * Saves the current Panels display in the tempstore or real storage.. * * @param \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display * The Panels display to be saved. * @param bool $temp * Whether or not to save to temp store. * * @return \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant * The Panels display that was saved. * * @throws \Drupal\user\TempStoreException * If there are any issues manipulating the entry in the temp store. */ protected function savePanelsDisplay(PanelsDisplayVariant $panels_display, $temp = TRUE) { $temp_store_key = $panels_display->id(); // Save configuration to temp store. if ($temp) { $this->tempStore->set($temp_store_key, $panels_display->getConfiguration()); } else { // Check to see if temp store has configuration saved. if ($variant_config = $this->tempStore->get($temp_store_key)) { // Delete the existing temp store value. $this->tempStore->delete($temp_store_key); } // Save to the real storage. $this->panelsStorage->save($panels_display); } return $panels_display; }
/** * Takes the current Page Variant and saves it, optionally deleting anything * that may be in temp store. * * @param \Drupal\page_manager\PageVariantInterface $page_variant * The current Page Variant. * @param bool $temp * Whether or not to save to temp store. * * @return \Drupal\page_manager\PageVariantInterface */ protected function savePageVariant(PageVariantInterface $page_variant, $temp = TRUE) { $temp_store_key = 'variant.' . $page_variant->id(); // Save configuration to temp store. if ($temp) { /** @var \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $variant_plugin */ $variant_plugin = $page_variant->getVariantPlugin(); $this->tempStore->set($temp_store_key, $variant_plugin->getConfiguration()); } else { // Check to see if temp store has configuration saved. if ($variant_config = $this->tempStore->get($temp_store_key)) { // Delete the existing temp store value. $this->tempStore->delete($temp_store_key); } // Save the real entity. $page_variant->save(); } return $page_variant; }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $block_instance = $this->getBlockInstance($form_state); // Submit the block form. $block_instance->submitConfigurationForm($form, $form_state); // Save the block instance to our temporary configuration. /** @var \Drupal\page_manager\PageVariantInterface $page_variant */ $page_variant = PageVariant::load($form_state->getValue('variant_id')); /** @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); } // Set the block region appropriately. $block_config = $block_instance->getConfiguration(); $block_config['region'] = $form_state->getValue('region'); // Determine if we need to update or add this block. if ($uuid = $form_state->getValue('uuid')) { $variant_plugin->updateBlock($uuid, $block_config); } else { $uuid = $variant_plugin->addBlock($block_config); } // Set the tempstore value. $variant_config = $variant_plugin->getConfiguration(); $this->tempStore->set('variant.' . $page_variant->id(), $variant_config); // Assemble data required for our App. $build = $this->buildBlockInstance($block_instance); // Add our data attribute for the Backbone app. $build['#attributes']['data-block-id'] = $uuid; $settings = ['uuid' => $uuid, 'label' => $block_instance->label(), 'id' => $block_instance->getPluginId(), 'region' => $form_state->getValue('region'), 'html' => $this->renderer->render($build)]; // Add Block metadata and HTML as a drupalSetting. // @todo How do we handle #attachments in the $build this way? $form['#attached']['drupalSettings']['panels_ipe']['updated_block'] = $settings; return $form; }
/** * {@inheritdoc} */ public function executeMultiple(array $entities) { $this->tempStore->set($this->currentUser->id(), $entities); }
/** * Saves the given Panels Display to TempStore. * * @param \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display * @throws \Drupal\user\TempStoreException */ protected function savePanelsDisplayToTempStore(PanelsDisplayVariant $panels_display) { $this->tempStore->set($panels_display->id(), $panels_display->getConfiguration()); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { // Return early if there are any errors. if ($form_state->hasAnyErrors()) { return $form; } $block_instance = $this->getBlockInstance($form_state); // Submit the block configuration form. $this->submitBlock($block_instance, $form, $form_state); // 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); } // Set the block region appropriately. $block_config = $block_instance->getConfiguration(); $block_config['region'] = $form_state->getValue(array('settings', 'region')); // Determine if we need to update or add this block. if ($uuid = $form_state->getValue('uuid')) { $this->panelsDisplay->updateBlock($uuid, $block_config); } else { $uuid = $this->panelsDisplay->addBlock($block_config); } // Set the tempstore value. $this->tempStore->set($this->panelsDisplay->id(), $this->panelsDisplay->getConfiguration()); // Assemble data required for our App. $build = $this->buildBlockInstance($block_instance); // Bubble block attributes up if possible. This allows modules like // Quickedit to function. // See \Drupal\block\BlockViewBuilder::preRender() for reference. if ($build['content'] !== NULL && !Element::isEmpty($build['content'])) { foreach (['#attributes', '#contextual_links'] as $property) { if (isset($build['content'][$property])) { $build[$property] += $build['content'][$property]; unset($build['content'][$property]); } } } // Add our data attribute for the Backbone app. $build['#attributes']['data-block-id'] = $uuid; $block_model = ['uuid' => $uuid, 'label' => $block_instance->label(), 'id' => $block_instance->getPluginId(), 'region' => $block_config['region'], 'html' => $this->renderer->render($build)]; $form['build'] = $build; // Add Block metadata and HTML as a drupalSetting. $form['#attached']['drupalSettings']['panels_ipe']['updated_block'] = $block_model; return $form; }