/**
  * Constructs a new PanelsIPEBlockPluginForm.
  *
  * @param \Drupal\Component\Plugin\PluginManagerInterface $block_manager
  * @param \Drupal\Core\Plugin\Context\ContextHandlerInterface $context_handler
  * @param \Drupal\Core\Render\RendererInterface $renderer
  * @param \Drupal\user\SharedTempStoreFactory $temp_store_factory
  */
 public function __construct(PluginManagerInterface $block_manager, ContextHandlerInterface $context_handler, RendererInterface $renderer, SharedTempStoreFactory $temp_store_factory)
 {
     $this->blockManager = $block_manager;
     $this->contextHandler = $context_handler;
     $this->renderer = $renderer;
     $this->tempStore = $temp_store_factory->get('panels_ipe');
 }
 /**
  * Constructs a new PanelsIPEController.
  *
  * @param \Drupal\Core\Block\BlockManagerInterface $block_manager
  * @param \Drupal\Core\Render\RendererInterface $renderer
  * @param \Drupal\layout_plugin\Plugin\Layout\LayoutPluginManagerInterface $layout_plugin_manager
  * @param \Drupal\user\SharedTempStoreFactory $temp_store_factory
  */
 public function __construct(BlockManagerInterface $block_manager, RendererInterface $renderer, LayoutPluginManagerInterface $layout_plugin_manager, SharedTempStoreFactory $temp_store_factory)
 {
     $this->blockManager = $block_manager;
     $this->renderer = $renderer;
     $this->layoutPluginManager = $layout_plugin_manager;
     $this->tempStore = $temp_store_factory->get('panels_ipe');
 }
