/**
  * 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. 2
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, array &$form_state)
 {
     $form = parent::form($form, $form_state);
     $form['shortcuts'] = array('#tree' => TRUE, '#weight' => -20);
     $form['shortcuts']['links'] = array('#type' => 'table', '#header' => array(t('Name'), t('Weight'), t('Operations')), '#empty' => $this->t('No shortcuts available. <a href="@link">Add a shortcut</a>', array('@link' => $this->url('shortcut.link_add', array('shortcut_set' => $this->entity->id())))), '#attributes' => array('id' => 'shortcuts'), '#tabledrag' => array(array('action' => 'order', 'relationship' => 'sibling', 'group' => 'shortcut-weight')));
     foreach ($this->entity->getShortcuts() as $shortcut) {
         $id = $shortcut->id();
         $form['shortcuts']['links'][$id]['#attributes']['class'][] = 'draggable';
         $form['shortcuts']['links'][$id]['name']['#markup'] = l($shortcut->getTitle(), $shortcut->path->value);
         $form['shortcuts']['links'][$id]['#weight'] = $shortcut->getWeight();
         $form['shortcuts']['links'][$id]['weight'] = array('#type' => 'weight', '#title' => t('Weight for @title', array('@title' => $shortcut->getTitle())), '#title_display' => 'invisible', '#default_value' => $shortcut->getWeight(), '#attributes' => array('class' => array('shortcut-weight')));
         $links['edit'] = array('title' => t('Edit'), 'href' => "admin/config/user-interface/shortcut/link/{$id}");
         $links['delete'] = array('title' => t('Delete'), 'href' => "admin/config/user-interface/shortcut/link/{$id}/delete");
         $form['shortcuts']['links'][$id]['operations'] = array('#type' => 'operations', '#links' => $links);
     }
     // Sort the list so the output is ordered by weight.
     uasort($form['shortcuts']['links'], array('\\Drupal\\Component\\Utility\\SortArray', 'sortByWeightProperty'));
     return $form;
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $form['shortcuts'] = array('#tree' => TRUE, '#weight' => -20);
     $form['shortcuts']['links'] = array('#type' => 'table', '#header' => array(t('Name'), t('Weight'), t('Operations')), '#empty' => $this->t('No shortcuts available. <a href=":link">Add a shortcut</a>', array(':link' => $this->url('shortcut.link_add', array('shortcut_set' => $this->entity->id())))), '#attributes' => array('id' => 'shortcuts'), '#tabledrag' => array(array('action' => 'order', 'relationship' => 'sibling', 'group' => 'shortcut-weight')));
     foreach ($this->entity->getShortcuts() as $shortcut) {
         $id = $shortcut->id();
         $url = $shortcut->getUrl();
         if (!$url->access()) {
             continue;
         }
         $form['shortcuts']['links'][$id]['#attributes']['class'][] = 'draggable';
         $form['shortcuts']['links'][$id]['name'] = array('#type' => 'link', '#title' => $shortcut->getTitle()) + $url->toRenderArray();
         unset($form['shortcuts']['links'][$id]['name']['#access_callback']);
         $form['shortcuts']['links'][$id]['#weight'] = $shortcut->getWeight();
         $form['shortcuts']['links'][$id]['weight'] = array('#type' => 'weight', '#title' => t('Weight for @title', array('@title' => $shortcut->getTitle())), '#title_display' => 'invisible', '#default_value' => $shortcut->getWeight(), '#attributes' => array('class' => array('shortcut-weight')));
         $links['edit'] = array('title' => t('Edit'), 'url' => $shortcut->urlInfo());
         $links['delete'] = array('title' => t('Delete'), 'url' => $shortcut->urlInfo('delete-form'));
         $form['shortcuts']['links'][$id]['operations'] = array('#type' => 'operations', '#links' => $links, '#access' => $url->access());
     }
     return $form;
 }
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');
 }