diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Form/SetCustomize.php b/core/modules/shortcut/lib/Drupal/shortcut/Form/SetCustomize.php new file mode 100644 index 0000000..dca16bb --- /dev/null +++ b/core/modules/shortcut/lib/Drupal/shortcut/Form/SetCustomize.php @@ -0,0 +1,102 @@ +id(); + $form['shortcuts'] = array( + '#tree' => TRUE, + '#weight' => -20, + 'links' => array(), + ); + + foreach ($shortcut->links as $uuid => $link) { + $mlid = $link['mlid']; + $form['shortcuts']['links'][$mlid]['name']['#markup'] = l($link['link_title'], $link['link_path']); + $form['shortcuts']['links'][$mlid]['weight'] = array( + '#type' => 'weight', + '#title' => t('Weight for @title', array('@title' => $link['link_title'])), + '#title_display' => 'invisible', + '#delta' => 50, + '#default_value' => $link['weight'], + '#attributes' => array('class' => array('shortcut-weight')), + ); + + $links['edit'] = array( + 'title' => t('Edit'), + 'href' => "admin/config/user-interface/shortcut/link/$mlid", + ); + $links['delete'] = array( + 'title' => t('Delete'), + 'href' => "admin/config/user-interface/shortcut/link/$mlid/delete", + ); + $form['shortcuts']['links'][$mlid]['operations'] = array( + '#type' => 'operations', + '#links' => $links, + ); + } + + $form['actions'] = array( + '#type' => 'actions', + '#access' => !empty($shortcut_set->links), + ); + $form['actions']['submit'] = array( + '#type' => 'submit', + '#value' => t('Save changes'), + ); + + return $form; + } + + /** + * {@inheritdoc} + */ + public function validateform(array &$form, array &$form_state) { + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + } + +} diff --git a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutAccessController.php b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutAccessController.php index b527b1f..46aeadd 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/ShortcutAccessController.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/ShortcutAccessController.php @@ -20,12 +20,31 @@ class ShortcutAccessController extends EntityAccessController { * {@inheritdoc} */ protected function checkAccess(EntityInterface $entity, $operation, $langcode, User $account) { - if ($operation == 'delete') { - if (!user_access('administer shortcuts', $account)) { + switch ($operation) { + case 'delete': + if (!user_access('administer shortcuts', $account)) { + return FALSE; + } + return $entity->id() != 'default'; + break; + + case 'customize': + // Sufficiently-privileged users can edit their currently displayed shortcut + // set, but not other sets. Shortcut administrators can edit any set. + if (user_access('administer shortcuts')) { + return TRUE; + } + if (user_access('customize shortcut links')) { + print_r($entity == shortcut_current_displayed_set()); + return !isset($entity) || $entity == shortcut_current_displayed_set(); + } + return FALSE; + break; + + default: return FALSE; - } - return $entity->id() != 'default'; } + } } diff --git a/core/modules/shortcut/shortcut.module b/core/modules/shortcut/shortcut.module index db3373b..685f5ec 100644 --- a/core/modules/shortcut/shortcut.module +++ b/core/modules/shortcut/shortcut.module @@ -77,13 +77,7 @@ function shortcut_menu() { ); $items['admin/config/user-interface/shortcut/manage/%shortcut_set'] = array( 'title' => 'Edit shortcuts', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('shortcut_set_customize', 5), - 'title callback' => 'entity_page_label', - 'title arguments' => array(5), - 'access callback' => 'shortcut_set_edit_access', - 'access arguments' => array(5), - 'file' => 'shortcut.admin.inc', + 'route_name' => 'shortcut_set_customize', ); $items['admin/config/user-interface/shortcut/manage/%shortcut_set/links'] = array( 'title' => 'List links', diff --git a/core/modules/shortcut/shortcut.routing.yml b/core/modules/shortcut/shortcut.routing.yml index 277853f..ae6cf19 100644 --- a/core/modules/shortcut/shortcut.routing.yml +++ b/core/modules/shortcut/shortcut.routing.yml @@ -11,3 +11,11 @@ shortcut_set_delete: _form: 'Drupal\shortcut\Form\SetDelete' requirements: _entity_access: 'shortcut.delete' + +shortcut_set_customize: + pattern: '/admin/config/user-interface/shortcut/manage/{shortcut}' + defaults: + _form: 'Drupal\shortcut\Form\SetCustomize' + requirements: + _entity_access: 'shortcut.customize' +