Example #3
0
 /**
  * Constructs a new ViewEditForm object.
  *
  * @param \Drupal\user\SharedTempStoreFactory $temp_store_factory
  *   The factory for the temp store object.
  * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
  *   The request stack object.
  * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
  *   The date Formatter service.
  * @param \Drupal\Core\Render\ElementInfoManagerInterface $element_info
  *   The element info manager.
  */
 public function __construct(SharedTempStoreFactory $temp_store_factory, RequestStack $requestStack, DateFormatterInterface $date_formatter, ElementInfoManagerInterface $element_info)
 {
     $this->tempStore = $temp_store_factory->get('views');
     $this->requestStack = $requestStack;
     $this->dateFormatter = $date_formatter;
     $this->elementInfo = $element_info;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, $machine_name = '')
 {
     $cached_values = $this->tempstore->get('ctools_wizard_test.config_entity')->get($machine_name);
     /** @var $page \Drupal\ctools_wizard_test\Entity\ExampleConfigEntity */
     $config_entity = $cached_values['ctools_wizard_test_config_entity'];
     $form['blah'] = ['#markup' => 'Value from one: ' . $config_entity->getOne()];
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
     $contexts = $this->getContexts($cached_values);
     unset($contexts[$this->id]);
     $cached_values = $this->setContexts($cached_values, $contexts);
     $this->tempstore->get($this->tempstore_id)->set($this->machine_name, $cached_values);
     list($route_name, $route_parameters) = $this->getRouteInfo();
     $form_state->setRedirect($route_name, $route_parameters);
 }
 /**
  * Constructs a new PanelsIPEController.
  *
  * @param \Drupal\Core\Block\BlockManagerInterface $block_manager
  * @param \Drupal\Core\Render\RendererInterface $renderer
  * @param \Drupal\layout_plugin\Plugin\Layout\LayoutPluginManagerInterface $layout_plugin_manager
  * @param \Drupal\panels\Storage\PanelsStorageManagerInterface $panels_storage_manager
  * @param \Drupal\user\SharedTempStoreFactory $temp_store_factory
  */
 public function __construct(BlockManagerInterface $block_manager, RendererInterface $renderer, LayoutPluginManagerInterface $layout_plugin_manager, PanelsStorageManagerInterface $panels_storage_manager, SharedTempStoreFactory $temp_store_factory)
 {
     $this->blockManager = $block_manager;
     $this->renderer = $renderer;
     $this->layoutPluginManager = $layout_plugin_manager;
     $this->panelsStorage = $panels_storage_manager;
     $this->tempStore = $temp_store_factory->get('panels_ipe');
     $this->updateLayoutRequestHandler = new UpdateLayoutRequestHandler($this->moduleHandler(), $this->panelsStorage, $this->tempStore);
     $this->removeBlockRequestHandler = new RemoveBlockRequestHandler($this->moduleHandler(), $this->panelsStorage, $this->tempStore);
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
     $conditions = $this->getConditions($cached_values);
     /** @var  $instance \Drupal\ctools\ConstraintConditionInterface */
     $instance = $this->manager->createInstance($conditions[$this->id]['id'], $conditions[$this->id]);
     if ($instance instanceof ConstraintConditionInterface) {
         $instance->removeConstraints($this->getContexts($cached_values));
     }
     unset($conditions[$this->id]);
     $cached_values = $this->setConditions($cached_values, $conditions);
     $this->tempstore->get($this->tempstore_id)->set($this->machine_name, $cached_values);
     list($route_name, $route_parameters) = $this->getRouteInfo();
     $form_state->setRedirect($route_name, $route_parameters);
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 public function convert($value, $definition, $name, array $defaults)
 {
     // Standard upcasting: check if the config entity exists at all in the
     // storage.
     if (!($entity = parent::convert($value, $definition, $name, $defaults))) {
         return;
     }
     // Now check if there is also a version being edited and return that.
     $store = $this->tempStoreFactory->get($entity->getEntityTypeId());
     $edited_entity = $store->get($value);
     if ($edited_entity) {
         return $edited_entity;
     }
     return $entity;
 }
Example #9
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $store = $this->tempStoreFactory->get($this->entity->getEntityTypeId());
     $store->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 rule.'));
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
     /** @var $instance \Drupal\Core\Condition\ConditionInterface */
     $instance = $form_state->getValue('instance');
     $instance->submitConfigurationForm($form, $form_state);
     $conditions = $this->getConditions($cached_values);
     if ($instance instanceof ContextAwarePluginInterface) {
         /** @var  $instance \Drupal\Core\Plugin\ContextAwarePluginInterface */
         $context_mapping = $form_state->hasValue('context_mapping') ? $form_state->getValue('context_mapping') : [];
         $instance->setContextMapping($context_mapping);
     }
     if ($instance instanceof ConstraintConditionInterface) {
         /** @var  $instance \Drupal\ctools\ConstraintConditionInterface */
         $instance->applyConstraints($this->getContexts($cached_values));
     }
     if ($form_state->hasValue('id')) {
         $conditions[$form_state->getValue('id')] = $instance->getConfiguration();
     } else {
         $conditions[] = $instance->getConfiguration();
     }
     $cached_values = $this->setConditions($cached_values, $conditions);
     $this->tempstore->get($this->tempstore_id)->set($this->machine_name, $cached_values);
     list($route_name, $route_parameters) = $this->getParentRouteInfo();
     $form_state->setRedirect($route_name, $route_parameters);
 }
 public function ajaxSave(array &$form, FormStateInterface $form_state)
 {
     $response = new AjaxResponse();
     $cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
     list($route_name, $route_parameters) = $this->getParentRouteInfo($cached_values);
     $response->addCommand(new RedirectCommand($this->url($route_name, $route_parameters)));
     $response->addCommand(new CloseModalDialogCommand());
     return $response;
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
     /** @var $policy \Drupal\password_policy\Entity\PasswordPolicy */
     $policy = $cached_values['password_policy'];
     $constraints = $policy->getConstraints();
     unset($constraints[$this->id]);
     $policy->set('policy_constraints', $constraints);
     $this->tempstore->get($this->tempstore_id)->set($this->machine_name, $cached_values);
     $form_state->setRedirect('entity.password_policy.wizard.edit', ['machine_name' => $this->machine_name, 'step' => 'constraint']);
 }
 /**
  * {@inheritdoc}
  */
 public function convert($value, $definition, $name, array $defaults)
 {
     /** @var \Drupal\search_api\IndexInterface $entity */
     if (!($entity = parent::convert($value, $definition, $name, $defaults))) {
         return NULL;
     }
     // Get the temp store for this variable if it needs one. Attempt to load the
     // index from the temp store, update the currently logged-in user's ID and
     // store the lock metadata.
     $store = $this->tempStoreFactory->get('search_api_index');
     $current_user_id = $this->currentUser->id() ?: session_id();
     /** @var \Drupal\search_api\IndexInterface|\Drupal\search_api\UnsavedConfigurationInterface $index */
     if ($index = $store->get($value)) {
         $index->setCurrentUserId($current_user_id);
         $index->setLockInformation($store->getMetadata($value));
     } else {
         $index = new UnsavedIndexConfiguration($entity, $store, $current_user_id);
     }
     return $index;
 }
