Commit e4c2a578 authored by webchick's avatar webchick
Browse files

Issue #934714 by swentel, caiovlp, Coornail: Fixed Cannot add frontpage as shortcut.

parent bea70831
...@@ -35,6 +35,7 @@ function testShortcutLinkAdd() { ...@@ -35,6 +35,7 @@ function testShortcutLinkAdd() {
// Create some paths to test. // Create some paths to test.
$test_cases = array( $test_cases = array(
array('path' => ''),
array('path' => 'admin'), array('path' => 'admin'),
array('path' => 'admin/config/system/site-information'), array('path' => 'admin/config/system/site-information'),
array('path' => "node/{$this->node->nid}/edit"), array('path' => "node/{$this->node->nid}/edit"),
...@@ -52,7 +53,8 @@ function testShortcutLinkAdd() { ...@@ -52,7 +53,8 @@ function testShortcutLinkAdd() {
$this->assertResponse(200); $this->assertResponse(200);
$saved_set = shortcut_set_load($set->set_name); $saved_set = shortcut_set_load($set->set_name);
$paths = $this->getShortcutInformation($saved_set, 'link_path'); $paths = $this->getShortcutInformation($saved_set, 'link_path');
$this->assertTrue(in_array(drupal_get_normal_path($test['path']), $paths), 'Shortcut created: '. $test['path']); $test_path = empty($test['path']) ? '<front>' : $test['path'];
$this->assertTrue(in_array(drupal_get_normal_path($test_path), $paths), 'Shortcut created: '. $test['path']);
$this->assertLink($title, 0, 'Shortcut link found on the page.'); $this->assertLink($title, 0, 'Shortcut link found on the page.');
} }
} }
......
...@@ -409,7 +409,7 @@ function _shortcut_link_form_elements($shortcut_link = NULL) { ...@@ -409,7 +409,7 @@ function _shortcut_link_form_elements($shortcut_link = NULL) {
); );
} }
else { else {
$shortcut_link['link_path'] = drupal_get_path_alias($shortcut_link['link_path']); $shortcut_link['link_path'] = ($shortcut_link['link_path'] == '<front>') ? '' : drupal_get_path_alias($shortcut_link['link_path']);
} }
$form['shortcut_link']['#tree'] = TRUE; $form['shortcut_link']['#tree'] = TRUE;
...@@ -456,7 +456,11 @@ function shortcut_link_edit_validate($form, &$form_state) { ...@@ -456,7 +456,11 @@ function shortcut_link_edit_validate($form, &$form_state) {
*/ */
function shortcut_link_edit_submit($form, &$form_state) { function shortcut_link_edit_submit($form, &$form_state) {
// Normalize the path in case it is an alias. // Normalize the path in case it is an alias.
$form_state['values']['shortcut_link']['link_path'] = drupal_get_normal_path($form_state['values']['shortcut_link']['link_path']); $shortcut_path = drupal_get_normal_path($form_state['values']['shortcut_link']['link_path']);
if (empty($shortcut_path)) {
$shortcut_path = '<front>';
}
$form_state['values']['shortcut_link']['link_path'] = $shortcut_path;
$shortcut_link = array_merge($form_state['values']['original_shortcut_link'], $form_state['values']['shortcut_link']); $shortcut_link = array_merge($form_state['values']['original_shortcut_link'], $form_state['values']['shortcut_link']);
...@@ -493,6 +497,9 @@ function shortcut_link_add_submit($form, &$form_state) { ...@@ -493,6 +497,9 @@ function shortcut_link_add_submit($form, &$form_state) {
function shortcut_admin_add_link($shortcut_link, &$shortcut_set) { function shortcut_admin_add_link($shortcut_link, &$shortcut_set) {
// Normalize the path in case it is an alias. // Normalize the path in case it is an alias.
$shortcut_link['link_path'] = drupal_get_normal_path($shortcut_link['link_path']); $shortcut_link['link_path'] = drupal_get_normal_path($shortcut_link['link_path']);
if (empty($shortcut_link['link_path'])) {
$shortcut_link['link_path'] = '<front>';
}
// Add the link to the end of the list. // Add the link to the end of the list.
$shortcut_set->links[] = $shortcut_link; $shortcut_set->links[] = $shortcut_link;
......
...@@ -620,8 +620,8 @@ function shortcut_valid_link($path) { ...@@ -620,8 +620,8 @@ function shortcut_valid_link($path) {
if ($path != $normal_path) { if ($path != $normal_path) {
$path = $normal_path; $path = $normal_path;
} }
// Only accept links that correspond to valid paths on the site itself. // An empty path is valid too and will be converted to <front>.
return !url_is_external($path) && menu_get_item($path); return (!url_is_external($path) && menu_get_item($path)) || empty($path) || $path == '<front>';
} }
/** /**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment