/**
  * {@inheritdoc}
  */
 public function convert($value, $definition, $name, array $defaults)
 {
     $store = $this->tempStoreFactory->get('node_preview');
     if ($form_state = $store->get($value)) {
         return $form_state->getFormObject()->getEntity();
     }
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, array &$form_state)
 {
     $current_user_id = $this->currentUser()->id();
     // Clear out the accounts from the temp store.
     $this->tempStoreFactory->get('user_user_operations_cancel')->delete($current_user_id);
     if ($form_state['values']['confirm']) {
         foreach ($form_state['values']['accounts'] as $uid => $value) {
             // Prevent programmatic form submissions from cancelling user 1.
             if ($uid <= 1) {
                 continue;
             }
             // Prevent user administrators from deleting themselves without confirmation.
             if ($uid == $current_user_id) {
                 $admin_form_mock = array();
                 $admin_form_state = $form_state;
                 unset($admin_form_state['values']['user_cancel_confirm']);
                 // The $user global is not a complete user entity, so load the full
                 // entity.
                 $account = $this->userStorage->load($uid);
                 $admin_form = $this->entityManager->getFormObject('user', 'cancel');
                 $admin_form->setEntity($account);
                 // Calling this directly required to init form object with $account.
                 $admin_form->buildForm($admin_form_mock, $admin_form_state);
                 $admin_form->submit($admin_form_mock, $admin_form_state);
             } else {
                 user_cancel($form_state['values'], $uid, $form_state['values']['user_cancel_method']);
             }
         }
     }
     $form_state['redirect_route']['route_name'] = 'user.admin_account';
 }
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     $node = $this->entity;
     $insert = $node->isNew();
     $node->save();
     $node_link = $node->link($this->t('View'));
     $context = array('@type' => $node->getType(), '%title' => $node->label(), 'link' => $node_link);
     $t_args = array('@type' => node_get_type_label($node), '%title' => $node->label());
     if ($insert) {
         $this->logger('content')->notice('@type: added %title.', $context);
         drupal_set_message(t('@type %title has been created.', $t_args));
     } else {
         $this->logger('content')->notice('@type: updated %title.', $context);
         drupal_set_message(t('@type %title has been updated.', $t_args));
     }
     if ($node->id()) {
         $form_state->setValue('nid', $node->id());
         $form_state->set('nid', $node->id());
         if ($node->access('view')) {
             $form_state->setRedirect('entity.node.canonical', array('node' => $node->id()));
         } else {
             $form_state->setRedirect('<front>');
         }
         // Remove the preview entry from the temp store, if any.
         $store = $this->tempStoreFactory->get('node_preview');
         if ($store->get($node->uuid())) {
             $store->delete($node->uuid());
         }
     } else {
         // In the unlikely case something went wrong on save, the node will be
         // rebuilt and node form redisplayed the same way as in preview.
         drupal_set_message(t('The post could not be saved.'), 'error');
         $form_state->setRebuild();
     }
 }
 /**
  * {@inheritdoc}
  *
  * Saves the entity with updated values for the edited field.
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $entity = $this->buildEntity($form, $form_state);
     $form_state->set('entity', $entity);
     // Store entity in tempstore with its UUID as tempstore key.
     $this->tempStoreFactory->get('quickedit')->set($entity->uuid(), $entity);
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, array &$form_state)
 {
     if ($form_state['values']['confirm'] && !empty($this->nodes)) {
         $this->storage->delete($this->nodes);
         $this->tempStoreFactory->get('node_multiple_delete_confirm')->delete(\Drupal::currentUser()->id());
         $count = count($this->nodes);
         watchdog('content', 'Deleted @count posts.', array('@count' => $count));
         drupal_set_message(format_plural($count, 'Deleted 1 post.', 'Deleted @count posts.'));
     }
     $form_state['redirect_route']['route_name'] = 'system.admin_content';
 }
Esempio n. 6
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     if ($form_state['values']['confirm'] && !empty($this->nodes)) {
         $this->storage->delete($this->nodes);
         $this->tempStoreFactory->get('node_multiple_delete_confirm')->delete(\Drupal::currentUser()->id());
         $count = count($this->nodes);
         $this->logger('content')->notice('Deleted @count posts.', array('@count' => $count));
         drupal_set_message(format_plural($count, 'Deleted 1 post.', 'Deleted @count posts.'));
     }
     $form_state->setRedirect('system.admin_content');
 }
 /**
  * {@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;
 }
Esempio n. 8
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, array &$form_state)
 {
     if ($form_state['values']['confirm'] && !empty($this->feeds)) {
         $this->storageController->delete($this->feeds);
         $this->tempStoreFactory->get('feeds_multiple_delete_confirm')->delete($GLOBALS['user']->id());
         $count = count($this->feeds);
         watchdog('content', 'Deleted @count feeds.', array('@count' => $count));
         drupal_set_message(format_plural($count, 'Deleted 1 feed.', 'Deleted @count posts.', array('@count' => $count)));
     }
     // @todo Set the correct route once views can override paths.
     $form_state['redirect'] = 'admin/content/feed';
 }
Esempio n. 9
0
 /**
  * Saves an entity into the database, from TempStore.
  *
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The entity being edited.
  *
  * @return \Drupal\Core\Ajax\AjaxResponse
  *   The Ajax response.
  */
 public function entitySave(EntityInterface $entity)
 {
     // Take the entity from TempStore and save in entity storage. fieldForm()
     // ensures that the TempStore copy exists ahead.
     $tempstore = $this->tempStoreFactory->get('quickedit');
     $tempstore->get($entity->uuid())->save();
     $tempstore->delete($entity->uuid());
     // Return information about the entity that allows a front end application
     // to identify it.
     $output = array('entity_type' => $entity->getEntityTypeId(), 'entity_id' => $entity->id());
     // Respond to client that the entity was saved properly.
     $response = new AjaxResponse();
     $response->addCommand(new EntitySavedCommand($output));
     return $response;
 }
 /**
  * Tests the UserTempStore API.
  */
 public function testUserTempStore()
 {
     // Create a key/value collection.
     $factory = new TempStoreFactory(new PhpSerialize(), Database::getConnection(), 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 TempStore 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', $collection)->condition('name', $key)->execute();
     $this->assertFalse($stores[0]->get($key));
     $this->assertFalse($stores[1]->get($key));
 }
Esempio n. 11
0
 /**
  * Constructs a new ViewPreviewForm object.
  *
  * @param \Drupal\user\TempStoreFactory $temp_store_factory
  *   The factory for the temp store object.
  */
 public function __construct(TempStoreFactory $temp_store_factory)
 {
     $this->tempStore = $temp_store_factory->get('views');
 }
 /**
  * Constructs a new DeleteNode object.
  *
  * @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 implementation definition.
  * @param \Drupal\user\TempStoreFactory $temp_store_factory
  *   The tempstore factory.
  */
 public function __construct(array $configuration, $plugin_id, $plugin_definition, TempStoreFactory $temp_store_factory)
 {
     parent::__construct($configuration, $plugin_id, $plugin_definition);
     $this->tempStore = $temp_store_factory->get('node_multiple_delete_confirm');
 }
Esempio n. 13
0
 /**
  * Constructs a new ViewEditForm object.
  *
  * @param \Drupal\user\TempStoreFactory $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(TempStoreFactory $temp_store_factory, RequestStack $requestStack, DateFormatter $date_formatter)
 {
     $this->tempStore = $temp_store_factory->get('views');
     $this->requestStack = $requestStack;
     $this->dateFormatter = $date_formatter;
 }
 /**
  * {@inheritdoc}
  */
 public function executeMultiple(array $entities)
 {
     $this->tempStoreFactory->get('user_user_operations_cancel')->set(\Drupal::currentUser()->id(), $entities);
 }
Esempio n. 15
0
 /**
  * Constructs a new ViewEditForm object.
  *
  * @param \Drupal\user\TempStoreFactory $temp_store_factory
  *   The factory for the temp store object.
  * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
  *   The request stack object.
  */
 public function __construct(TempStoreFactory $temp_store_factory, RequestStack $requestStack)
 {
     $this->tempStore = $temp_store_factory->get('views');
     $this->requestStack = $requestStack;
 }
Esempio n. 16
0
 /**
  * {@inheritdoc}
  *
  * Saves the entity with updated values for the edited field.
  */
 public function submitForm(array &$form, array &$form_state)
 {
     $form_state['entity'] = $this->buildEntity($form, $form_state);
     // Store entity in tempstore with its UUID as tempstore key.
     $this->tempStoreFactory->get('quickedit')->set($form_state['entity']->uuid(), $form_state['entity']);
 }
Esempio n. 17
0
 /**
  * Constructs a \Drupal\views_ui\Form\BreakLockForm object.
  *
  * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
  *   The Entity manager.
  * @param \Drupal\user\TempStoreFactory $temp_store_factory
  *   The factory for the temp store object.
  */
 public function __construct(EntityManagerInterface $entity_manager, TempStoreFactory $temp_store_factory)
 {
     $this->entityManager = $entity_manager;
     $this->tempStore = $temp_store_factory->get('views');
 }