Example #14
0
 /**
  * {@inheritdoc}
  */
 public function convert($value, $definition, $name, array $defaults)
 {
     if (!($entity = parent::convert($value, $definition, $name, $defaults))) {
         return;
     }
     // Get the temp store for this variable if it needs one. Attempt to load the
     // view from the temp store, synchronize its status with the existing view,
     // and store the lock metadata.
     $store = $this->tempStoreFactory->get('views');
     if ($view = $store->get($value)) {
         if ($entity->status()) {
             $view->enable();
         } else {
             $view->disable();
         }
         $view->lock = $store->getMetadata($value);
     } else {
         $view = new ViewUI($entity);
     }
     return $view;
 }
 /**
  * Update entity browser configuration.
  *
  * @param string $browser
  *   Id of the entity browser.
  * @param array $configuration
  *   Configuration array to update.
  * @param array $oldConfiguration
  *   Only if current config is same like old config we are updating.
  *
  * @return bool
  *   Indicates if config was updated or not.
  */
 public function updateEntityBrowserConfig($browser, $configuration, $oldConfiguration = [])
 {
     $ebConfig = $this->configFactory->getEditable('entity_browser.browser.' . $browser);
     $config = $ebConfig->get();
     if (!empty($oldConfiguration) && DiffArray::diffAssocRecursive($oldConfiguration, $config)) {
         return FALSE;
     }
     $ebConfig->setData(NestedArray::mergeDeep($config, $configuration));
     $ebConfig->save();
     // Update entity browser edit form.
     $entityBrowserConfig = $this->tempStoreFactory->get('entity_browser.config');
     $storage = $entityBrowserConfig->get($browser);
     if (!empty($storage)) {
         foreach ($configuration as $key => $value) {
             $part = $storage['entity_browser']->getPluginCollections()[$key];
             $part->setConfiguration(NestedArray::mergeDeep($part->getConfiguration(), $value));
         }
         $entityBrowserConfig->set($browser, $storage);
     }
     return TRUE;
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
     $contexts = $this->getContexts($cached_values);
     $context = ['context' => $form_state->getValue('context'), 'label' => $form_state->getValue('label'), 'machine_name' => $form_state->getValue('machine_name'), 'description' => $form_state->getValue('description')];
     if ($form_state->hasValue('id')) {
         $contexts[$form_state->getValue('id')] = $context;
     } else {
         $contexts[] = $context;
     }
     $cached_values = $this->setContexts($cached_values, $contexts);
     $this->tempstore->get($this->tempstore_id)->set($this->machine_name, $cached_values);
     list($route_name, $route_parameters) = $this->getRouteInfo();
     $form_state->setRedirect($route_name, $route_parameters);
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
     /** @var $policy \Drupal\password_policy\Entity\PasswordPolicy */
     $policy = $cached_values['password_policy'];
     $constraints = $policy->getConstraints();
     /** @var $instance \Drupal\password_policy\PasswordConstraintInterface */
     $instance = $form_state->getValue('instance');
     $instance->submitConfigurationForm($form, $form_state);
     if ($form_state->hasValue('id')) {
         $constraints[$form_state->getValue('id')] = $instance->getConfiguration();
     } else {
         $constraints[] = $instance->getConfiguration();
     }
     $policy->set('policy_constraints', $constraints);
     $this->tempstore->get($this->tempstore_id)->set($this->machine_name, $cached_values);
     $form_state->setRedirect('entity.password_policy.wizard.edit', ['machine_name' => $this->machine_name, 'step' => 'constraint']);
 }
