Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function save(array $form, array &$form_state)
 {
     foreach ($this->entity->getShortcuts() as $shortcut) {
         $shortcut->setWeight($form_state['values']['shortcuts']['links'][$shortcut->id()]['weight']);
         $shortcut->save();
     }
     drupal_set_message(t('The shortcut set has been updated.'));
 }
 /**
  * Returns a rendered edit form to create a new shortcut associated to the
  * given shortcut set.
  *
  * @param \Drupal\shortcut\ShortcutSetInterface $shortcut_set
  *   The shortcut set this shortcut will be added to.
  *
  * @return array
  *   The shortcut add form.
  */
 public function addForm(ShortcutSetInterface $shortcut_set)
 {
     $shortcut = $this->entityManager()->getStorage('shortcut')->create(array('shortcut_set' => $shortcut_set->id()));
     if ($this->moduleHandler()->moduleExists('language')) {
         $shortcut->langcode = language_get_default_langcode('shortcut', $shortcut_set->id());
     }
     return $this->entityFormBuilder()->getForm($shortcut, 'add');
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     foreach ($this->entity->getShortcuts() as $shortcut) {
         $weight = $form_state->getValue(array('shortcuts', 'links', $shortcut->id(), 'weight'));
         $shortcut->setWeight($weight);
         $shortcut->save();
     }
     drupal_set_message(t('The shortcut set has been updated.'));
 }
Esempio n. 4
0
 /**
  * Creates a new link in the provided shortcut set.
  *
  * @param \Drupal\shortcut\ShortcutSetInterface $shortcut_set
  *   The shortcut set to add a link to.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object.
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  *   A redirect response to the front page, or the previous location.
  *
  * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
  */
 public function addShortcutLinkInline(ShortcutSetInterface $shortcut_set, Request $request)
 {
     $link = $request->query->get('link');
     $name = $request->query->get('name');
     if (parse_url($link, PHP_URL_SCHEME) === NULL && $this->pathValidator->isValid($link)) {
         $shortcut = $this->entityManager()->getStorage('shortcut')->create(array('title' => $name, 'shortcut_set' => $shortcut_set->id(), 'link' => array('uri' => 'internal:/' . $link)));
         try {
             $shortcut->save();
             drupal_set_message($this->t('Added a shortcut for %title.', array('%title' => $shortcut->label())));
         } catch (\Exception $e) {
             drupal_set_message($this->t('Unable to add a shortcut for %title.', array('%title' => $shortcut->label())), 'error');
         }
         return $this->redirect('<front>');
     }
     throw new AccessDeniedHttpException();
 }
 /**
  * Creates a new link in the provided shortcut set.
  *
  * @param \Drupal\shortcut\ShortcutSetInterface $shortcut_set
  *   The shortcut set to add a link to.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object.
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  *   A redirect response to the front page, or the previous location.
  *
  * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
  */
 public function addShortcutLinkInline(ShortcutSetInterface $shortcut_set, Request $request)
 {
     $link = $request->query->get('link');
     $name = $request->query->get('name');
     if (shortcut_valid_link($link)) {
         $shortcut = $this->entityManager()->getStorage('shortcut')->create(array('title' => $name, 'shortcut_set' => $shortcut_set->id(), 'path' => $link));
         try {
             $shortcut->save();
             drupal_set_message($this->t('Added a shortcut for %title.', array('%title' => $shortcut->label())));
         } catch (\Exception $e) {
             drupal_set_message($this->t('Unable to add a shortcut for %title.', array('%title' => $shortcut->label())));
         }
         return $this->redirect('<front>');
     }
     throw new AccessDeniedHttpException();
 }
Esempio n. 6
0
 /**
  * {@inheritdoc}
  */
 public function countAssignedUsers(ShortcutSetInterface $shortcut_set)
 {
     return db_query('SELECT COUNT(*) FROM {shortcut_set_users} WHERE set_name = :name', array(':name' => $shortcut_set->id()))->fetchField();
 }
Esempio n. 7
0
 /**
  * Returns a form to add a new shortcut to a given set.
  *
  * @param \Drupal\shortcut\ShortcutSetInterface $shortcut_set
  *   The shortcut set this shortcut will be added to.
  *
  * @return array
  *   The shortcut add form.
  */
 public function addForm(ShortcutSetInterface $shortcut_set)
 {
     $shortcut = $this->entityManager()->getStorage('shortcut')->create(array('shortcut_set' => $shortcut_set->id()));
     return $this->entityFormBuilder()->getForm($shortcut, 'add');
 }
Esempio n. 8
0
 /**
  * Extracts information from shortcut set links.
  *
  * @param \Drupal\shortcut\ShortcutSetInterface $set
  *   The shortcut set object to extract information from.
  * @param string $key
  *   The array key indicating what information to extract from each link:
  *    - 'title': Extract shortcut titles.
  *    - 'path': Extract shortcut paths.
  *    - 'id': Extract the shortcut ID.
  *
  * @return array
  *   Array of the requested information from each link.
  */
 function getShortcutInformation(ShortcutSetInterface $set, $key)
 {
     $info = array();
     \Drupal::entityManager()->getStorage('shortcut')->resetCache();
     foreach ($set->getShortcuts() as $shortcut) {
         $info[] = $shortcut->{$key}->value;
     }
     return $info;
 }