diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Access/LinkEditAccessCheck.php b/core/modules/shortcut/lib/Drupal/shortcut/Access/LinkEditAccessCheck.php new file mode 100644 index 0000000..4677716 --- /dev/null +++ b/core/modules/shortcut/lib/Drupal/shortcut/Access/LinkEditAccessCheck.php @@ -0,0 +1,38 @@ +getRequirements()); + } + + /** + * {@inheritdoc} + */ + public function access(Route $route, Request $request) { + if ($menu_link = $request->attributes->get('menu_link')) { + $set_name = str_replace('shortcut-', '', $menu_link['menu_name']); + if ($shortcut_set = shortcut_set_load($set_name)) { + return shortcut_set_edit_access($shortcut_set); + } + } + } + +} \ No newline at end of file diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Form/Elements.php b/core/modules/shortcut/lib/Drupal/shortcut/Form/Elements.php new file mode 100644 index 0000000..83e55ac --- /dev/null +++ b/core/modules/shortcut/lib/Drupal/shortcut/Form/Elements.php @@ -0,0 +1,69 @@ +menu_link = $entityManager + ->getStorageController('menu_link') + ->create(array( + 'link_title' => '', + 'link_path' => '', + )); + } + else { + $this->menu_link = $menu_link; + $this->menu_link['link_path'] = ($menu_link['link_path'] == '') ? '' : drupal_container()->get('path.alias_manager')->getPathAlias($menu_link['link_path']); + } + } + + /** + * Give form elements + */ + public function giveFormElements() { + $form['shortcut_link']['#tree'] = TRUE; + $form['shortcut_link']['link_title'] = array( + '#type' => 'textfield', + '#title' => t('Name'), + '#size' => 40, + '#maxlength' => 255, + '#default_value' => $this->menu_link['link_title'], + '#required' => TRUE, + ); + + $form['shortcut_link']['link_path'] = array( + '#type' => 'textfield', + '#title' => t('Path'), + '#size' => 40, + '#maxlength' => 255, + '#field_prefix' => url(NULL, array('absolute' => TRUE)), + '#default_value' => $this->menu_link['link_path'], + ); + + $form['actions'] = array('#type' => 'actions'); + $form['actions']['submit'] = array( + '#type' => 'submit', + '#value' => t('Save'), + ); + + return $form; + } +} \ No newline at end of file diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Form/LinkEdit.php b/core/modules/shortcut/lib/Drupal/shortcut/Form/LinkEdit.php new file mode 100644 index 0000000..80e8afd --- /dev/null +++ b/core/modules/shortcut/lib/Drupal/shortcut/Form/LinkEdit.php @@ -0,0 +1,123 @@ +entityManager = $entity_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('plugin.manager.entity') + ); + } + + /** + * Returns a unique string identifying the form. + * + * @return string + * The unique string identifying the form. + */ + public function getFormID() { + return 'shortcut_link_edit'; + } + + /** + * Form constructor. + * + * @param array $form + * An associative array containing the structure of the form. + * @param array $form_state + * An associative array containing the current state of the form. + * + * @return array + * The form structure. + */ + public function buildForm(array $form, array &$form_state, MenuLink $menu_link = NULL, Request $request = NULL) { + $this->menuLink = $menu_link; + drupal_set_title(t('Editing @shortcut', array('@shortcut' => $this->menuLink['link_title']))); + $form['original_shortcut_link'] = array( + '#type' => 'value', + '#value' => $this->menuLink, + ); + $elements = new Elements($this->menuLink, $this->entityManager); + $form += $elements->giveFormElements(); + return $form; + } + + /** + * Form validation handler. + * + * @param array $form + * An associative array containing the structure of the form. + * @param array $form_state + * An associative array containing the current state of the form. + */ + public function validateForm(array &$form, array &$form_state){ + if (!shortcut_valid_link($form_state['values']['shortcut_link']['link_path'])) { + form_set_error('shortcut_link][link_path', t('The link must correspond to a valid path on the site.')); + } + } + + /** + * Form submission handler. + * + * @param array $form + * An associative array containing the structure of the form. + * @param array $form_state + * An associative array containing the current state of the form. + */ + public function submitForm(array &$form, array &$form_state){ + // Normalize the path in case it is an alias. + $shortcut_path = \Drupal::service('path.alias_manager')->getSystemPath($form_state['values']['shortcut_link']['link_path']); + if (empty($shortcut_path)) { + $shortcut_path = ''; + } + $form_state['values']['shortcut_link']['link_path'] = $shortcut_path; + + $shortcut_link = $form_state['values']['original_shortcut_link']; + foreach ($form_state['values']['shortcut_link'] as $key => $value) { + $shortcut_link[$key] = $value; + } + + $shortcut_link->save(); + $set_name = str_replace('shortcut-', '' , $shortcut_link['menu_name']); + $form_state['redirect'] = 'admin/config/user-interface/shortcut/manage/' . $set_name; + drupal_set_message(t('The shortcut %link has been updated.', array('%link' => $shortcut_link['link_title']))); + } +} \ No newline at end of file