Example #18
0
 /**
  * {@inheritdoc}
  */
 public function convert($value, $definition, $name, array $defaults)
 {
     $tempstore_id = !empty($definition['tempstore_id']) ? $definition['tempstore_id'] : $defaults['tempstore_id'];
     $machine_name = $this->convertVariable($value, $defaults);
     list(, $parts) = explode(':', $definition['type'], 2);
     $parts = explode(':', $parts);
     foreach ($parts as $key => $part) {
         $parts[$key] = $this->convertVariable($part, $defaults);
     }
     $cached_values = $this->tempstore->get($tempstore_id)->get($machine_name);
     // Entity type upcasting is most common, so we just assume that here.
     // @todo see if there's a better way to do this.
     if (!$cached_values && $this->entityTypeManager->hasDefinition($name)) {
         $value = $this->entityTypeManager->getStorage($name)->load($machine_name);
         return $value;
     } elseif (!$cached_values) {
         return NULL;
     } else {
         $value = NestedArray::getValue($cached_values, $parts, $key_exists);
         return $key_exists ? $value : NULL;
     }
 }
 /**
  * Constructs a new InPlaceEditorDisplayBuilder.
  *
  * @param array $configuration
  *   A configuration array containing information about the plugin instance.
  * @param string $plugin_id
  *   The plugin ID for the plugin instance.
  * @param mixed $plugin_definition
  *   The plugin definition.
  * @param \Drupal\Core\Plugin\Context\ContextHandlerInterface $context_handler
  *   The context handler.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The current user.
  * @param \Drupal\user\SharedTempStoreFactory $temp_store_factory
  *   The factory for the temp store object.
  */
 public function __construct(array $configuration, $plugin_id, $plugin_definition, ContextHandlerInterface $context_handler, AccountInterface $account, SharedTempStoreFactory $temp_store_factory)
 {
     parent::__construct($configuration, $plugin_id, $plugin_definition, $context_handler, $account);
     $this->tempStore = $temp_store_factory->get('panels_ipe');
 }
 /**
  * Constructs an IndexBreakLockForm object.
  *
  * @param \Drupal\user\SharedTempStoreFactory $temp_store_factory
  *   The factory for shared temporary storages.
  * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
  *   The Entity manager.
  * @param \Drupal\Core\Render\RendererInterface $renderer
  *   The renderer to use.
  */
 public function __construct(SharedTempStoreFactory $temp_store_factory, EntityTypeManagerInterface $entity_type_manager, RendererInterface $renderer)
 {
     $this->tempStore = $temp_store_factory->get('search_api_index');
     $this->entityTypeManager = $entity_type_manager;
     $this->renderer = $renderer;
 }
Example #21
0
 protected function setTempstore($cached_values)
 {
     $this->tempstore->get($this->tempstore_id)->set($this->machine_name, $cached_values);
 }
 /**
  * Tests the UserTempStore API.
  */
 public function testUserTempStore()
 {
     // Create a key/value collection.
     $factory = new SharedTempStoreFactory(new KeyValueExpirableFactory(\Drupal::getContainer()), new DatabaseLockBackend(Database::getConnection()));
     $collection = $this->randomMachineName();
     // Create two mock users.
     for ($i = 0; $i <= 1; $i++) {
         $users[$i] = mt_rand(500, 5000000);
         // Storing the SharedTempStore objects in a class member variable causes a
         // fatal exception, because in that situation garbage collection is not
         // triggered until the test class itself is destructed, after tearDown()
         // has deleted the database tables. Store the objects locally instead.
         $stores[$i] = $factory->get($collection, $users[$i]);
     }
     $key = $this->randomMachineName();
     // Test that setIfNotExists() succeeds only the first time.
     for ($i = 0; $i <= 1; $i++) {
         // setIfNotExists() should be TRUE the first time (when $i is 0) and
         // FALSE the second time (when $i is 1).
         $this->assertEqual(!$i, $stores[0]->setIfNotExists($key, $this->objects[$i]));
         $metadata = $stores[0]->getMetadata($key);
         $this->assertEqual($users[0], $metadata->owner);
         $this->assertIdenticalObject($this->objects[0], $stores[0]->get($key));
         // Another user should get the same result.
         $metadata = $stores[1]->getMetadata($key);
         $this->assertEqual($users[0], $metadata->owner);
         $this->assertIdenticalObject($this->objects[0], $stores[1]->get($key));
     }
     // Remove the item and try to set it again.
     $stores[0]->delete($key);
     $stores[0]->setIfNotExists($key, $this->objects[1]);
     // This time it should succeed.
     $this->assertIdenticalObject($this->objects[1], $stores[0]->get($key));
     // This user can update the object.
     $stores[0]->set($key, $this->objects[2]);
     $this->assertIdenticalObject($this->objects[2], $stores[0]->get($key));
     // The object is the same when another user loads it.
     $this->assertIdenticalObject($this->objects[2], $stores[1]->get($key));
     // This user should be allowed to get, update, delete.
     $this->assertTrue($stores[0]->getIfOwner($key) instanceof \stdClass);
     $this->assertTrue($stores[0]->setIfOwner($key, $this->objects[1]));
     $this->assertTrue($stores[0]->deleteIfOwner($key));
     // Another user can update the object and become the owner.
     $stores[1]->set($key, $this->objects[3]);
     $this->assertIdenticalObject($this->objects[3], $stores[0]->get($key));
     $this->assertIdenticalObject($this->objects[3], $stores[1]->get($key));
     $metadata = $stores[1]->getMetadata($key);
     $this->assertEqual($users[1], $metadata->owner);
     // The first user should be informed that the second now owns the data.
     $metadata = $stores[0]->getMetadata($key);
     $this->assertEqual($users[1], $metadata->owner);
     // The first user should no longer be allowed to get, update, delete.
     $this->assertNull($stores[0]->getIfOwner($key));
     $this->assertFalse($stores[0]->setIfOwner($key, $this->objects[1]));
     $this->assertFalse($stores[0]->deleteIfOwner($key));
     // Now manually expire the item (this is not exposed by the API) and then
     // assert it is no longer accessible.
     db_update('key_value_expire')->fields(array('expire' => REQUEST_TIME - 1))->condition('collection', "user.shared_tempstore.{$collection}")->condition('name', $key)->execute();
     $this->assertFalse($stores[0]->get($key));
     $this->assertFalse($stores[1]->get($key));
 }
