Exemple #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}
  */
 protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL)
 {
     if ($shortcut_set = $this->shortcutSetStorage->load($entity_bundle)) {
         return shortcut_set_edit_access($shortcut_set, $account);
     }
     // @todo Fix this bizarre code: how can a shortcut exist without a shortcut
     // set? The above if-test is unnecessary. See https://www.drupal.org/node/2339903.
     return AccessResult::neutral();
 }
 /**
  * {@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);
 }
 /**
  * {@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);
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     // Find out how many users are directly assigned to this shortcut set, and
     // make a message.
     $number = $this->storage->countAssignedUsers($this->entity);
     $info = '';
     if ($number) {
         $info .= '<p>' . format_plural($number, '1 user has chosen or been assigned to this shortcut set.', '@count users have chosen or been assigned to this shortcut set.') . '</p>';
     }
     // Also, if a module implements hook_shortcut_default_set(), it's possible
     // that this set is being used as a default set. Add a message about that too.
     if ($this->moduleHandler->getImplementations('shortcut_default_set')) {
         $info .= '<p>' . t('If you have chosen this shortcut set as the default for some or all users, they may also be affected by deleting it.') . '</p>';
     }
     $form['info'] = array('#markup' => $info);
     return parent::buildForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL)
 {
     if ($shortcut_set = $this->shortcutSetStorage->load($entity_bundle)) {
         return shortcut_set_edit_access($shortcut_set, $account);
     }
 }