Example #1
0
 /**
  * {@inheritdoc}
  */
 public function import(Row $row, array $old_destination_id_values = array())
 {
     /** @var \Drupal\shortcut\ShortcutSetInterface $set */
     $set = $this->shortcutSetStorage->load($row->getDestinationProperty('set_name'));
     /** @var \Drupal\user\UserInterface $account */
     $account = User::load($row->getDestinationProperty('uid'));
     $this->shortcutSetStorage->assignUser($set, $account);
     return array($set->id(), $account->id());
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $account = $this->currentUser();
     $account_is_user = $this->user->id() == $account->id();
     if ($form_state->getValue('set') == 'new') {
         // Save a new shortcut set with links copied from the user's default set.
         /* @var \Drupal\shortcut\Entity\ShortcutSet $set */
         $set = $this->shortcutSetStorage->create(array('id' => $form_state->getValue('id'), 'label' => $form_state->getValue('label')));
         $set->save();
         $replacements = array('%user' => $this->user->label(), '%set_name' => $set->label(), ':switch-url' => $this->url('<current>'));
         if ($account_is_user) {
             // Only administrators can create new shortcut sets, so we know they have
             // access to switch back.
             drupal_set_message($this->t('You are now using the new %set_name shortcut set. You can edit it from this page or <a href=":switch-url">switch back to a different one.</a>', $replacements));
         } else {
             drupal_set_message($this->t('%user is now using a new shortcut set called %set_name. You can edit it from this page.', $replacements));
         }
         $form_state->setRedirect('entity.shortcut_set.customize_form', array('shortcut_set' => $set->id()));
     } else {
         // Switch to a different shortcut set.
         /* @var \Drupal\shortcut\Entity\ShortcutSet $set */
         $set = $this->shortcutSetStorage->load($form_state->getValue('set'));
         $replacements = array('%user' => $this->user->getDisplayName(), '%set_name' => $set->label());
         drupal_set_message($account_is_user ? $this->t('You are now using the %set_name shortcut set.', $replacements) : $this->t('%user is now using the %set_name shortcut set.', $replacements));
     }
     // Assign the shortcut set to the provided user account.
     $this->shortcutSetStorage->assignUser($set, $this->user);
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, array &$form_state)
 {
     $account = $this->currentUser();
     $account_is_user = $this->user->id() == $account->id();
     if ($form_state['values']['set'] == 'new') {
         // Save a new shortcut set with links copied from the user's default set.
         /* @var \Drupal\shortcut\Entity\ShortcutSet $set */
         $set = $this->shortcutSetStorage->create(array('id' => $form_state['values']['id'], 'label' => $form_state['values']['label']));
         $set->save();
         $replacements = array('%user' => $this->user->label(), '%set_name' => $set->label(), '@switch-url' => $this->url($this->routeMatch->getRouteName(), array('user' => $this->user->id())));
         if ($account_is_user) {
             // Only administrators can create new shortcut sets, so we know they have
             // access to switch back.
             drupal_set_message($this->t('You are now using the new %set_name shortcut set. You can edit it from this page or <a href="@switch-url">switch back to a different one.</a>', $replacements));
         } else {
             drupal_set_message($this->t('%user is now using a new shortcut set called %set_name. You can edit it from this page.', $replacements));
         }
         $form_state['redirect_route'] = array('route_name' => 'shortcut.set_customize', 'route_parameters' => array('shortcut_set' => $set->id()));
     } else {
         // Switch to a different shortcut set.
         /* @var \Drupal\shortcut\Entity\ShortcutSet $set */
         $set = $this->shortcutSetStorage->load($form_state['values']['set']);
         $replacements = array('%user' => $this->user->label(), '%set_name' => $set->label());
         drupal_set_message($account_is_user ? $this->t('You are now using the %set_name shortcut set.', $replacements) : $this->t('%user is now using the %set_name shortcut set.', $replacements));
     }
     // Assign the shortcut set to the provided user account.
     $this->shortcutSetStorage->assignUser($set, $this->user);
 }