uppdated modules
This commit is contained in:
+20
-1
@@ -1,12 +1,29 @@
|
||||
<?php
|
||||
|
||||
|
||||
class me_node_creation_CrumbsMonoPlugin implements crumbs_MonoPlugin {
|
||||
|
||||
/**
|
||||
* @param crumbs_InjectedAPI_describeMonoPlugin $api
|
||||
* Injected API object, with methods that allows the plugin to further
|
||||
* describe itself.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function describe($api) {
|
||||
$api->setTitle('Set breadcrumbs for placeholder pages.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Find candidates for the parent path.
|
||||
*
|
||||
* @param string $path
|
||||
* The path that we want to find a parent for.
|
||||
* @param array $item
|
||||
* Item as returned from crumbs_get_router_item()
|
||||
*
|
||||
* @return string
|
||||
* Parent path candidate.
|
||||
*/
|
||||
function findParent($path, $item) {
|
||||
switch ($item['route']) {
|
||||
case 'node/add/%/mlid/%':
|
||||
@@ -16,5 +33,7 @@ class me_node_creation_CrumbsMonoPlugin implements crumbs_MonoPlugin {
|
||||
// Let the menu.hierarchy.* plugin do its thing
|
||||
break;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
+12
-5
@@ -1,10 +1,14 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* Page callback for node/add/%node_type/mlid/%menu_editor_mlid
|
||||
*
|
||||
* @param object $type
|
||||
* @param array $menu_item
|
||||
*
|
||||
* @return array|mixed
|
||||
*/
|
||||
function me_node_creation_create_node($type, $menu_item) {
|
||||
function me_node_creation_create_node($type, array $menu_item) {
|
||||
global $user;
|
||||
|
||||
drupal_set_title(t('Create @name', array('@name' => $type->name)), PASS_THROUGH);
|
||||
@@ -24,8 +28,11 @@ function me_node_creation_create_node($type, $menu_item) {
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
||||
function _me_node_creation_form_alter(&$form, $node) {
|
||||
/**
|
||||
* @param array $form
|
||||
* @param object $node
|
||||
*/
|
||||
function _me_node_creation_form_alter(array &$form, $node) {
|
||||
$menu_item = $node->me_node_creation_menu_item;
|
||||
|
||||
unset($form['menu']);
|
||||
@@ -39,7 +46,7 @@ function _me_node_creation_form_alter(&$form, $node) {
|
||||
}
|
||||
|
||||
$txt = t('The created node will be associated with the chosen menu item (!mlid),<br/>with link title "@title"', array(
|
||||
'!mlid' => $mlid_text,
|
||||
'!mlid' => $mlid_text,
|
||||
'@title' => $menu_item['link_title'],
|
||||
));
|
||||
$txt = "<p>$txt</p>";
|
||||
|
||||
@@ -6,9 +6,9 @@ dependencies[] = menu_editor
|
||||
; xautoload for the crumbs plugin
|
||||
dependencies[] = xautoload
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-10-01
|
||||
version = "7.x-1.0-beta3+0-dev"
|
||||
; Information added by Drupal.org packaging script on 2016-11-06
|
||||
version = "7.x-1.0-beta4"
|
||||
core = "7.x"
|
||||
project = "menu_editor"
|
||||
datestamp = "1380586819"
|
||||
datestamp = "1478399941"
|
||||
|
||||
|
||||
+39
-19
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_permission()
|
||||
*/
|
||||
@@ -12,25 +11,31 @@ function me_node_creation_permission() {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_menu()
|
||||
*/
|
||||
function me_node_creation_menu() {
|
||||
$items = array();
|
||||
/* @see node_type_load() */
|
||||
/* @see menu_editor_menu_link_load() */
|
||||
$items['node/add/%node_type/mlid/%menu_editor_menu_link'] = array(
|
||||
'load arguments' => array(2, 4),
|
||||
'title' => 'Create a node',
|
||||
/* @see me_node_creation_create_node() */
|
||||
'page callback' => 'me_node_creation_create_node',
|
||||
'page arguments' => array(2, 4),
|
||||
'file' => 'me_node_creation.create.inc',
|
||||
/* @see me_node_creation_create_node_access() */
|
||||
'access callback' => 'me_node_creation_create_node_access',
|
||||
'access arguments' => array(2),
|
||||
);
|
||||
/* @see menu_editor_menu_link_load() */
|
||||
$items['mlid/%menu_editor_menu_link/under-construction'] = array(
|
||||
'title' => 'Under Construction',
|
||||
/* @see menu_editor_placeholder_title() */
|
||||
'title callback' => 'menu_editor_placeholder_title',
|
||||
'title arguments' => array(1),
|
||||
/* @see menu_editor_placeholder_page() */
|
||||
'page callback' => 'menu_editor_placeholder_page',
|
||||
'page arguments' => array(1),
|
||||
'file' => 'me_node_creation.placeholder.inc',
|
||||
@@ -40,11 +45,14 @@ function me_node_creation_menu() {
|
||||
return $items;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_form_alter()
|
||||
*
|
||||
* @param array $form
|
||||
* @param array $form_state
|
||||
* @param string $form_id
|
||||
*/
|
||||
function me_node_creation_form_alter(&$form, &$form_state, $form_id) {
|
||||
function me_node_creation_form_alter(array &$form, array &$form_state, $form_id) {
|
||||
if (empty($form['#node_edit_form']) || empty($form['#node'])) {
|
||||
return;
|
||||
}
|
||||
@@ -53,12 +61,14 @@ function me_node_creation_form_alter(&$form, &$form_state, $form_id) {
|
||||
return;
|
||||
}
|
||||
module_load_include('create.inc', 'me_node_creation');
|
||||
return _me_node_creation_form_alter($form, $node);
|
||||
form_load_include($form_state, 'inc', 'node', 'node.pages');
|
||||
_me_node_creation_form_alter($form, $node);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_node_insert()
|
||||
*
|
||||
* @param object $node
|
||||
*/
|
||||
function me_node_creation_node_insert($node) {
|
||||
$menu_item = @$node->me_node_creation_menu_item;
|
||||
@@ -77,9 +87,10 @@ function me_node_creation_node_insert($node) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_crumbs_plugins()
|
||||
*
|
||||
* @param crumbs_InjectedAPI_hookCrumbsPlugins $api
|
||||
*/
|
||||
function me_node_creation_crumbs_plugins($api) {
|
||||
$api->monoPlugin();
|
||||
@@ -89,12 +100,15 @@ function me_node_creation_crumbs_plugins($api) {
|
||||
// Wildcard loaders
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Wildcard loader for %menu_editor_menu_link
|
||||
* This is similar to menu_link_load(), but we do some loop prevention.
|
||||
*
|
||||
* TODO: Test if the by-reference does not explode in some edge cases.
|
||||
*
|
||||
* @param int $mlid
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function menu_editor_menu_link_load($mlid) {
|
||||
static $_cache = array();
|
||||
@@ -124,10 +138,9 @@ function menu_editor_menu_link_load($mlid) {
|
||||
// Title callbacks
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Title callback for mlid/%menu_link/under-construction
|
||||
*
|
||||
*
|
||||
* @param array $item
|
||||
* The menu link, as returned by menu_link_load()
|
||||
* @return string
|
||||
@@ -138,30 +151,38 @@ function menu_editor_placeholder_title($item) {
|
||||
return $item['link_title'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Title for menu links or tabs.
|
||||
* The page title can be different!
|
||||
*
|
||||
* @param $type_arg
|
||||
* @param $item
|
||||
*
|
||||
* @param string $type_arg
|
||||
* @param array|mixed $item
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @todo This is currently not in use anywhere, and not useful as-is.
|
||||
*/
|
||||
function me_node_creation_title($type_arg, $item) {
|
||||
// @todo This is a stupid way to get a node type label.
|
||||
foreach (node_type_get_types() as $type_name => $type_object) {
|
||||
if ($type_name == $type_arg) {
|
||||
if ($type_name === $type_arg) {
|
||||
// @todo This should use t() with @placeholder.
|
||||
return "New $type_object->name";
|
||||
}
|
||||
}
|
||||
return $type->name;
|
||||
return t('Create node of unknown type');
|
||||
}
|
||||
|
||||
|
||||
// Access callbacks
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Access callback for node/add/%node_type/mlid/%menu_editor_mlid
|
||||
*
|
||||
* @param object|mixed $type
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function me_node_creation_create_node_access($type) {
|
||||
if (!is_object($type)) {
|
||||
@@ -175,9 +196,8 @@ function me_node_creation_create_node_access($type) {
|
||||
// Utility
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @return string[]
|
||||
* Array of placeholders
|
||||
*/
|
||||
function me_node_creation_menu_editor_placeholders() {
|
||||
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* Page callback for mlid/%menu_link/under-construction
|
||||
*
|
||||
*
|
||||
* @param array $item
|
||||
* The menu link, as returned by menu_link_load()
|
||||
*
|
||||
* @return string
|
||||
* Rendered HTML
|
||||
* TODO: We could instead return a renderable array.
|
||||
|
||||
+3
-3
@@ -4,9 +4,9 @@ core = 7.x
|
||||
dependencies[] = menu_editor
|
||||
package = Menu
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-10-01
|
||||
version = "7.x-1.0-beta3+0-dev"
|
||||
; Information added by Drupal.org packaging script on 2016-11-06
|
||||
version = "7.x-1.0-beta4"
|
||||
core = "7.x"
|
||||
project = "menu_editor"
|
||||
datestamp = "1380586819"
|
||||
datestamp = "1478399941"
|
||||
|
||||
|
||||
+117
-49
@@ -3,7 +3,7 @@
|
||||
/**
|
||||
* @file
|
||||
* Find node paths on menu item creation via autocomplete.
|
||||
*
|
||||
*
|
||||
* This is a shameless clone of
|
||||
* http://drupal.org/project/mpac
|
||||
* by stBorchert
|
||||
@@ -12,7 +12,8 @@
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*
|
||||
* @return An array of menu items.
|
||||
* @return array
|
||||
* An array of menu items.
|
||||
*/
|
||||
function me_path_autocomplete_menu() {
|
||||
$items = array();
|
||||
@@ -20,6 +21,7 @@ function me_path_autocomplete_menu() {
|
||||
$items['mepac/autocomplete'] = array(
|
||||
'title' => 'Menu path autocomplete',
|
||||
'description' => 'Autocomplete callback for menu path autocomplete',
|
||||
/* @see me_path_autocomplete() */
|
||||
'page callback' => 'me_path_autocomplete',
|
||||
'access callback' => 'user_access',
|
||||
'access arguments' => array('access content'),
|
||||
@@ -30,76 +32,142 @@ function me_path_autocomplete_menu() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Find nodes and URL aliases based on title.
|
||||
* @param $string
|
||||
* Page callback for 'mepac/autocomplete'.
|
||||
*
|
||||
* Finds nodes and URL aliases based on title.
|
||||
* Sets a http header, and prints json output.
|
||||
*
|
||||
* @param string $string
|
||||
* Title of element to find.
|
||||
* @return
|
||||
* List of elements with path as key.
|
||||
*
|
||||
* @see mpac_autocomplete()
|
||||
*/
|
||||
function me_path_autocomplete($string = NULL) {
|
||||
$args = func_get_args();
|
||||
$string = implode('/', $args);
|
||||
$string = strtolower($string);
|
||||
$title = filter_xss_admin($string);
|
||||
$matches = array();
|
||||
// $matches[$string] = $string;
|
||||
|
||||
$matches = _me_path_autocomplete_get_matches($string);
|
||||
|
||||
drupal_json_output($matches);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
function _me_path_autocomplete_get_matches($string) {
|
||||
$string = strtolower($string);
|
||||
|
||||
// @todo Do we need to filter this?
|
||||
// See https://www.drupal.org/node/2785261 in mpac issue queue.
|
||||
# $title = filter_xss_admin($string);
|
||||
|
||||
$matches = _me_path_autocomplete_get_matches_for_placeholders($string);
|
||||
|
||||
if ($string === '') {
|
||||
return $matches;
|
||||
}
|
||||
|
||||
$like_placeholder = (strlen($string) > 3) ? "%" . db_like($string) . "%" : db_like($string) . "%";
|
||||
|
||||
$matches += _me_path_autocomplete_get_matches_for_nodes($like_placeholder);
|
||||
$matches += _me_path_autocomplete_get_matches_for_aliases($like_placeholder);
|
||||
|
||||
return $matches;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*
|
||||
* @return string[]
|
||||
*
|
||||
* @see _mpac_get_matches_for_nodes()
|
||||
*/
|
||||
function _me_path_autocomplete_get_matches_for_placeholders($string) {
|
||||
|
||||
$matches = array();
|
||||
/* @see hook_menu_editor_placeholders() */
|
||||
foreach (module_invoke_all('menu_editor_placeholders') as $placeholder_code => $placeholder_path) {
|
||||
if (!strlen($string) || count(explode($string, $placeholder_code)) > 1) {
|
||||
if ($string === '' || false !== strpos($placeholder_code, $string)) {
|
||||
$matches[$placeholder_code] = htmlentities($placeholder_code);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Get a list of all nodes where the title matches the given string.
|
||||
if (strlen($string) > 1) {
|
||||
$like_placeholder = (strlen($string) > 3) ? "%" . db_like($string) . "%" : db_like($string) . "%";
|
||||
$nodes = db_select('node', 'n')
|
||||
->fields('n')
|
||||
->condition('title', $like_placeholder, 'LIKE')
|
||||
->range(0, 8)
|
||||
->execute();
|
||||
return $matches;
|
||||
}
|
||||
|
||||
foreach ($nodes as $node) {
|
||||
// Add node path and title to list.
|
||||
if (node_access('view', $node) && $node->status) {
|
||||
$node_title = check_plain($node->title);
|
||||
$nid = $node->nid;
|
||||
$lang = $node->language != LANGUAGE_NONE ? ($node->language . ': ') : '';
|
||||
$matches['node/'. $node->nid] = $lang . "$node_title [nid:$nid]";
|
||||
}
|
||||
}
|
||||
if (module_exists('path')) {
|
||||
// Get a list of all URL aliases where the destination matches the given
|
||||
// string.
|
||||
$aliases = db_select('url_alias')
|
||||
->fields('url_alias')
|
||||
->condition('alias', $like_placeholder, 'LIKE')
|
||||
->range(0, 8)
|
||||
->execute();
|
||||
/**
|
||||
* @param string $like_placeholder
|
||||
*
|
||||
* @return string[]
|
||||
*
|
||||
* @see _mpac_get_matches_for_nodes()
|
||||
*/
|
||||
function _me_path_autocomplete_get_matches_for_nodes($like_placeholder) {
|
||||
|
||||
foreach ($aliases as $alias) {
|
||||
// Add alias source and destination to list (and add a special marker to
|
||||
// the item).
|
||||
$lang = $alias->language != LANGUAGE_NONE ? ($alias->language . ': ') : '';
|
||||
$src = check_plain($alias->source);
|
||||
$dst = check_plain($alias->alias);
|
||||
$matches[$alias->source] = $lang . "$dst | $src";
|
||||
}
|
||||
$q = db_select('node', 'n');
|
||||
$q->fields('n');
|
||||
$q->condition('title', $like_placeholder, 'LIKE');
|
||||
$q->range(0, 8);
|
||||
|
||||
$matches = array();
|
||||
foreach ($q->execute() as $node) {
|
||||
// Add node path and title to list.
|
||||
if (node_access('view', $node) && $node->status) {
|
||||
$node_title = check_plain($node->title);
|
||||
$nid = $node->nid;
|
||||
$lang = $node->language !== LANGUAGE_NONE ? ($node->language . ': ') : '';
|
||||
$matches['node/'. $node->nid] = $lang . "$node_title [nid:$nid]";
|
||||
}
|
||||
}
|
||||
|
||||
drupal_json_output($matches);
|
||||
|
||||
return $matches;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $like_placeholder
|
||||
*
|
||||
* @return string[]
|
||||
*
|
||||
* @see _mpac_get_matches_for_aliases()
|
||||
*/
|
||||
function _me_path_autocomplete_get_matches_for_aliases($like_placeholder) {
|
||||
|
||||
if (!module_exists('path')) {
|
||||
return array();
|
||||
}
|
||||
|
||||
// Get a list of all URL aliases where the destination matches the given
|
||||
// string.
|
||||
$q = db_select('url_alias');
|
||||
$q->fields('url_alias');
|
||||
$q->condition('alias', $like_placeholder, 'LIKE');
|
||||
$q->range(0, 8);
|
||||
|
||||
$matches = array();
|
||||
foreach ($q->execute() as $alias) {
|
||||
// Add alias source and destination to list (and add a special marker to
|
||||
// the item).
|
||||
$lang = $alias->language !== LANGUAGE_NONE ? ($alias->language . ': ') : '';
|
||||
$src = check_plain($alias->source);
|
||||
$dst = check_plain($alias->alias);
|
||||
$matches[$alias->source] = $lang . "$dst | $src";
|
||||
}
|
||||
|
||||
return $matches;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
*
|
||||
* Change path field to autocomplete field.
|
||||
*
|
||||
* @param array $form
|
||||
* @param array $form_state
|
||||
*/
|
||||
function me_path_autocomplete_form_menu_editor_overview_form_alter(&$form, &$form_state) {
|
||||
function me_path_autocomplete_form_menu_editor_overview_form_alter(array &$form, array &$form_state) {
|
||||
foreach (element_children($form) as $element_key) {
|
||||
$form[$element_key]['link_path']['#autocomplete_path'] = 'mepac/autocomplete';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,23 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* Form for editing an entire menu tree at once.
|
||||
*
|
||||
* Shows for one menu the menu items accessible to the current user and
|
||||
* relevant operations.
|
||||
*
|
||||
* @param array $form
|
||||
* @param array $form_state
|
||||
* @param array $menu
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @see menu_overview_form()
|
||||
* @see menu_edit_item()
|
||||
* @see menu_editor_overview_form_validate()
|
||||
* @see menu_editor_overview_form_submit()
|
||||
*/
|
||||
function menu_editor_overview_form($form, &$form_state, $menu) {
|
||||
global $menu_admin;
|
||||
function menu_editor_overview_form(array $form, array &$form_state, array $menu) {
|
||||
$form['#attached']['css'] = array(drupal_get_path('module', 'menu') . '/menu.css');
|
||||
$sql = "
|
||||
SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.delivery_callback, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.*
|
||||
@@ -24,9 +33,9 @@ function menu_editor_overview_form($form, &$form_state, $menu) {
|
||||
$node_links = array();
|
||||
menu_tree_collect_node_links($tree, $node_links);
|
||||
// We indicate that a menu administrator is running the menu access check.
|
||||
$menu_admin = TRUE;
|
||||
$GLOBALS['menu_admin'] = TRUE;
|
||||
menu_tree_check_access($tree, $node_links);
|
||||
$menu_admin = FALSE;
|
||||
$GLOBALS['menu_admin'] = FALSE;
|
||||
|
||||
$form = array('#tree' => TRUE);
|
||||
$form['#multilingual_menu'] = FALSE;
|
||||
@@ -34,12 +43,12 @@ function menu_editor_overview_form($form, &$form_state, $menu) {
|
||||
|
||||
$max_root_weight = _menu_editor_overview_tree_form($form, $form_state, $tree);
|
||||
|
||||
// default values for all new menu items..
|
||||
// default form values for all new menu items..
|
||||
$default_values = array(
|
||||
'link_title' => '',
|
||||
'link_path' => '<front>',
|
||||
'description' => '',
|
||||
'hidden' => true,
|
||||
'enabled' => true,
|
||||
'expanded' => false,
|
||||
'weight' => 0,
|
||||
// 'mlid' => NULL, // this is different for every single one
|
||||
@@ -53,19 +62,22 @@ function menu_editor_overview_form($form, &$form_state, $menu) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
for ($i=0; $i<8; ++$i) {
|
||||
for ($i = 0; $i < 8; ++$i) {
|
||||
// new menu item
|
||||
$default_values['mlid'] = 'new' . $i;
|
||||
$item_key = 'mlid-new'.$i;
|
||||
$form[$item_key] = _menu_editor_overview_tree_form_item('new'.$i, $default_values, $form['#multilingual_menu']);
|
||||
$item_key = 'mlid-new' . $i;
|
||||
$form[$item_key] = _menu_editor_overview_tree_form_item('new' . $i, $default_values, $form['#multilingual_menu']);
|
||||
$form[$item_key]['weight']['#default_value'] = $max_root_weight + $i + 1;
|
||||
$form[$item_key]['#item'] = array();
|
||||
$form[$item_key]['#item'] = array(
|
||||
'module' => 'menu',
|
||||
'hidden' => 0,
|
||||
'menu_name' => $menu['menu_name'],
|
||||
);
|
||||
$form[$item_key]['#attributes'] = array('class' => 'menu-new');
|
||||
$form[$item_key]['drag']['#markup'] = t('New menu item');
|
||||
}
|
||||
|
||||
$form['#menu'] = $menu;
|
||||
$form['#menu'] = $menu;
|
||||
if (element_children($form)) {
|
||||
$form['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
@@ -79,18 +91,25 @@ function menu_editor_overview_form($form, &$form_state, $menu) {
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Recursive helper function for menu_overview_form().
|
||||
*
|
||||
* @param array $form
|
||||
* @param array $form_state
|
||||
* @param array $tree
|
||||
*
|
||||
* @return int
|
||||
* The max root weight (whatever this means)
|
||||
*/
|
||||
function _menu_editor_overview_tree_form(&$form, &$form_state, $tree) {
|
||||
function _menu_editor_overview_tree_form(array &$form, array &$form_state, array $tree) {
|
||||
$max_root_weight = 0;
|
||||
foreach ($tree as $data) {
|
||||
$title = '';
|
||||
$item = $data['link'];
|
||||
// Don't show callbacks; these have $item['hidden'] < 0.
|
||||
if ($item && $item['hidden'] >= 0) {
|
||||
$item_key = 'mlid-'. $item['mlid'];
|
||||
$item_key = 'mlid-' . $item['mlid'];
|
||||
// @todo This is bogus. The value might be in $form_state['input'][$item_key], but never in $form_state[$item_key].
|
||||
$weight = isset($form_state[$item_key]['weight']) ? $form_state[$item_key]['weight'] : $item['weight'];
|
||||
$plid = isset($form_state[$item_key]['plid']) ? $form_state[$item_key]['plid'] : $item['plid'];
|
||||
|
||||
@@ -101,24 +120,30 @@ function _menu_editor_overview_tree_form(&$form, &$form_state, $tree) {
|
||||
$path = $item['link_path'];
|
||||
if (!empty($item['options']['query'])) {
|
||||
if (is_array($item['options']['query'])) {
|
||||
$path .= '?'. drupal_http_build_query($item['options']['query']);
|
||||
$path .= '?' . drupal_http_build_query($item['options']['query']);
|
||||
}
|
||||
else {
|
||||
// Query could be a string, due to a malfunction in previous versions of this module.
|
||||
$path .= '?'. $item['options']['query'];
|
||||
$path .= '?' . $item['options']['query'];
|
||||
}
|
||||
}
|
||||
if (isset($item['options']['fragment'])) {
|
||||
$path .= '#'. $item['options']['fragment'];
|
||||
$path .= '#' . $item['options']['fragment'];
|
||||
}
|
||||
|
||||
/* @see menu_firstchild_form_alter() */
|
||||
if (isset($item['href']) && '<firstchild>' === $item['href']) {
|
||||
$item['hidden'] = !empty($item['options']['unaltered_hidden']);
|
||||
}
|
||||
|
||||
$default_values = array(
|
||||
'link_title' => $item['link_title'],
|
||||
'link_path' => $path,
|
||||
'description' => isset($item['options']['attributes']['title']) ? $item['options']['attributes']['title'] : '',
|
||||
'hidden' => !$item['hidden'],
|
||||
'enabled' => !$item['hidden'],
|
||||
'expanded' => $item['expanded'],
|
||||
'weight' => $weight,
|
||||
'plid' => $plid,
|
||||
'weight' => $weight,
|
||||
'plid' => $plid,
|
||||
'depth' => 1,
|
||||
);
|
||||
|
||||
@@ -180,7 +205,7 @@ function _menu_editor_overview_tree_form(&$form, &$form_state, $tree) {
|
||||
}
|
||||
|
||||
// Only items created by the menu module can be deleted.
|
||||
if ($item['module'] == 'menu' || $item['updated'] == 1) {
|
||||
if ($item['module'] === 'menu' || (string)$item['updated'] === '1') {
|
||||
$form[$item_key]['delete'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('delete'),
|
||||
@@ -191,17 +216,23 @@ function _menu_editor_overview_tree_form(&$form, &$form_state, $tree) {
|
||||
|
||||
// process child elements
|
||||
if ($data['below']) {
|
||||
_menu_editor_overview_tree_form($form, $form_data, $data['below']);
|
||||
_menu_editor_overview_tree_form($form, $form_state, $data['below']);
|
||||
}
|
||||
}
|
||||
return $max_root_weight;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int|string $item_mlid
|
||||
* @param array $default_values
|
||||
* @param bool $multilingual_menu
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function _menu_editor_overview_tree_form_item($item_mlid, $default_values, $multilingual_menu = FALSE) {
|
||||
|
||||
foreach (menu_editor_get_placeholders() as $code => $path) {
|
||||
if (str_replace('@mlid', $item_mlid, $path) == $default_values['link_path']) {
|
||||
if (str_replace('@mlid', $item_mlid, $path) === $default_values['link_path']) {
|
||||
$default_values['link_path'] = $code;
|
||||
}
|
||||
}
|
||||
@@ -210,10 +241,12 @@ function _menu_editor_overview_tree_form_item($item_mlid, $default_values, $mult
|
||||
$element['link_title'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#size' => 25,
|
||||
'#maxlength' => 128,
|
||||
);
|
||||
$element['link_path'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#size' => 25,
|
||||
'#maxlength' => 255,
|
||||
);
|
||||
$element['description'] = array(
|
||||
'#type' => 'textarea',
|
||||
@@ -221,7 +254,7 @@ function _menu_editor_overview_tree_form_item($item_mlid, $default_values, $mult
|
||||
'#rows' => 1,
|
||||
'#resizable' => FALSE,
|
||||
);
|
||||
$element['hidden'] = array(
|
||||
$element['enabled'] = array(
|
||||
'#type' => 'checkbox',
|
||||
);
|
||||
$element['expanded'] = array(
|
||||
@@ -255,22 +288,31 @@ function _menu_editor_overview_tree_form_item($item_mlid, $default_values, $mult
|
||||
return $element;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Weight textfield validation function
|
||||
* Stolen from http://drupal.org/project/tiny_menu_editor
|
||||
* Big thanks to Dmitriy.trt
|
||||
*
|
||||
* @param array $element
|
||||
* @param array $form_state
|
||||
*/
|
||||
function _menu_editor_valid_weight($element, &$form_state) {
|
||||
function _menu_editor_valid_weight(array $element, array &$form_state) {
|
||||
if ((isset($element['#value']) && $element['#value'] !== '') || !empty($element['#required'])) {
|
||||
if (!preg_match('/^\-?\d+$/', $element['#value'])) {
|
||||
form_error($element, t('Weight has to be an integer value.'));
|
||||
form_error($element, t('Weight has to be an integer value.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function menu_editor_overview_form_validate($form, &$form_state) {
|
||||
/**
|
||||
* Form validation callback for menu_editor_overview_form.
|
||||
*
|
||||
* @param array $form
|
||||
* @param array $form_state
|
||||
*
|
||||
* @see menu_editor_overview_form()
|
||||
*/
|
||||
function menu_editor_overview_form_validate(array $form, array &$form_state) {
|
||||
$form_values = &$form_state['values'];
|
||||
|
||||
// Check existing items.
|
||||
@@ -295,11 +337,14 @@ function menu_editor_overview_form_validate($form, &$form_state) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validate form values for a menu link being added or edited.
|
||||
*
|
||||
* @param array $element
|
||||
* @param string $link_path
|
||||
* @param string $error_key_prefix
|
||||
*/
|
||||
function menu_editor_validate_item(&$element, $link_path, $error_key_prefix) {
|
||||
function menu_editor_validate_item(array &$element, $link_path, $error_key_prefix) {
|
||||
$placeholders = menu_editor_get_placeholders();
|
||||
if (isset($placeholders[$link_path])) {
|
||||
// it would be hard to check access,
|
||||
@@ -308,7 +353,7 @@ function menu_editor_validate_item(&$element, $link_path, $error_key_prefix) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($element['link_path']['#default_value'] == $link_path) {
|
||||
if ($element['link_path']['#default_value'] === $link_path) {
|
||||
// link_path is the only field that we check,
|
||||
// and we don't complain about existing link paths.
|
||||
return;
|
||||
@@ -334,27 +379,32 @@ function menu_editor_validate_item(&$element, $link_path, $error_key_prefix) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* validate a menu item that was dynamically added through javascript
|
||||
*
|
||||
* @param unknown_type $item
|
||||
* Validates a menu item that was dynamically added through javascript.
|
||||
*
|
||||
* @param array|mixed $item
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function menu_editor_overview_form_validate_new_item($item) {
|
||||
// TODO: add some sanity checks
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Submit handler for the menu overview form.
|
||||
*
|
||||
* This function takes great care in saving parent items first, then items
|
||||
* underneath them. Saving items in the incorrect order can break the menu tree.
|
||||
*
|
||||
* @see menu_overview_form()
|
||||
* @param array $form
|
||||
* @param array $form_state
|
||||
*
|
||||
* @see menu_editor_overview_form()
|
||||
* @see menu_overview_form_submit()
|
||||
* @see menu_edit_item_submit()
|
||||
*/
|
||||
function menu_editor_overview_form_submit($form, &$form_state) {
|
||||
function menu_editor_overview_form_submit(array $form, array &$form_state) {
|
||||
|
||||
// When dealing with saving menu items, the order in which these items are
|
||||
// saved is critical. If a changed child item is saved before its parent,
|
||||
@@ -373,7 +423,9 @@ function menu_editor_overview_form_submit($form, &$form_state) {
|
||||
foreach ($form_values as $item_key => $v) {
|
||||
if (isset($form[$item_key]['#item'])) {
|
||||
$element = $form[$item_key];
|
||||
if (!is_numeric($v['mlid'])) {
|
||||
$original_item = $item = $element['#item'];
|
||||
|
||||
if (!isset($item['mlid'])) {
|
||||
// add new item
|
||||
unset($v['mlid']);
|
||||
if (!is_string($v['link_title']) || empty($v['link_title'])) {
|
||||
@@ -382,42 +434,51 @@ function menu_editor_overview_form_submit($form, &$form_state) {
|
||||
if (!is_string($v['link_path']) || empty($v['link_path'])) {
|
||||
continue;
|
||||
}
|
||||
$element['#item']['menu_name'] = $menu_name;
|
||||
$item['menu_name'] = $menu_name;
|
||||
// Set all fields in this menu item.
|
||||
foreach ($fields as $field) {
|
||||
// Check if field is set since some fields could not be NULL when
|
||||
// Check if field is set since some fields could not be NULL when
|
||||
// doing menu_link_save().
|
||||
if (isset($v[$field])) {
|
||||
$element['#item'][$field] = $v[$field];
|
||||
$item[$field] = $v[$field];
|
||||
}
|
||||
}
|
||||
$updated_items[$item_key] = $element['#item'];
|
||||
} else if (!empty($v['delete'])) {
|
||||
$updated_items[$item_key] = $item;
|
||||
}
|
||||
elseif (!empty($v['delete'])) {
|
||||
// delete existing item
|
||||
if (is_numeric($v['mlid'])) {
|
||||
menu_link_delete($v['mlid']);
|
||||
if (is_numeric($item['mlid'])) {
|
||||
menu_link_delete($item['mlid']);
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// update existing item
|
||||
// Update any fields that have changed in this menu item.
|
||||
foreach ($fields as $field) {
|
||||
// Using != instead of !== to support '5' == 5.
|
||||
/** @noinspection TypeUnsafeComparisonInspection */
|
||||
if ($v[$field] != $element[$field]['#default_value']) {
|
||||
$element['#item'][$field] = $v[$field];
|
||||
$updated_items[$item_key] = $element['#item'];
|
||||
$item[$field] = $v[$field];
|
||||
$updated_items[$item_key] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Hidden is a special case, the value needs to be inverted.
|
||||
// Besides, while we operate with boolean, the database wants numeric 0/1.
|
||||
if ($v['hidden'] xor $element['hidden']['#default_value']) {
|
||||
$element['#item']['hidden'] = empty($v['hidden']) ? 1 : 0;
|
||||
if ($v['enabled'] xor $element['enabled']['#default_value']) {
|
||||
// Checkbox for 'enabled' was changed.
|
||||
$element['#item']['hidden'] = empty($v['enabled']) ? 1 : 0;
|
||||
$updated_items[$item_key] = $element['#item'];
|
||||
}
|
||||
else {
|
||||
// Checkbox for 'enabled' was not changed.
|
||||
}
|
||||
// langcode is a special case as well
|
||||
if (!empty($form['#multilingual_menu'])) {
|
||||
$langcode = isset($element['language']['#default_value']) ? $element['language']['#default_value'] : $element['language']['#value'];
|
||||
if ($v['language'] != $langcode) {
|
||||
if ($v['language'] !== $langcode) {
|
||||
$element['#item']['language'] = $v['language'];
|
||||
$updated_items[$item_key] = $element['#item'];
|
||||
}
|
||||
@@ -477,7 +538,7 @@ function menu_editor_overview_form_submit($form, &$form_state) {
|
||||
unset($item['options']['fragment']);
|
||||
}
|
||||
|
||||
if ($link_path != $parsed_link['path']) {
|
||||
if ($link_path !== $parsed_link['path']) {
|
||||
$link_path = $parsed_link['path'];
|
||||
}
|
||||
}
|
||||
@@ -497,6 +558,12 @@ function menu_editor_overview_form_submit($form, &$form_state) {
|
||||
}
|
||||
}
|
||||
|
||||
// @see menu_firstchild_menu_link_alter() expects $link['module'] to be set.
|
||||
$item += array(
|
||||
'module' => 'menu',
|
||||
'hidden' => 0,
|
||||
);
|
||||
|
||||
$mlid = menu_link_save($item);
|
||||
|
||||
if (is_numeric($mlid)) {
|
||||
@@ -519,18 +586,18 @@ function menu_editor_overview_form_submit($form, &$form_state) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Theme the menu overview form into a table.
|
||||
*
|
||||
* @param array $variables
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_menu_editor_overview_form($variables) {
|
||||
function theme_menu_editor_overview_form(array $variables) {
|
||||
$form = $variables['form'];
|
||||
drupal_add_css(drupal_get_path('module', 'menu_editor') .'/menu_editor.css');
|
||||
drupal_add_css(drupal_get_path('module', 'menu_editor') . '/menu_editor.css');
|
||||
drupal_add_js(drupal_get_path('module', 'menu_editor') . '/menu_editor.js');
|
||||
global $language;
|
||||
$i18n_menu = $form['#multilingual_menu'] || $form['#translatable_nodes'];
|
||||
@@ -548,13 +615,13 @@ function theme_menu_editor_overview_form($variables) {
|
||||
if ($i18n_menu) {
|
||||
$header[] = t('Language');
|
||||
}
|
||||
$header[] = array('data' => t('Delete'), 'class' => 'delete-checkbox');
|
||||
$header[] = array('data' => t('Delete'), 'class' => 'delete-checkbox');
|
||||
|
||||
$rows = array();
|
||||
$items = array();
|
||||
|
||||
foreach (element_children($form) as $item_key) {
|
||||
if (isset($form[$item_key]['hidden'])) {
|
||||
if (isset($form[$item_key]['enabled'])) {
|
||||
$element = &$form[$item_key];
|
||||
|
||||
// Add special classes to be used for tabledrag.js.
|
||||
@@ -566,7 +633,7 @@ function theme_menu_editor_overview_form($variables) {
|
||||
$element['plid']['#type'] = 'hidden';
|
||||
|
||||
// Adjust tab index to allow vertical tabbing
|
||||
foreach (array('link_title', 'link_path', 'description', 'hidden', 'expanded') as $i => $key) {
|
||||
foreach (array('link_title', 'link_path', 'description', 'enabled', 'expanded') as $i => $key) {
|
||||
$element[$key]['#attributes']['tabindex'] = $i+2;
|
||||
}
|
||||
$element['link_path']['#attributes']['tabindex'] = 2;
|
||||
@@ -581,7 +648,7 @@ function theme_menu_editor_overview_form($variables) {
|
||||
$cells['link_title'] = array('data' => drupal_render($element['link_title']), 'class' => 'title-edit');
|
||||
$cells['link_path'] = array('data' => drupal_render($element['link_path']), 'class' => 'path-edit');
|
||||
$cells['description'] = array('data' => drupal_render($element['description']), 'class' => 'description');
|
||||
$cells['hidden'] = array('data' => drupal_render($element['hidden']), 'class' => 'checkbox');
|
||||
$cells['enabled'] = array('data' => drupal_render($element['enabled']), 'class' => 'checkbox');
|
||||
$cells['expanded'] = array('data' => drupal_render($element['expanded']), 'class' => 'checkbox');
|
||||
$cells['mlid'] = drupal_render($element['weight']) . drupal_render($element['plid']) . drupal_render($element['mlid']);
|
||||
if ($i18n_menu) {
|
||||
@@ -598,8 +665,8 @@ function theme_menu_editor_overview_form($variables) {
|
||||
$row['class'] = array('draggable');
|
||||
if ($i18n_menu) {
|
||||
$langcode = isset($element['language']['#default_value']) ? $element['language']['#default_value'] : $element['language']['#value'];
|
||||
$row['class'][] = ($langcode != LANGUAGE_NONE) ? 'langcode-'.$langcode : 'all-languages';
|
||||
$row['class'][]= ($langcode == $language->language) ? 'active-language' : '';
|
||||
$row['class'][] = ($langcode !== LANGUAGE_NONE) ? 'langcode-'.$langcode : 'all-languages';
|
||||
$row['class'][]= ($langcode === $language->language) ? 'active-language' : '';
|
||||
}
|
||||
$rows[$item_key] = $row;
|
||||
}
|
||||
@@ -611,4 +678,3 @@ function theme_menu_editor_overview_form($variables) {
|
||||
$output .= drupal_render_children($form);
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
function hook_menu_editor_placeholders() {
|
||||
return array(
|
||||
'<new>' => 'mlid/@mlid/under-construction',
|
||||
);
|
||||
}
|
||||
@@ -53,4 +53,3 @@ form#menu-editor-overview-form .focus-description-column tr.focus td.description
|
||||
form#menu-editor-overview-form .focus-description-column tr.focus td.description textarea {
|
||||
height:60px !important;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,9 @@ package = Menu
|
||||
core = 7.x
|
||||
dependencies[] = menu
|
||||
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-10-01
|
||||
version = "7.x-1.0-beta3+0-dev"
|
||||
; Information added by Drupal.org packaging script on 2016-11-06
|
||||
version = "7.x-1.0-beta4"
|
||||
core = "7.x"
|
||||
project = "menu_editor"
|
||||
datestamp = "1380586819"
|
||||
datestamp = "1478399941"
|
||||
|
||||
|
||||
@@ -2,31 +2,31 @@
|
||||
Drupal.behaviors.menuEditor = {
|
||||
attach: function (context, settings) {
|
||||
$('#menu-editor-overview-form #menu-overview', context).each(function(){
|
||||
|
||||
|
||||
// table elements
|
||||
var table = $(this);
|
||||
var tbody = $('tbody', this);
|
||||
|
||||
|
||||
// delete all checkbox
|
||||
(function(){
|
||||
var th_delete = $('thead th.delete-checkbox', table);
|
||||
var master_delete_checkbox = $('<input type="checkbox" class="master-delete-checkbox" />');
|
||||
th_delete.html('<span> '+th_delete.html()+'</span>');
|
||||
th_delete.prepend(master_delete_checkbox);
|
||||
|
||||
|
||||
var onchange = function(){
|
||||
var checked_now = master_delete_checkbox.attr('checked');
|
||||
$('tbody td.delete-checkbox :checkbox', table).attr('checked', checked_now);
|
||||
};
|
||||
|
||||
|
||||
master_delete_checkbox.change(onchange);
|
||||
|
||||
|
||||
// IE does not trigger the change event..
|
||||
if ($.browser.msie) {
|
||||
master_delete_checkbox.click(onchange);
|
||||
}
|
||||
})();
|
||||
|
||||
|
||||
// freeze width of first column (currently disabled)
|
||||
if (false) {
|
||||
var w = $('td.drag', this).width();
|
||||
@@ -34,7 +34,7 @@
|
||||
$(this).css('width', w+'px');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// get reference css for textareas
|
||||
var ref_input = $('td.path-edit input', this);
|
||||
var h = ref_input.height();
|
||||
@@ -44,12 +44,12 @@
|
||||
'padding-bottom': ref_input.css('padding-bottom')
|
||||
};
|
||||
var div_ref_height = ref_input.parent().height();
|
||||
|
||||
|
||||
// adjust height of existing description textareas
|
||||
$('td.description textarea', this).css(ref_css);
|
||||
// this is necessary because of the vertical-align:middle
|
||||
$('td.description div.form-item', this).css('height', div_ref_height+'px');
|
||||
|
||||
|
||||
// description column resizing
|
||||
$('td.description textarea', this).focus(function(){
|
||||
table.addClass('focus-description-column');
|
||||
|
||||
@@ -33,6 +33,11 @@ function menu_editor_permission() {
|
||||
return $perm;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $menu
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function menu_editor_form_access($menu) {
|
||||
return
|
||||
user_access('administer menu') ||
|
||||
@@ -55,7 +60,9 @@ function menu_editor_form_access($menu) {
|
||||
// }
|
||||
|
||||
/**
|
||||
* Implemenation of hook_theme().
|
||||
* Implements hook_theme().
|
||||
*
|
||||
* @return array[]
|
||||
*/
|
||||
function menu_editor_theme() {
|
||||
return array(
|
||||
@@ -68,21 +75,33 @@ function menu_editor_theme() {
|
||||
|
||||
/**
|
||||
* Title callback for the menu overview page and links.
|
||||
*
|
||||
* @param array $menu
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function menu_editor_overview_title($menu) {
|
||||
function menu_editor_overview_title(array $menu) {
|
||||
return $menu['title'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
function menu_editor_get_placeholders() {
|
||||
static $placeholders;
|
||||
if (!isset($placeholders)) {
|
||||
/* @see hook_menu_editor_placeholders() */
|
||||
$placeholders = module_invoke_all('menu_editor_placeholders');
|
||||
}
|
||||
return $placeholders;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $placeholder
|
||||
* @param string|int $mlid
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function menu_editor_get_path_for_placeholder($placeholder, $mlid) {
|
||||
$placeholders = menu_editor_get_placeholders();
|
||||
if (isset($placeholders[$placeholder])) {
|
||||
|
||||
Reference in New Issue
Block a user