Example #23
0
 /**
  * Constructs a \Drupal\views_ui\Form\BreakLockForm object.
  *
  * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
  *   The Entity manager.
  * @param \Drupal\user\SharedTempStoreFactory $temp_store_factory
  *   The factory for the temp store object.
  */
 public function __construct(EntityManagerInterface $entity_manager, SharedTempStoreFactory $temp_store_factory)
 {
     $this->entityManager = $entity_manager;
     $this->tempStore = $temp_store_factory->get('views');
 }
 /**
  * Constructs an IndexAddFieldsForm object.
  *
  * @param \Drupal\user\SharedTempStoreFactory $temp_store_factory
  *   The factory for shared temporary storages.
  * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
  *   The entity manager.
  * @param \Drupal\search_api\DataType\DataTypePluginManager $data_type_plugin_manager
  *   The data type plugin manager.
  * @param \Drupal\Core\Render\RendererInterface $renderer
  *   The renderer to use.
  * @param \Drupal\Core\Datetime\DateFormatter $date_formatter
  *   The date formatter.
  * @param array $parameters
  *   The parameters for this page request.
  */
 public function __construct(SharedTempStoreFactory $temp_store_factory, EntityTypeManagerInterface $entity_type_manager, DataTypePluginManager $data_type_plugin_manager, RendererInterface $renderer, DateFormatter $date_formatter, array $parameters)
 {
     $this->tempStore = $temp_store_factory->get('search_api_index');
     $this->entityTypeManager = $entity_type_manager;
     $this->dataTypePluginManager = $data_type_plugin_manager;
     $this->renderer = $renderer;
     $this->dateFormatter = $date_formatter;
     $this->parameters = $parameters;
 }
Example #25
0
 /**
  * {@inheritdoc}
  */
 public function getCancelUrl()
 {
     $cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
     list($route_name, $route_parameters) = $this->getParentRouteInfo($cached_values);
     return new Url($route_name, $route_parameters);
 }
Example #26
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $cached_values = $this->tempstore->get($this->tempstore_id)->get($this->machine_name);
     $form_state->setRedirectUrl($this->getCancelUrl($cached_values));
 }
Example #27
0
 /**
  * {@inheritdoc}
  */
 public function getTempstore()
 {
     return $this->tempstore->get($this->getTempstoreId());
 }
Example #28
0
 /**
  * Constructs a new ViewEditForm object.
  *
  * @param \Drupal\user\SharedTempStoreFactory $temp_store_factory
  *   The factory for the temp store object.
  * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
  *   The request stack object.
  * @param \Drupal\Core\Datetime\DateFormatter $date_formatter
  *   The date Formatter service.
  */
 public function __construct(SharedTempStoreFactory $temp_store_factory, RequestStack $requestStack, DateFormatter $date_formatter)
 {
     $this->tempStore = $temp_store_factory->get('views');
     $this->requestStack = $requestStack;
     $this->dateFormatter = $date_formatter;
 }