/**
  * Constructs a \Drupal\demo\Form\Multistep\MultistepFormBase.
  *
  * @param \Drupal\user\PrivateTempStoreFactory $temp_store_factory
  * @param \Drupal\Core\Session\SessionManagerInterface $session_manager
  * @param \Drupal\Core\Session\AccountInterface $current_user
  */
 public function __construct(PrivateTempStoreFactory $temp_store_factory, SessionManagerInterface $session_manager, AccountInterface $current_user)
 {
     $this->tempStoreFactory = $temp_store_factory;
     $this->sessionManager = $session_manager;
     $this->currentUser = $current_user;
     $this->store = $this->tempStoreFactory->get('multistep_data');
 }
Exemplo n.º 2
0
 /**
  * {@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();
     }
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $this->taskInfo = $this->tempStoreFactory->get('task_multiple_assign')->get(\Drupal::currentUser()->id());
     $form_state->set('tasks', array_keys($this->taskInfo));
     $roles = tmgmt_local_translator_roles();
     if (empty($roles)) {
         drupal_set_message(t('No user role has the "provide translation services" permission. <a href="@url">Configure permissions</a> for the Drupal user module.', array('@url' => URL::fromRoute('user.admin_permissions'))), 'warning');
     }
     $form['tuid'] = array('#title' => t('Assign to'), '#type' => 'select', '#empty_option' => t('- Select user -'), '#options' => tmgmt_local_get_assignees_for_tasks($form_state->get('tasks')), '#required' => TRUE);
     $form['actions']['#type'] = 'actions';
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Assign tasks'));
     return $form;
 }
Exemplo n.º 4
0
 /**
  * {@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);
 }
Exemplo n.º 5
0
 /**
  * {@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');
         $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();
     }
 }
Exemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $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->getValue('confirm')) {
         foreach ($form_state->getValue('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;
                 $admin_form_state->unsetValue('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->submitForm($admin_form_mock, $admin_form_state);
             } else {
                 user_cancel($form_state->getValues(), $uid, $form_state->getValue('user_cancel_method'));
             }
         }
     }
     $form_state->setRedirect('entity.user.collection');
 }
Exemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state) {
   if ($form_state->getValue('confirm') && !empty($this->profiles)) {
     $this->storage->delete($this->profiles);
     $this->privateTempStoreFactory->get('profile_multiple_delete_confirm')->delete(\Drupal::currentUser()->id());
     $count = count($this->profiles);
     $this->logger('content')->notice('Deleted @count profiles.', ['@count' => $count]);
     drupal_set_message(\Drupal::translation()->formatPlural($count, 'Deleted 1 profile.', 'Deleted @count profiles.'));
   }
   $form_state->setRedirect('entity.profile.collection');
 }
Exemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     if ($form_state->getValue('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($this->formatPlural($count, 'Deleted 1 post.', 'Deleted @count posts.'));
     }
     $form_state->setRedirect('system.admin_content');
 }
Exemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     if ($form_state->getValue('confirm') && !empty($this->feeds)) {
         $this->storage->delete($this->feeds);
         $this->tempStoreFactory->get('feeds_feed_multiple_delete_confirm')->delete($this->user->id());
         $count = count($this->feeds);
         $this->logger('feeds')->notice('Deleted @count feeds.', ['@count' => $count]);
         drupal_set_message($this->formatPlural($count, 'Deleted 1 feed.', 'Deleted @count posts.'));
     }
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
Exemplo n.º 10
0
 /**
  * Saves an entity into the database, from PrivateTempStore.
  *
  * @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 PrivateTempStore and save in entity storage.
     // fieldForm() ensures that the PrivateTempStore 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;
 }
Exemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     if ($form_state->getValue('confirm') && !empty($this->nodeInfo)) {
         $total_count = 0;
         $delete_nodes = [];
         /** @var \Drupal\Core\Entity\ContentEntityInterface[][] $delete_translations */
         $delete_translations = [];
         /** @var \Drupal\node\NodeInterface[] $nodes */
         $nodes = $this->storage->loadMultiple(array_keys($this->nodeInfo));
         foreach ($this->nodeInfo as $id => $langcodes) {
             foreach ($langcodes as $langcode) {
                 $node = $nodes[$id]->getTranslation($langcode);
                 if ($node->isDefaultTranslation()) {
                     $delete_nodes[$id] = $node;
                     unset($delete_translations[$id]);
                     $total_count += count($node->getTranslationLanguages());
                 } elseif (!isset($delete_nodes[$id])) {
                     $delete_translations[$id][] = $node;
                 }
             }
         }
         if ($delete_nodes) {
             $this->storage->delete($delete_nodes);
             $this->logger('content')->notice('Deleted @count posts.', array('@count' => count($delete_nodes)));
         }
         if ($delete_translations) {
             $count = 0;
             foreach ($delete_translations as $id => $translations) {
                 $node = $nodes[$id]->getUntranslated();
                 foreach ($translations as $translation) {
                     $node->removeTranslation($translation->language()->getId());
                 }
                 $node->save();
                 $count += count($translations);
             }
             if ($count) {
                 $total_count += $count;
                 $this->logger('content')->notice('Deleted @count content translations.', array('@count' => $count));
             }
         }
         if ($total_count) {
             drupal_set_message($this->formatPlural($total_count, 'Deleted 1 post.', 'Deleted @count posts.'));
         }
         $this->tempStoreFactory->get('node_multiple_delete_confirm')->delete(\Drupal::currentUser()->id());
     }
     $form_state->setRedirect('system.admin_content');
 }
Exemplo n.º 12
0
 /**
  * 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\PrivateTempStoreFactory $temp_store_factory
  *   The tempstore factory.
  * @param AccountInterface $current_user
  *   Current user.
  */
 public function __construct(array $configuration, $plugin_id, $plugin_definition, PrivateTempStoreFactory $temp_store_factory, AccountInterface $current_user)
 {
     $this->currentUser = $current_user;
     $this->tempStore = $temp_store_factory->get('node_multiple_delete_confirm');
     parent::__construct($configuration, $plugin_id, $plugin_definition);
 }
Exemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 public function executeMultiple(array $entities) {
   $this->privateTempStore->set(\Drupal::currentUser()->id(), $entities);
 }
Exemplo n.º 14
0
 /**
  * {@inheritdoc}
  */
 public function executeMultiple(array $entities)
 {
     $this->tempStoreFactory->get('user_user_operations_cancel')->set($this->currentUser->id(), $entities);
 }
Exemplo n.º 15
0
 /**
  * Constructs a new DeleteMultiple object.
  *
  * @param \Drupal\Core\Session\AccountInterface $current_user
  *   The current user.
  * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
  *   The entity type manager.
  * @param \Drupal\user\PrivateTempStoreFactory $temp_store_factory
  *   The tempstore factory.
  */
 public function __construct(AccountInterface $current_user, EntityTypeManagerInterface $entity_type_manager, PrivateTempStoreFactory $temp_store_factory)
 {
     $this->currentUser = $current_user;
     $this->entityTypeManager = $entity_type_manager;
     $this->tempStore = $temp_store_factory->get('entity_delete_multiple_confirm');
 }