initial commit of starter install drupal 7

This commit is contained in:
Bachir Soussi Chiadmi
2015-02-21 17:21:40 +01:00
commit eeba51cea6
6113 changed files with 1249218 additions and 0 deletions
@@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
@@ -0,0 +1,54 @@
Content menu module rewires Drupal's default menu management interface for tighter intergation of content authoring and menu management.
The goal is to make building a site's structure and content in one fluid process seamless, easy and natural. Editors can create content along with a menu item without ever really leaving the menu management process. Editors can find, associate and edit content right from the menu management interface.
Content Menu module makes building a structure-oriented website "page by page" with Drupal effortless and intuitive.
To get an impression of how easy content centric menu management is with the content menu module, watch our screencast: http://youtu.be/sYoYtoQ1s8c
HOW IT WORKS
Basically, Content Menu evolves Drupal's simplistic and isolated menu management interface into an editor's intuitive central for site authoring.
The most important new possibilties are to directly asses and edit a menu item's linked content and to directly create and position a new menu item with selectable target (content) type.
You can create a new menu item as …
URL With the traditional menu item form
Dummy As a dummy menu item (with simple dummy link target)
New NODETYPE directly create a new content for the new item
Existing content selecting an existing content via a nice filterable view (if views is enabled)
Menu position rule (if the Menu Position module is enabled)
IMPROVED WORKFLOWS
The workflows are kept concise and seamless, e.g for adding new menu items along with brand new content or with comfortably choosing existing content to link to.
HOW TO INSTALL
To install Content Menu module, …
* Download and enable the module from http://drupal.org/project/content_menu
* Download additional modules
CTools and Views modules are strongly recommended (though technically not required)
Menu Position module is supported (and great for rule based appearance of content in menus)
* Configure your permissions and content types:
Make sure at least one content type is configured in Drupal's standard node type configuration form to be enabled to receive menu entries of the menu(s) where the content should be placed, to make at least one node type show up in the "target type" dropdown.
Make sure the user you try the module with has sufficient permission (to access admin area, to administer menus, to administer content, to create and delete nodes of the respective type, …). The new "administer system menus" is necessary for users that should see _all_ menus on the menu overview admin page (Users without this permission are not shown the content_menu_special_menus (variable details see below)).
* Go to Admin > Structure > Menus and start adding menu items into e.g the "Main Menu".
* Or watch out Screencast (see above) to get ideas of what to do (and how).
* See the content_menu.api.php file for further development information on new permission(s), system variables you can override, or hooks you might want to use as a developer to extend content_menu.module
RESSOURCES
* Screencast: http://youtu.be/sYoYtoQ1s8c
* Blog Post with background-info and discussion: http://wunderkraut.com/en/blog/content-menu-module-%E2%80%93-menu-author...
* content_menu.api.php file for further development information.
Content Menu is sponsored by http://www.wunderkraut.com
@@ -0,0 +1,82 @@
<?php
/**
*
* PERMISSIONS introduced by this module:
*
* administer system menus
* Allows a user to show/list _all_ menus on the menu overview admin page.
* Users without this permission are not shown the content_menu_special_menus
* (variable details see below).
*
*
*
* SYSTEM VARIABLES of this module that can be changed:
* (There's currently no config interface to set them, but you can do that
* manually or programmatically)
*
* content_menu_add_existing_content_url
* URL of the "select existing content" page to use when creating a new menu
* item that is linking to "existing content".
*
* content_menu_add_existing_content_view
* VIEWNAME[:DISPLAYNAME] of the view (if any) that should be used
* when creating a new menu item that is linking to "existing content".
* An "nid" field of this field based view[/display] is changed to be used as
* "select" link to select existing content for the new menu item to link to.
*
* content_menu_special_menus
* Array of menu machine names that are considered special/system menus, and
* are hence not altered by content_menu, and not shown to users without the
* new 'administer system menus' permission.
* Default: array('management', 'user-menu', 'navigation', 'devel'));
*
* content_menu_alter_all_menus
* Boolean flag to state whether all menus should be altered to have to
* improved interface, including those listed in the variable
* content_menu_special_menus.
* Default: FALSE (to let system menus be untouched, 'just in case').
*
*
*/
/**
* Extend the target types for a new menu item.
*
* @param $target_types Array
* Array of menu item target types that you can extend.
* The key is a machine name of a target type (alphanumerical char, _)
* The value is an array containing the following entries:
* - label => translated label to display in the interface
* - handler => full name of a handler function to use, with the signature
* ...(&$form, &$form_state, &$item [, $arg_1, ..., $arg_n])
* - arguments => array of arg_name=>arg_value (optional),
* each argument is passed to handler callback function.
* - clean_menu_save_message => flag whether the existing message
* "Your configuration has been saved"
* should be removed (TRUE) or not (FALSE).
*
* @param $context Array
* Array with context information. Currently the following key is used:
* 'menu_name' => machine name of the menu the target types are assembled.
*
*/
function hook_menu_item_target_types_alter(&$target_types, &$context) {
$target_types['url'] = array(
'label' => t('URL'),
'handler' => 'content_menu_menu_form_handler_url',
'clean_menu_save_message' => TRUE
);
}
/**
* Alter a menu item's form element in the menu item administration.
*
* @param $el Array The form element of the menu item to alter.
*/
function _content_menu_menu_item_element_alter(&$el) {
module_load_include('inc', 'content_menu', 'content_menu.menu_admin');
_content_menu_menu_item_element_alter($el);
}
@@ -0,0 +1,13 @@
name = "Content Menu"
dependencies[] = "menu"
description = "Content centric menu management interface for editors."
package = User interface
core = "7.x"
php = "5.2.4"
; Information added by Drupal.org packaging script on 2014-08-01
version = "7.x-1.0+7-dev"
core = "7.x"
project = "content_menu"
datestamp = "1406871528"
@@ -0,0 +1,25 @@
<?php
/**
* @file
* Installation hooks for Content Menu module
*/
/**
* Implements hook_install().
*/
function content_menu_install() {
// Set weight to come after core menu.module.
// Make sure this module's hooks' weight is set to be executed after the core.
// Menu.module's hooks, so the node add/edit form is already altered by the.
// Menu.module befor content_menu does its form alterations.
$weight = db_select('system', 's')
->fields('s', array('weight'))
->condition('name', 'menu', '=')
->execute()
->fetchField();
db_update('system')
->fields(array('weight' => $weight + 1))
->condition('name', 'content_menu', '=')
->execute();
}
@@ -0,0 +1,13 @@
(function($){
Drupal.behaviors.content_menu ={
attach:function(context, settings){
// Show menu item title input field when clicking on the trigger.
$('.menu-overview-title-edit-trigger', context).click(function(e) {
$(this).siblings('.form-type-textfield').show().children('input').focus();
$(this).siblings('.menu-overview-title-link').hide();
$(this).hide();
e.stopPropagation();
e.stopImmediatePropagation();
});
}
};})(jQuery);
@@ -0,0 +1,770 @@
<?php
/**
* @file
* Menu Management Workflow improvements.
*/
/**
* Callback for altered admin/structure/menu router item.
*
* Only show custom menus to regular sitebuilders/editors (no system menus).
*/
function _content_menu_menu_overview_page_extended() {
$result = db_query("SELECT * FROM {menu_custom} ORDER BY title", array(), array('fetch' => PDO::FETCH_ASSOC));
$header = array(t('Title'), array('data' => t('Operations'), 'colspan' => '1'));
$rows = array();
foreach ($result as $menu) {
if (content_menu_is_menu_considered($menu['menu_name']) || user_access('administer system menus')) {
$url = 'admin/structure/menu/manage/' . $menu['menu_name'];
$row = array(theme('menu_admin_overview', array('title' => $menu['title'], 'name' => $menu['menu_name'], 'description' => $menu['description'])));
$row[] = array('data' => l(t('Edit'), $url));
$rows[] = $row;
}
}
return theme('table', array('header' => $header, 'rows' => $rows));
}
/**
* Actual implementation for content_menu_form_menu_overview_form_alter().
*
* Overhaul the menu_overview_form to improve menu authoring experience.
*/
function _content_menu_form_menu_overview_form_alter(&$form, &$form_state, $form_id) {
$form['#theme'][0] = 'menu_overview_form_extended';
// Check whether any filtering element should be acitvated.
$filtering_active = TRUE;
// Filtering depends on ctools module.
// @todo Remove ctools dependency as ajax is actually not used.
$filtering_active = $filtering_active && module_exists('ctools');
if ($filtering_active) {
// Add form elements for filters.
// @todo Add configuration interface for filters.
require_once 'filters/content_menu_domain_filter.php';
require_once 'filters/content_menu_language_filter.php';
$filters = array(new content_menu_domain_filter(), new content_menu_language_filter($form['#menu']['menu_name']));
// Add filter widgets to form.
foreach ($filters as $f) {
$f->addFilterWidget($form, $form_state, $form_id);
}
}
// ToDo: Clean up and untangle operations-changing and target_content setting.
$hidden = array();
// Adjust operations for each item.
foreach (element_children($form) as $mlid) {
$el = &$form[$mlid];
if ($filtering_active) {
foreach ($filters as $f) {
if ($f->hideElement($el)) {
unset($form[$mlid]);
$hidden[$el['#item']['mlid']] = $el['#item']['mlid'];
continue;
}
}
}
if (isset($el['#item']['plid']) &&
isset($hidden[$el['#item']['plid']])) {
// Check if a parent has been disabled before.
// If so, the childern will be hidden too.
unset($form[$mlid]);
$hidden[$el['#item']['mlid']] = $el['#item']['mlid'];
continue;
}
$el['#inline_edit_title'] = TRUE;
if (isset($form[$mlid]['operations'])) {
// Invoke hook to let modules provide target operations for new item.
drupal_alter('menu_item_element', $el);
// Make sure that operations are ordered by their weight, then unset it.
uasort($el['operations'], 'drupal_sort_weight');
foreach ($el['operations'] as $el_op_key => $el_op) {
unset($el['operations'][$el_op_key]['weight']);
}
// Wrap link-type operations into CTools dropbutton, if available.
if (module_exists('ctools') && isset($el['operations'])) {
// Split up operation in dropbutton-ops and other ops.
$other_operations = array();
$dropbutton_operations = array();
foreach ($form[$mlid]['operations'] as $op_key => $op_item) {
if (is_array($op_item) && isset($op_item['#type'])) {
if ($op_item['#type'] == 'link') {
$dropbutton_operations[$op_key] = array(
'title' => $op_item['#title'],
'href' => $op_item['#href'],
);
if (isset($op_item['#options'])) {
$dropbutton_operations[$op_key] += $op_item['#options'];
}
}
else {
$other_operations[$op_key] = $op_item;
}
}
}
// Compose operation from dropbutton and other ops.
$el['operations'] = array();
$el['operations']['dropbutton_operations'] = array(
'#theme' => 'links__ctools_dropbutton',
'#links' => $dropbutton_operations,
);
$el['operations'] += $other_operations;
}
// Count operations of this item.
$el['#operations_count'] = count($form[$mlid]['operations']);
}
// Add inline-editing for menu item title.
if ($el['#inline_edit_title'] && isset($el['title'])) {
// ToDo: Check title inplace-edit for multilanguage compatibility issues.
$title = $el['#item']['title'];
$el['title'] = array(
'#type' => 'textfield',
'#default_value' => $title,
'#size' => 30,
'#maxlength' => 255,
'#prefix' => '<span class="menu-overview-title-link">' . $el['title']['#markup'] . '</span>',
'#suffix' => '<a href="javascript:void();" title="Click to edit title" class="menu-overview-title-edit-trigger">' . t('edit title') . '</a>',
);
$form['#attached']['js'] = array(drupal_get_path('module', 'content_menu') . '/content_menu.js');
}
}
// Add "add item" item/row/elements.
content_menu_form_menu_overview_form_alter_additem($form);
// Add css as via drupal_add_css and put it after ctools button css files.
drupal_add_css(drupal_get_path('module', 'content_menu') . "/css/content_menu.css", array('weight' => 2));
// Change submit handler function to our own implementation.
$form['#submit'] = array('content_menu_menu_overview_form_submit_extended');
// Prevent 'destination' from hijacking our submit.
unset($_GET['destination']);
if (!isset($form['actions'])) {
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
}
$form['actions']['submit']['#value'] = t('Save');
}
/**
* Menu item element alterations provided by default by this module.
*
* This helper function is called by this module's hook_menu_item_element_alter
* implementation content_menu_menu_item_element_alter().
*
* @param $el Array The form element of the menu item to alter.
*/
function _content_menu_menu_item_element_alter(&$el) {
$el_item = &$el['#item'];
$el_ops = &$el['operations'];
$target_content = '';
$link_path = ($el_item['link_path'] == '<front>') ? variable_get('site_frontpage', 'node') : $el_item['link_path'];
$link_path = (array) explode('/', $link_path);
$link_path = array_pad($link_path, 2, '');
// Change "edit" operation.
if (isset($el_ops['edit']) && ($el_ops['edit']['#type'] == 'link')) {
$el_ops['edit']['weight'] = 1;
// Add "select content" operation.
$selectcontenturl = content_menu_variable_get_add_existing_content_url();
if ($selectcontenturl) {
$el_ops['selectcontent'] = array(
'#type' => 'link',
'weight' => 2,
'#title' => t('select content'),
'#href' => $selectcontenturl,
'#options' => array(
'query' => content_menu_assemble_query_string($el_item),
),
);
}
// Add "new <node-type>" operation to Dummies.
if ($link_path[0] == 'menu-dummy') {
$node_type_count = 0;
foreach (node_type_get_types() as $node_type) {
$type = $node_type->type;
if (user_access('create ' . $type . ' content')) {
$node_menu_options = variable_get('menu_options_' . $type, array('main-menu' => 'main-menu'));
if (in_array($el_item['menu_name'], $node_menu_options)) {
$el_ops['new_' . $type] = array(
'#type' => 'link',
'weight' => 10 + $node_type_count,
'#title' => t('New @type', array('@type' => t($node_type->name))),
'#href' => 'node/add/' . str_replace("_", "-", $type),
'#options' => array(
'query' => content_menu_assemble_query_string($el_item),
),
);
}
}
}
}
// Add "configure" operation by cloning "edit" operation.
$el_ops['configure'] = $el_ops['edit'];
$el_ops['configure']['#title'] = t('configure item');
$el_ops['configure']['weight'] = 3;
// Change "edit" operation to ...
// ... do nothing for menu item dummies.
if ($link_path[0] == 'menu-dummy') {
$target_content = t('Placeholder');
}
// ... lead to node edit form for node-url-items.
elseif (($link_path[0] == 'node') && (is_numeric($link_path[1]))) {
$node = node_load($link_path[1]);
if (is_object($node)) {
if (node_access('update', $node)) {
$el_ops['edit']['#href'] = 'node/' . $link_path[1] . '/edit';
}
$node_type = node_type_get_type($node);
$target_content = t($node_type->name);
// Mark unpublished nodes.
if (!$node->status) {
$target_content = '<span class="menu-item-content-target-unpublished">' . $target_content . '</span>';
}
}
}
// ... lead to panel page edit form for panel paged.
elseif (($el_item['page_callback'] == 'page_manager_page_execute')) {
if (user_access('use page manager')) {
$page_arguments = unserialize($el_item['page_arguments']);
$el_ops['edit']['#href'] = 'admin/structure/pages/edit/page-' . implode('/', $page_arguments);
}
$target_content = t('Panel');
}
// ... lead to view edit form for views.
elseif ($el_item['page_callback'] == 'views_page') {
if (user_access('administer views')) {
$page_arguments = unserialize($el_item['page_arguments']);
$el_ops['edit']['#href'] = 'admin/structure/views/view/' . $page_arguments[0] . '/edit/' . $page_arguments[1];
}
$el_ops['selectcontent']['#href'] = CONTENT_MENU_ADD_EXISTING_VIEW_URL;
$el_ops['selectcontent']['#title'] = t('select view');
$target_content = t('View');
}
// ... menu position rule.
elseif ($link_path[0] == 'menu-position') {
if (!user_access('administer menu positions')) {
$el_ops['configure'] = $el_ops['edit'] = array();
}
$target_content = t('Menu rule');
$el['#inline_edit_title'] = FALSE;
}
else {
// If no other content or target is identifier, assume generic URL.
if (url_is_external($el_item['link_path'])) {
// External.
$target_content = t('URL');
}
else {
// Internal.
$target_content = t('Path');
}
}
// Delete the "edit" operation altogether if its url didn't change.
if (isset($el_ops['edit']['#href'])) {
if ($el_ops['edit']['#href'] == $el_ops['configure']['#href']) {
$el_ops['edit'] = array();
$el_ops['selectcontent']['weight'] = 4;
}
else {
$el_ops['edit']['#title'] = t('edit content');
$el_ops['edit']['#options']['query']['destination'] = current_path();
}
}
}
else {
$el_ops['edit'] = array();
}
// Add "delete" operation for menu_position items.
if (!isset($el_ops['delete']) && ($link_path[0] == 'menu-position') && (is_numeric($link_path[1]) && user_access('administer menu positions'))) {
$el_ops['delete'] = array(
'#type' => 'link',
'#title' => t('delete'),
'#href' => 'admin/structure/menu-position/delete/' . intval($link_path[1]),
'#options' => array('query' => array('destination' => current_path())),
);
}
// Push "delete" operation to end of ops list.
if (isset($el_ops['delete'])) {
$el_ops['delete']['#title'] = t('delete item');
$el_ops['delete']['weight'] = 100;
}
$el['target_content'] = array('#type' => 'markup', '#markup' => $target_content);
}
/**
* Add item/row/elements to menu overview form for "add item" functionality.
*/
function content_menu_form_menu_overview_form_alter_additem(&$form) {
// Assemble and add the "Add link" item.
$form['additem'] = array(
'#attributes' => array(
'class' => array('menu-additem'),
),
'hidden' => array(
'#type' => 'checkbox',
'#title' => t('Enable the new menu link'),
'#title_display' => 'invisible',
'#default_value' => TRUE,
),
'weight' => array(
'#type' => 'weight',
// '#delta' has to be in sync with:
// a) CONTENT_MENU_ADD_ITEM_WEIGHT.
// b) Delta set in menu_form_node_form_alter().
'#delta' => 50,
// Real weight is set in content_menu_menu_overview_form_submit_extended.
'#default_value' => CONTENT_MENU_ADD_ITEM_WEIGHT,
'#title_display' => 'invisible',
'#title' => 'Weight',
),
'mlid' => array(
'#type' => 'hidden',
'#value' => '0',
),
'plid' => array(
'#type' => 'hidden',
'#default_value' => '0',
),
'operations' => array(),
'#operations_count' => 0,
'title' => array(
'#type' => 'textfield',
'#title' => t('New menu item'),
'#default_value' => '',
'#size' => 30,
'#maxlength' => 255,
'#required' => FALSE,
),
);
$target_types = content_menu_get_target_types($form['#menu']['menu_name']);
// Retrieve possible add-"type"-operations for "Add link" item.
foreach ($target_types as $op_key => $op_info) {
$target_types[$op_key] = $op_info['label'];
}
// Build "type" select for "Add link" item.
$form['additem']['target_content'] = array(
'#type' => 'select',
'#title' => '&nbsp;',
'#options' => $target_types,
'#default_value' => variable_get('content_menu_default_add_operation', 'url'),
);
}
/**
* Returns HTML for the menu overview form into a table.
*
* Code taken mainly from original theme_menu_overview_form().
*
* @param $variables
* An associative array containing:
* - form: A render element representing the form.
*
* @ingroup themeable
*/
function theme_menu_overview_form_extended($variables) {
$form = $variables['form'];
drupal_add_tabledrag('menu-overview', 'match', 'parent', 'menu-plid', 'menu-plid', 'menu-mlid', TRUE, MENU_MAX_DEPTH - 1);
drupal_add_tabledrag('menu-overview', 'order', 'sibling', 'menu-weight');
// Count max number of operations per item.
$operations_count_max = 1;
foreach (element_children($form) as $mlid) {
if (isset($form[$mlid]['#operations_count'])) {
$operations_count_max = max($operations_count_max, $form[$mlid]['#operations_count']);
}
}
$header = array(
t('Menu link'),
array('data' => t('Enabled'), 'class' => array('checkbox')),
t('Weight'),
t('Target'),
array('data' => t('Operations'), 'colspan' => $operations_count_max),
);
// Build item tables.
$rows = array();
foreach (element_children($form) as $mlid) {
if (isset($form[$mlid]['hidden'])) {
$element = &$form[$mlid];
// Build a list of operations.
$operations = array();
foreach (element_children($element['operations']) as $op) {
$operations[] = array('data' => drupal_render($element['operations'][$op]), 'class' => array('menu-operations'));
}
while (count($operations) < $operations_count_max) {
$operations[] = '';
}
// Add special classes to be used for tabledrag.js.
$element['plid']['#attributes']['class'] = array('menu-plid');
$element['mlid']['#attributes']['class'] = array('menu-mlid');
$element['weight']['#attributes']['class'] = array('menu-weight');
// Change the parent field to a hidden.
// This allows any value but hides the field.
$element['plid']['#type'] = 'hidden';
$depth = isset($element['#item']) ? $element['#item']['depth'] : 1;
$row = array();
$row[] = theme('indentation', array('size' => $depth - 1)) . drupal_render($element['title']);
$row[] = array('data' => drupal_render($element['hidden']), 'class' => array('checkbox', 'menu-enabled'));
$row[] = drupal_render($element['weight']) . drupal_render($element['plid']) . drupal_render($element['mlid']);
$row[] = array('data' => drupal_render($element['target_content']), 'class' => array('menu-target-content'));
$row = array_merge($row, $operations);
$row = array_merge(array('data' => $row), $element['#attributes']);
$row['class'][] = 'draggable';
// Highlight row if menu item has been created within the last minute.
if (isset($element['#item']['mlid']) && isset($_SESSION['content_menu_inserted_links'][$element['#item']['mlid']])) {
if ((time() - $_SESSION['content_menu_inserted_links'][$element['#item']['mlid']]['created']) <= 60) {
$row['class'][] = 'ok';
}
unset($_SESSION['content_menu_inserted_links'][$element['#item']['mlid']]);
}
$rows[] = $row;
}
}
$output = '';
if (empty($rows)) {
$rows[] = array(array('data' => $form['#empty_text'], 'colspan' => '7'));
}
// Render selection filter widgets on top.
if (isset($form['#content_menu_filter_widget'])) {
foreach ($form['#content_menu_filter_widget'] as $widgetname) {
$output .= drupal_render($form[$widgetname]);
}
}
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'menu-overview')));
$output .= drupal_render_children($form);
return $output;
}
/**
* Submit handler for menu_overview_form extended with item adding handling.
*/
function content_menu_menu_overview_form_submit_extended($form, &$form_state) {
// Edit item handling.
$max_weight = 0;
// Step though items.
foreach (element_children($form) as $mlid) {
$el = &$form[$mlid];
// Keep track of maximum weight.
if (isset($el['#item']['weight']) && ($el['#item']['weight'] > $max_weight)) {
$max_weight = $el['#item']['weight'];
}
// If title changed, ...
if (isset($el['#item']) && isset($el['title']['#value'])) {
if ($el['title']['#value'] != $el['title']['#default_value']) {
// Inject item title.
$title = $form_state['input'][$mlid]['title'];
$el['#item']['title'] = $el['#item']['link_title'] = $title;
// Change default value of weight field to trigger
// menu_overview_form_submit() marking the item as updated.
$el['weight']['#default_value'] += 1;
}
}
}
// Do standard menu.module's item processing.
menu_overview_form_submit($form, $form_state);
// Add item handling.
$item = $form_state['input']['additem'];
// If title has been entered for new menu item, prepare add operation.
if (trim($item['title'] != '')) {
// Complete data for new menu item.
$item['link_title'] = $item['title'];
$item['name'] = $form['#menu']['menu_name'];
$item['hidden'] = $item['hidden'] ? 0 : 1;
$item['customized'] = 1;
if ($item['weight'] == CONTENT_MENU_ADD_ITEM_WEIGHT) {
$item['weight'] = $max_weight + 1;
}
// Determine operation details.
$operations = content_menu_get_target_types($item['name']);
$op = $operations[$item['target_content']];
// Prepare arguments for handler callback function.
$args = array('form' => $form, 'form_state' => $form_state, 'item' => $item);
if (isset($op['arguments']) && is_array($op['arguments'])) {
$args += $op['arguments'];
}
// Call handler callback function.
if (function_exists($op['handler'])) {
// Get rid of the 'Your configuration has been saved.' message.
if ($op['clean_menu_save_message']) {
foreach ($_SESSION['messages']['status'] as $msg_key => $msg_text) {
if ($_SESSION['messages']['status'][$msg_key] == t('Your configuration has been saved.')) {
unset($_SESSION['messages']['status'][$msg_key]);
}
}
}
$result = call_user_func_array($op['handler'], $args);
}
}
}
/**
* Menu add item operation handler for a new dummy menu item.
*/
function content_menu_menu_form_handler_dummy($form, $form_state, $item) {
drupal_set_message(t('A new menu item has been created.'));
$item['link_path'] = 'menu-dummy';
content_menu_link_save($item);
}
/**
* Menu add item operation handler for a new node menu item.
*/
function content_menu_menu_form_handler_node($form, $form_state, $item, $type) {
$types = node_type_get_types();
drupal_set_message(t("You're about to create a new menu item with new %type content.", array('%type' => $types[$type]->name)));
drupal_set_message(t('Complete the process by filling out and saving the form below.'));
$type = str_replace("_", "-", $type);
drupal_goto('node/add/' . $type, array('query' => content_menu_assemble_query_string($item)));
}
/**
* Menu add item operation handler for a new generic menu item.
*/
function content_menu_menu_form_handler_url($form, $form_state, $item) {
drupal_set_message(t("You're about to create a new generic menu item linking to a URL path."));
drupal_set_message(t('Complete the process by filling out and saving the form below.'));
drupal_goto('admin/structure/menu/manage/' . $item['name'] . '/add', array('query' => content_menu_assemble_query_string($item)));
}
/**
* Menu add item operation handler for a new generic menu item.
*/
function content_menu_menu_form_handler_menu_position_rule($form, $form_state, $item) {
drupal_set_message(t("You're about to create a new generic menu position rule."));
drupal_set_message(t('Complete the process by filling out and saving the form below.'));
drupal_goto('admin/structure/menu-position/add', array('query' => content_menu_assemble_query_string($item)));
}
/**
* Menu add item operation handler for a new menu item to existing content.
*/
function content_menu_menu_form_handler_menu_position_existing($form, $form_state, $item) {
$url = content_menu_variable_get_add_existing_content_url();
// If using default view, ensure to only goto view page if views is enabled.
if (empty($url)) {
content_menu_menu_form_handler_url($form, $form_state, $item);
}
else {
drupal_set_message(t("You're about to create a new menu item for an existing content."));
drupal_set_message(t('Complete the process by finding and selecting an existing content to add to the menu.'));
drupal_goto($url, array('query' => content_menu_assemble_query_string($item)));
}
}
/**
* Menu add item operation handler for a new menu item to an existing view.
*/
function content_menu_menu_form_handler_existing_view($form, $form_state, $item) {
drupal_set_message(t("You're about to create a new menu item for an existing view."));
drupal_set_message(t('Complete the process by finding and selecting the view to add to the menu.'));
drupal_goto(CONTENT_MENU_ADD_EXISTING_VIEW_URL, array('query' => content_menu_assemble_query_string($item)));
}
/**
* List all views with a page display.
*/
function content_menu_add_exiting_view($form, $form_state) {
if (!module_exists('views')) {
return;
}
$form = array();
$item = content_menu_get_menu_item_from_querystring();
$form['#menu_item'] = $item;
$all_views = views_get_all_views();
foreach ($all_views as $view) {
foreach ($view->display as $display) {
if ($display->display_plugin == 'page') {
if ((!property_exists($view, 'disabled') || (property_exists($view, 'disabled') && !$view->disabled))) {
$view_path = $display->display_options['path'];
$view_title = check_plain($view->name . ' - ' . $display->display_title . ' (' . $display->display_options['path'] . ')');
if (drupal_valid_path($view_path)) {
$options[$view_path] = $view_title;
}
}
}
}
}
if (!empty($options)) {
asort($options);
$form['existing_view'] = array(
'#type' => 'radios',
'#title' => t('Link to this view'),
'#default_value' => isset($item['link_path']) ? $item['link_path'] : NULL,
'#required' => TRUE,
'#options' => $options,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#submit' => array('content_menu_add_exiting_view_submit'),
);
}
else {
$no_views_notice = t('There are no available views.');
if (module_exists('views_ui') && user_access('administer views')) {
$no_views_notice .= ' ' . t('You can create views in the <a href="@url">Views UI</a>', array('@url' => url('admin/structure/views')));
}
$form['view_info'] = array(
'#title' => t('Use these views'),
'#type' => 'item',
'#markup' => $no_views_notice,
);
}
return $form;
}
/**
* Submit handler for the form above.
*/
function content_menu_add_exiting_view_submit($form, $form_state) {
$menu_item = $form['#menu_item'];
$menu_item['link_path'] = $form_state['values']['existing_view'];
content_menu_link_save($menu_item);
}
/**
* Assembles a query string with menu item data.
*/
function content_menu_assemble_query_string($item) {
if (empty($item['name']) && isset($item['menu_name'])) {
$item['name'] = $item['menu_name'];
}
$query = array(
'menu_mlid' => isset($item['mlid']) ? $item['mlid'] : NULL,
'menu_title' => $item['title'],
'menu_plid' => $item['plid'],
'menu_name' => $item['name'],
'menu_hidden' => $item['hidden'],
'menu_weight' => $item['weight'],
'menu_link_path' => isset($item['link_path']) ? $item['link_path'] : NULL ,
'destination' => isset($item['destination']) ? $item['destination'] : ('admin/structure/menu/manage/' . $item['name']),
'msg_buffer' => isset($item['msg_buffer']) ? $item['msg_buffer'] : NULL,
);
return $query;
}
/**
* Retrieve all supported menu add item operations.
*/
function content_menu_get_target_types($menu_name) {
// Invoke hook to let modules provide target operations for new item.
$target_types = array();
$context = array('menu_name' => $menu_name);
drupal_alter('menu_item_target_types', $target_types, $context);
return $target_types;
}
/**
* Actual implementation for content_menu_menu_item_target_types_alter().
*
* Extend the target types for a new menu item provided by default.
* See content_menu.api.php for further documentation.
*/
function _content_menu_menu_item_target_types_alter(&$target_types, &$context) {
$target_types['url'] = array(
'label' => t('URL'),
'handler' => 'content_menu_menu_form_handler_url',
'clean_menu_save_message' => TRUE,
);
$target_types['dummy'] = array(
'label' => t('Placeholder'),
'handler' => 'content_menu_menu_form_handler_dummy',
'clean_menu_save_message' => FALSE,
);
foreach (node_type_get_types() as $node_type) {
if (user_access('create ' . $node_type->type . ' content') || user_access('administer nodes')) {
$node_menu_options = variable_get('menu_options_' . $node_type->type, array('main-menu' => 'main-menu'));
if (in_array($context['menu_name'], $node_menu_options)) {
$target_types['node_' . $node_type->type] = array(
'label' => t('New @type', array('@type' => t($node_type->name))),
'handler' => 'content_menu_menu_form_handler_node',
'arguments' => array('type' => $node_type->type),
'clean_menu_save_message' => TRUE,
);
}
}
}
$target_types['existing'] = array(
'label' => t('Existing content'),
'handler' => 'content_menu_menu_form_handler_menu_position_existing',
'clean_menu_save_message' => TRUE,
);
if (module_exists('views')) {
$target_types['existing_view'] = array(
'label' => t('Existing view'),
'handler' => 'content_menu_menu_form_handler_existing_view',
'clean_menu_save_message' => TRUE,
);
}
if (module_exists('menu_position') && user_access('administer menu positions')) {
$target_types['menu_position_rule'] = array(
'label' => t('Menu position rule'),
'handler' => 'content_menu_menu_form_handler_menu_position_rule',
'clean_menu_save_message' => TRUE,
);
}
}
@@ -0,0 +1,547 @@
<?php
/**
* @file
* Main code for the content_menu.module.
*
* ToDo: Use view query alter hook to mandatorily filter existing-node-selection
* by only those node types that can have a menu item in the resp. menu.
*
* ToDo: Mark menu items in item listing that are linked to unpublished content.
* NOTE: menu links to unpublished nodes are suppressed by Drupal.
* => Option 1: Alter Drupal's behavior to show unpublished links, too,
* and then mark them as unpublished (new permission).
* => Options 2: Leave everything as is.
*
* ToDo: Use menu.module's variable 'menu_override_parent_selector' to provide
* custom more scalable menu parent selector.
*
* ToDo: Pre-placement of new menu items is sometimes slightly misplaced.
*/
define('CONTENT_MENU_ADD_EXISTING_CONTENT_URL', 'admin/structure/menu/manage/add_existing_content');
define('CONTENT_MENU_ADD_EXISTING_VIEW_URL', 'admin/structure/menu/manage/add_existing_view');
define('CONTENT_MENU_ALTER_ALL_MENUS', FALSE);
define('CONTENT_MENU_ADD_ITEM_WEIGHT', 50);
/**
* Implements hook_permission().
*/
function content_menu_permission() {
return array(
// Introduce new permission for editing default system menus.
'administer system menus' => array(
'title' => t('Administer system menus'),
'description' => t('Administer system menus'),
),
);
}
/**
* Implements hook_menu().
*/
function content_menu_menu() {
// Add menu router item for use as target with dummy menu items.
$items['menu-dummy'] = array(
'title' => 'Placeholder for menu item dummies.',
'page callback' => 'content_menu_menu_callback_menu_dummy',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items[CONTENT_MENU_ADD_EXISTING_VIEW_URL] = array(
'title' => 'Add existing view.',
'page callback' => 'drupal_get_form',
'page arguments' => array('content_menu_add_exiting_view'),
'access arguments' => array('access content'),
'file' => 'content_menu.menu_admin.inc',
);
return $items;
}
/**
* Menu router callback for placeholder menu items.
*/
function content_menu_menu_callback_menu_dummy() {
return t('This is an empty placeholder page for a menu item.<br /><br />You can replace it with a valid target page URL in the <a href="@url">menu administration</a>.', array('@url' => url('admin/structure/menu')));
}
/**
* Implements hook_menu_alter().
*
* Rename some menu management tabs.
*/
function content_menu_menu_alter(&$items) {
$items['admin/structure/menu/manage/%menu']['title'] = $items['admin/structure/menu/manage/%menu/list']['title'] = t('Edit');
$items['admin/structure/menu/manage/%menu/edit']['title'] = t('Configure');
$items['admin/structure/menu']['page callback'] = 'content_menu_menu_overview_page_extended';
unset($items['admin/structure/menu']['file']);
}
/**
* Implements hook_init().
*
* Necessary to invoke for ajax callback to work correctly.
* @todo Refactor as ajax is actually not used.
*/
function content_menu_init() {
if (arg(0) == 'admin' || ((arg(0) == 'system') && (arg(1) == 'ajax'))) {
module_load_include('inc', 'content_menu', 'content_menu.menu_admin');
}
}
/**
* Callback for altered admin/structure/menu router item.
*/
function content_menu_menu_overview_page_extended() {
module_load_include('inc', 'content_menu', 'content_menu.menu_admin');
return _content_menu_menu_overview_page_extended();
}
/**
* Implements hook_theme().
*/
function content_menu_theme() {
return array(
// Theming function for extended menu overview form rendering.
'menu_overview_form_extended' => array(
'file' => 'content_menu.menu_admin.inc',
'render element' => 'form',
),
);
}
/**
* Implements hook_views_api().
*/
function content_menu_views_api() {
return array('api' => 3.0);
}
/**
* Implements hook_page_alter().
*
* Set consistent menu admin breadcrumbs on pages other than menu admin forms.
*/
function content_menu_page_alter(&$page) {
$menu_paths = array(
'admin/structure/menu/',
'admin/structure/menu-position/',
content_menu_variable_get_add_existing_content_url(),
);
$path = current_path();
foreach ($menu_paths as $menu_path) {
if (strpos($path, $menu_path) === 0) {
content_menu_set_menu_admin_breadcrumb();
break;
}
}
if (current_path() == content_menu_variable_get_add_existing_content_url()) {
$item = content_menu_get_menu_item_from_querystring();
if (isset($item['mlid']) && ($item['mlid'] != 0)) {
drupal_set_message(t("You're about to select a new content target for menu item %title.", array('%title' => $item['title'])));
drupal_set_message(t('Now you can select an existing content item for menu item %title.', array('%title' => $item['title'])));
}
}
}
/**
* Set consistent menu admin breadcrumb.
*/
function content_menu_set_menu_admin_breadcrumb($menu_name = NULL) {
$breadcrumb = array();
$breadcrumb[] = l(t('Home'), '<front>');
$breadcrumb[] = l(t('Administration'), 'admin');
$breadcrumb[] = l(t('Structure'), 'admin/structure');
$breadcrumb[] = l(t('Menus'), 'admin/structure/menu');
if ($menu_name == NULL) {
$menu_item = content_menu_get_menu_item_from_querystring();
if (isset($menu_item['name'])) {
$menu_name = $menu_item['name'];
}
}
if ($menu_name) {
$menus = menu_get_menus();
$menu_title = t($menus[$menu_name]);
$breadcrumb[] = l(t($menu_title), 'admin/structure/menu/manage/' . $menu_name);
drupal_set_title(t($menu_title));
}
drupal_set_breadcrumb($breadcrumb);
}
/**
* Implements hook_menu_link_insert().
*/
function content_menu_menu_link_insert($link) {
content_menu_mark_link_updated($link);
}
/**
* Implements hook_menu_link_update().
*/
function content_menu_menu_link_update($link) {
content_menu_mark_link_updated($link);
}
/**
* Mark newly created menu items, to highlight them subsequently.
*
* @param $link Array defining the link.
*/
function content_menu_mark_link_updated($link) {
// Save menu links created on or right before menu admin pages to session var.
if ((isset($_GET['destination']) && (strpos($_GET['destination'], 'admin/structure/menu/manage/') === 0))
||
(strpos(current_path(), 'admin/structure/menu/manage/') === 0)
) {
$link['created'] = time();
$_SESSION['content_menu_inserted_links'][$link['mlid']] = $link;
}
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Improve menu_edit_item form for better authoring experience.
*/
function content_menu_form_menu_edit_item_alter(&$form, &$form_state, $form_id) {
// Pre-populate menu item form elements with data from querystring.
if (isset($_GET['menu_title'])) {
$menu_item = content_menu_get_menu_item_from_querystring();
// If even link_path is given, create item right away and go back.
if (!empty($menu_item['link_path'])) {
content_menu_link_save($menu_item);
drupal_goto(check_plain($_GET['destination']));
}
$form['link_title']['#default_value'] = $menu_item['title'];
$form['link_path']['#default_value'] = $menu_item['link_path'];
$form['parent']['#default_value'] = $menu_item['name'] . ':' . $menu_item['plid'];
$form['weight']['#default_value'] = $menu_item['weight'];
$form['enabled']['#default_value'] = !($menu_item['hidden']);
}
// Extend breadcrumb.
if ($form['mlid']['#value']) {
$menu = explode(':', $form['parent']['#default_value']);
content_menu_set_menu_admin_breadcrumb($menu[0]);
}
// Simplify the form, by putting all "advanced" fields in fieldset.
$form['advanced'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 100,
'#title' => t('Advanced menu item settings'),
);
$advanced_elements = array('description', 'expanded', 'parent', 'weight');
foreach ($advanced_elements as $el_key) {
$form['advanced'][$el_key] = $form[$el_key];
unset($form[$el_key]);
}
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Improve menu_item_delete_form form for better authoring experience.
*/
function content_menu_form_menu_item_delete_form_alter(&$form, &$form_state, $form_id) {
if (!empty($form['#item']['mlid'])) {
// Extend breadcrumb.
$menu_name = $form['#item']['menu_name'];
content_menu_set_menu_admin_breadcrumb($menu_name);
// Add question text to form (instead of having it as the page title).
$form['question'] = array(
'#type' => 'markup',
'#markup' => '<div class="question">' . t('Are you sure you want to delete the custom menu link %item?', array('%item' => t($form['#item']['link_title']))) . '</div><p></p>',
'#weight' => -100,
);
// If menu item to delete links to a node, offer the choice to
// delete the associated node as well, if user is permitted.
if ($form['#item']['router_path'] == 'node/%') {
$nid = explode('/', $form['#item']['link_path']);
if (isset($nid[1]) && is_numeric($nid[1])) {
$node = node_load($nid[1]);
if (is_object($node) && node_access('delete', $node)) {
$form['delete_node'] = array(
'#type' => 'checkbox',
// '#markup' => '<div class="question">' . t('Are you sure you want to delete the custom menu link %item?', array('%item' => t($form['#item']['link_title']))) . '</div><p></p>',
'#title' => t('Delete associated %type <a href="@url">%title</a> as well.',
array(
'%type' => node_type_get_name($node),
'@url' => url('node/' . $node->nid),
'%title' => $node->title,
)),
'#default_value' => FALSE,
'#weight' => -50,
);
$form['delete_node_nid'] = array('#type' => 'value', '#value' => $node->nid);
$form['#submit'] = array('content_menu_item_delete_form_submit');
}
}
}
}
}
/**
* Extended submit handler for menu_item_delete_form.
*/
function content_menu_item_delete_form_submit($form, &$form_state) {
// Call default submit handler to handle deletion of menu item itself.
menu_item_delete_form_submit($form, $form_state);
// Delete an associated node as well, if intended and user is permitted.
if ($form_state['input']['delete_node'] == 1) {
$nid = explode('/', $form['#item']['link_path']);
if (isset($nid[1]) && is_numeric($nid[1])) {
$node = node_load($nid[1]);
if (is_object($node) && node_access('delete', $node) && ($node->nid == $form_state['values']['delete_node_nid'])) {
node_delete($node->nid);
watchdog('content', '@type: deleted %title.', array('@type' => $node->type, '%title' => $node->title));
drupal_set_message(t('@type %title has been deleted.', array('@type' => node_type_get_name($node), '%title' => $node->title)));
}
}
}
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Pre-populate input elements in menu_position_add_rule_form.
*/
function content_menu_form_menu_position_add_rule_form_alter(&$form, &$form_state, $form_id) {
// Pre-populate menu item form elements with data from querystring.
if (isset($_GET['menu_title'])) {
$menu_item = content_menu_get_menu_item_from_querystring();
$form['admin_title']['#default_value'] = $menu_item['title'];
$form['plid']['#default_value'] = $menu_item['name'] . ':' . $menu_item['plid'];
}
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Overhaul the menu_overview_form to improve menu authoring experience.
*/
function content_menu_form_menu_overview_form_alter(&$form, &$form_state, $form_id) {
if (variable_get('content_menu_alter_all_menus', CONTENT_MENU_ALTER_ALL_MENUS) || content_menu_is_menu_considered($form['#menu']['menu_name'])) {
module_load_include('inc', 'content_menu', 'content_menu.menu_admin');
_content_menu_form_menu_overview_form_alter($form, $form_state, $form_id);
}
}
/**
* Implements hook_menu_local_tasks_alter().
*
* Remove the "Add link" link on menu listing page, since
* we add a "New item" row and form element, which cares for adding new items.
*/
function content_menu_menu_local_tasks_alter(&$data, $router_item, $root_path) {
if (strpos(current_path(), 'admin/structure/menu/manage/') === 0) {
if (variable_get('content_menu_alter_all_menus', CONTENT_MENU_ALTER_ALL_MENUS) || content_menu_is_menu_considered(arg(4))) {
foreach ($data['actions']['output'] as $key => $action) {
if ($action['#link']['path'] == 'admin/structure/menu/manage/%/add') {
unset($data['actions']['output'][$key]);
}
}
}
}
}
/**
* Implements template_preprocess_views_view_field().
*
* For views to select exiting content, rewrite the nid field ("select" link)
* to link to the correct target url and pass through the querystring params.
*/
function content_menu_preprocess_views_view_field(&$vars) {
$view = &$vars['view'];
$field = &$vars['field'];
$selection_view = explode(':', variable_get('content_menu_add_existing_content_view', 'menu_existing_content_selection'));
if (($field->field == 'nid') && ($view->name == $selection_view[0]) && ((!isset($selection_view[1]) || ($view->current_display == $selection_view[1])))) {
module_load_include('inc', 'content_menu', 'content_menu.menu_admin');
$item = content_menu_get_menu_item_from_querystring();
if (!empty($item)) {
$item['link_path'] = 'node/' . $field->original_value;
$url = 'admin/structure/menu/manage/' . $item['name'] . '/add';
$vars['output'] = l(t('select'), $url, array('query' => content_menu_assemble_query_string($item)));
}
}
}
/**
* Implements hook_menu_item_target_types_alter().
*
* Extend the target types for a new menu item provided by default.
* See content_menu.api.php for further documentation.
*/
function content_menu_menu_item_target_types_alter(&$target_types, &$context) {
module_load_include('inc', 'content_menu', 'content_menu.menu_admin');
_content_menu_menu_item_target_types_alter($target_types, $context);
}
/**
* Alter a menu item's form element in the menu item administration.
*
* @param $el Array The form element of the menu item to alter.
*/
function content_menu_menu_item_element_alter(&$el) {
module_load_include('inc', 'content_menu', 'content_menu.menu_admin');
_content_menu_menu_item_element_alter($el);
}
/**
* Implements hook_node_insert().
*
* After creating a new node, if it's being created to replace a menu-dummy,
* perform the replacement.
*/
function content_menu_node_insert($node) {
// Ensure that this node is replacing a menu dummy.
if (isset($_GET['menu_link_path']) && $_GET['menu_link_path'] == 'menu-dummy') {
// Update the dummy that is being replaced by this node.
$menu_item = content_menu_get_menu_item_from_querystring();
$menu_item['link_path'] = "node/" . $node->nid;
content_menu_link_save($menu_item);
}
}
/**
* Implements hook_form_alter().
*
* Improve menu item management for node edit forms.
*/
function content_menu_form_alter(&$form, &$form_state, $form_id) {
if (isset($form['#node_edit_form'])) {
// Add link to menu overview / admin form to menu fieldset.
if (user_access('administer menu')) {
if ($form['#node_edit_form'] && isset($form['menu'])) {
$menu = explode(':', $form['menu']['link']['parent']['#default_value']);
$form['menu']['link']['menu_admin_link'] = array('#type' => 'markup', '#markup' => l(t('Manage menu structure') . ' …', 'admin/structure/menu/manage/' . $menu[0], array('attributes' => array('target' => '_blank'))));
}
}
if (isset($form['menu'])) {
if (isset($_GET['menu_link_path']) && $_GET['menu_link_path'] == 'menu-dummy') {
// If this node is being created to replace a menu dummy, substitute
// the usual menu form for a description of what will happen.
$form['menu']['enabled']['#access'] = FALSE;
$form['menu']['link']['#access'] = FALSE;
$trail = content_menu_get_menu_trail($_GET['menu_mlid']);
$form['menu']['menu_dummy_replace'] = array(
'#markup' => t('A link to this node will replace the menu dummy at <br /> %trail', array('%trail' => implode(' » ', $trail))),
);
$form['title']['#default_value'] = $form['title_field']['und']['0']['value']['#default_value'] = $_GET['menu_title'];
}
else {
// Hide description field from menu item fieldset.
$form['menu']['link']['description']['#access'] = FALSE;
// Pre-Populate menu item fields, if given via querystring.
if (isset($_GET['menu_title'])) {
$menu_item = content_menu_get_menu_item_from_querystring();
// Set node form's menu item input field
// according to query string input.
$form['menu']['enabled']['#default_value'] = 1;
$form['menu']['link']['hidden']['#value'] = $menu_item['hidden'];
$form['menu']['link']['link_title']['#default_value'] = $menu_item['title'];
$form['menu']['link']['parent']['#default_value'] = $menu_item['name'] . ':' . $menu_item['plid'];
$form['menu']['link']['weight']['#default_value'] = $menu_item['weight'];
$form['title']['#default_value'] = $form['title_field']['und']['0']['value']['#default_value'] = $menu_item['title'];
}
}
}
}
}
/**
* Build the menu trail array that points to the given mlid.
*/
function content_menu_get_menu_trail($leaf_mlid) {
$menu_link = menu_link_load($leaf_mlid);
$menu = menu_load($menu_link['menu_name']);
$trail = array();
while ($menu_link) {
array_unshift($trail, $menu_link['link_title']);
$menu_link = menu_link_load($menu_link['plid']);
}
array_unshift($trail, $menu['title']);
return $trail;
}
/**
* Build menu item data from querystring.
*/
function content_menu_get_menu_item_from_querystring() {
// Sanitize querystring input.
$menu_item = array();
foreach ($_GET as $get_key => $get_value) {
if (substr($get_key, 0, 5) == 'menu_') {
$menu_item[check_plain(substr($get_key, 5))] = strip_tags($get_value);
}
}
return $menu_item;
}
/**
* Check if a given menu (name) applies for being considered by this module.
*/
function content_menu_is_menu_considered($menu_name) {
$exclude_menus = variable_get('content_menu_special_menus',
array('management', 'user-menu', 'navigation', 'devel'));
return !in_array($menu_name, $exclude_menus);
}
/**
* Wrapper for menu_link_save() to create new menu link item from array.
*/
function content_menu_link_save($menu_item) {
$menu_item['menu_name'] = $menu_item['name'];
$menu_item['link_title'] = $menu_item['title'];
$menu_item['customized'] = 1;
return menu_link_save($menu_item);
}
/**
* Get config variable 'content_menu_add_existing_content_url'.
*/
function content_menu_variable_get_add_existing_content_url() {
$url = variable_get('content_menu_add_existing_content_url', CONTENT_MENU_ADD_EXISTING_CONTENT_URL);
// If using default view, ensure to only goto view page if views is enabled.
if (($url == CONTENT_MENU_ADD_EXISTING_CONTENT_URL) && !module_exists('views')) {
$url = NULL;
}
return $url;
}
@@ -0,0 +1,289 @@
<?php
/**
* @file
* Views-related stuff for Content Menu module.
*/
/**
* Implements hook_views_default_views().
*/
function content_menu_views_default_views() {
$view = new view();
$view->name = 'menu_existing_content_selection';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Menu existing content selection';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Select existing content';
$handler->display->display_options['use_ajax'] = TRUE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['access']['perm'] = 'administer menu';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
'title' => 'title',
'name' => 'name',
'created' => 'created',
'type' => 'type',
'nid' => 'nid',
);
$handler->display->display_options['style_options']['default'] = 'title';
$handler->display->display_options['style_options']['info'] = array(
'title' => array(
'sortable' => 1,
'default_sort_order' => 'asc',
'align' => '',
'separator' => '',
'empty_column' => 0,
),
'name' => array(
'sortable' => 1,
'default_sort_order' => 'asc',
'align' => '',
'separator' => '',
'empty_column' => 0,
),
'created' => array(
'sortable' => 1,
'default_sort_order' => 'asc',
'align' => '',
'separator' => '',
'empty_column' => 0,
),
'type' => array(
'sortable' => 1,
'default_sort_order' => 'asc',
'align' => '',
'separator' => '',
'empty_column' => 0,
),
'nid' => array(
'sortable' => 0,
'default_sort_order' => 'asc',
'align' => '',
'separator' => '',
'empty_column' => 0,
),
);
$handler->display->display_options['style_options']['override'] = 1;
$handler->display->display_options['style_options']['sticky'] = 0;
$handler->display->display_options['style_options']['empty_table'] = 0;
/* No results behavior: Global: Text area */
$handler->display->display_options['empty']['area']['id'] = 'area';
$handler->display->display_options['empty']['area']['table'] = 'views';
$handler->display->display_options['empty']['area']['field'] = 'area';
$handler->display->display_options['empty']['area']['empty'] = FALSE;
$handler->display->display_options['empty']['area']['content'] = 'There is no content available that matches your selection criteria';
$handler->display->display_options['empty']['area']['format'] = 'plain_text';
$handler->display->display_options['empty']['area']['tokenize'] = 0;
/* Relationship: Content: Author */
$handler->display->display_options['relationships']['uid']['id'] = 'uid';
$handler->display->display_options['relationships']['uid']['table'] = 'node';
$handler->display->display_options['relationships']['uid']['field'] = 'uid';
$handler->display->display_options['relationships']['uid']['required'] = 0;
/* Field: Content: Nid */
$handler->display->display_options['fields']['nid']['id'] = 'nid';
$handler->display->display_options['fields']['nid']['table'] = 'node';
$handler->display->display_options['fields']['nid']['field'] = 'nid';
$handler->display->display_options['fields']['nid']['label'] = '';
$handler->display->display_options['fields']['nid']['alter']['alter_text'] = 1;
$handler->display->display_options['fields']['nid']['alter']['text'] = '<span class="node-selector" data-nid="[nid]">select</span>';
$handler->display->display_options['fields']['nid']['alter']['make_link'] = 1;
$handler->display->display_options['fields']['nid']['alter']['path'] = 'node/[nid]';
$handler->display->display_options['fields']['nid']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['nid']['alter']['external'] = 0;
$handler->display->display_options['fields']['nid']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['nid']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['nid']['alter']['alt'] = 'Select this content';
$handler->display->display_options['fields']['nid']['alter']['link_class'] = 'node-pane-selector';
$handler->display->display_options['fields']['nid']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['nid']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['nid']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['nid']['alter']['more_link'] = 0;
$handler->display->display_options['fields']['nid']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['nid']['alter']['trim'] = 0;
$handler->display->display_options['fields']['nid']['alter']['html'] = 0;
$handler->display->display_options['fields']['nid']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['nid']['element_default_classes'] = 0;
$handler->display->display_options['fields']['nid']['hide_empty'] = 0;
$handler->display->display_options['fields']['nid']['empty_zero'] = 0;
$handler->display->display_options['fields']['nid']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['nid']['link_to_node'] = 0;
/* Field: Content: Link -&gt; */
$handler->display->display_options['fields']['title_1']['id'] = 'title_1';
$handler->display->display_options['fields']['title_1']['table'] = 'node';
$handler->display->display_options['fields']['title_1']['field'] = 'title';
$handler->display->display_options['fields']['title_1']['ui_name'] = 'Content: Link ->';
$handler->display->display_options['fields']['title_1']['label'] = '';
$handler->display->display_options['fields']['title_1']['exclude'] = TRUE;
$handler->display->display_options['fields']['title_1']['alter']['alter_text'] = 1;
$handler->display->display_options['fields']['title_1']['alter']['text'] = 'view &rarr;';
$handler->display->display_options['fields']['title_1']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['title_1']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['title_1']['alter']['external'] = 0;
$handler->display->display_options['fields']['title_1']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['title_1']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['title_1']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['title_1']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['title_1']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['title_1']['alter']['more_link'] = 0;
$handler->display->display_options['fields']['title_1']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['title_1']['alter']['trim'] = 0;
$handler->display->display_options['fields']['title_1']['alter']['html'] = 0;
$handler->display->display_options['fields']['title_1']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['title_1']['element_default_classes'] = 1;
$handler->display->display_options['fields']['title_1']['hide_empty'] = 0;
$handler->display->display_options['fields']['title_1']['empty_zero'] = 0;
$handler->display->display_options['fields']['title_1']['hide_alter_empty'] = 1;
$handler->display->display_options['fields']['title_1']['link_to_node'] = 1;
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['alter']['alter_text'] = 1;
$handler->display->display_options['fields']['title']['alter']['text'] = '[title] [title_1]';
$handler->display->display_options['fields']['title']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['title']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['title']['alter']['external'] = 0;
$handler->display->display_options['fields']['title']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['title']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = 0;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = 0;
$handler->display->display_options['fields']['title']['alter']['more_link'] = 0;
$handler->display->display_options['fields']['title']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['title']['alter']['trim'] = 0;
$handler->display->display_options['fields']['title']['alter']['html'] = 0;
$handler->display->display_options['fields']['title']['element_label_colon'] = 1;
$handler->display->display_options['fields']['title']['element_default_classes'] = 1;
$handler->display->display_options['fields']['title']['hide_empty'] = 0;
$handler->display->display_options['fields']['title']['empty_zero'] = 0;
$handler->display->display_options['fields']['title']['hide_alter_empty'] = 1;
$handler->display->display_options['fields']['title']['link_to_node'] = 0;
/* Field: Content: Type */
$handler->display->display_options['fields']['type']['id'] = 'type';
$handler->display->display_options['fields']['type']['table'] = 'node';
$handler->display->display_options['fields']['type']['field'] = 'type';
$handler->display->display_options['fields']['type']['label'] = 'Content Type';
$handler->display->display_options['fields']['type']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['type']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['type']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['type']['alter']['external'] = 0;
$handler->display->display_options['fields']['type']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['type']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['type']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['type']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['type']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['type']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['type']['alter']['trim'] = 0;
$handler->display->display_options['fields']['type']['alter']['html'] = 0;
$handler->display->display_options['fields']['type']['element_label_colon'] = 1;
$handler->display->display_options['fields']['type']['element_default_classes'] = 1;
$handler->display->display_options['fields']['type']['hide_empty'] = 0;
$handler->display->display_options['fields']['type']['empty_zero'] = 0;
$handler->display->display_options['fields']['type']['hide_alter_empty'] = 1;
$handler->display->display_options['fields']['type']['link_to_node'] = 0;
$handler->display->display_options['fields']['type']['machine_name'] = 0;
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['relationship'] = 'uid';
$handler->display->display_options['fields']['name']['label'] = 'Author';
$handler->display->display_options['fields']['name']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['name']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['name']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['name']['alter']['external'] = 0;
$handler->display->display_options['fields']['name']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['name']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['name']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['name']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['name']['alter']['trim'] = 0;
$handler->display->display_options['fields']['name']['alter']['html'] = 0;
$handler->display->display_options['fields']['name']['element_label_colon'] = 1;
$handler->display->display_options['fields']['name']['element_default_classes'] = 1;
$handler->display->display_options['fields']['name']['hide_empty'] = 0;
$handler->display->display_options['fields']['name']['empty_zero'] = 0;
$handler->display->display_options['fields']['name']['hide_alter_empty'] = 1;
$handler->display->display_options['fields']['name']['link_to_user'] = 0;
$handler->display->display_options['fields']['name']['overwrite_anonymous'] = 0;
$handler->display->display_options['fields']['name']['format_username'] = 1;
/* Field: Content: Post date */
$handler->display->display_options['fields']['created']['id'] = 'created';
$handler->display->display_options['fields']['created']['table'] = 'node';
$handler->display->display_options['fields']['created']['field'] = 'created';
$handler->display->display_options['fields']['created']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['created']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['created']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['created']['alter']['external'] = 0;
$handler->display->display_options['fields']['created']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['created']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['created']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['created']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['created']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['created']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['created']['alter']['trim'] = 0;
$handler->display->display_options['fields']['created']['alter']['html'] = 0;
$handler->display->display_options['fields']['created']['element_label_colon'] = 1;
$handler->display->display_options['fields']['created']['element_default_classes'] = 1;
$handler->display->display_options['fields']['created']['hide_empty'] = 0;
$handler->display->display_options['fields']['created']['empty_zero'] = 0;
$handler->display->display_options['fields']['created']['hide_alter_empty'] = 1;
$handler->display->display_options['fields']['created']['date_format'] = 'short';
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Title */
$handler->display->display_options['filters']['title']['id'] = 'title';
$handler->display->display_options['filters']['title']['table'] = 'node';
$handler->display->display_options['filters']['title']['field'] = 'title';
$handler->display->display_options['filters']['title']['operator'] = 'contains';
$handler->display->display_options['filters']['title']['exposed'] = TRUE;
$handler->display->display_options['filters']['title']['expose']['operator_id'] = 'title_op';
$handler->display->display_options['filters']['title']['expose']['label'] = 'Title contains';
$handler->display->display_options['filters']['title']['expose']['operator'] = 'title_op';
$handler->display->display_options['filters']['title']['expose']['identifier'] = 'title';
$handler->display->display_options['filters']['title']['expose']['required'] = 0;
$handler->display->display_options['filters']['title']['expose']['multiple'] = FALSE;
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['exposed'] = TRUE;
$handler->display->display_options['filters']['type']['expose']['operator_id'] = 'type_op';
$handler->display->display_options['filters']['type']['expose']['label'] = 'Type';
$handler->display->display_options['filters']['type']['expose']['operator'] = 'type_op';
$handler->display->display_options['filters']['type']['expose']['identifier'] = 'type';
$handler->display->display_options['filters']['type']['expose']['reduce'] = 0;
/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->display->display_options['path'] = 'admin/structure/menu/manage/add_existing_content';
$views[$view->name] = $view;
return $views;
}
@@ -0,0 +1,320 @@
#menu-overview-form tr.ok td {
background: #dfd;
}
.menu-overview-title-edit-trigger
{
margin-left: 8px;
display: none;
}
tr:hover .menu-overview-title-edit-trigger {
display: inline;
}
#menu-overview-form table.sticky-header {
z-index: 1;
}
table#menu-overview .menu-enabled .form-type-textfield,
table#menu-overview .menu-disabled .form-type-textfield {
display: inline;
display: none;
}
.menu-enabled .form-type-textfield input,
.menu-disabled .form-type-textfield input {
/*border-width: 0px;*/
margin-left: 0px;
}
.menu-additem .form-item-additem-hidden input {
margin-top: 2em;
}
.menu-additem .form-item-additem-title input {
margin: 0px;
}
.menu-additem td {
padding-bottom: 2em;
}
.menu-additem .tabledrag-changed {
position: absolute;
}
td.menu-target-content {
color: #888;
font-size: 11px;
}
.menu-target-content {
width: 90px;
}
.menu-operations {
width: 120px;
}
/* ctools dropbutton styling */
.ctools-button {
margin-top: -1em;
}
.ctools-button ul {
margin: 0em !important;
/* evil "!important" to override even more eveler theme style */
}
/* Taken from views/css/views-admin.ctools.css */
/* @group Buttons */
.ctools-button-processed {
background-color: #ffffff;
border-color: #cccccc;
font-size: 11px;
padding-bottom: 2px;
padding-top: 2px;
}
.ctools-button-processed,
.ctools-button-processed input {
text-transform: lowercase;
}
.ctools-button-processed:hover {
border-color: #b8b8b8;
}
.ctools-button-processed:active {
border-color: #a0a0a0;
}
.ctools-button-processed .ctools-content {
padding-bottom: 0;
padding-top: 0;
}
.ctools-dropbutton-processed {
position: absolute;
}
.ctools-dropbutton-processed .ctools-content {
border-right: 1px solid #e8e8e8;
}
.ctools-dropbutton-processed .ctools-content ul {
margin: 0;
padding: 0;
}
.ctools-content ul.actions {
margin-top: 0;
margin-bottom: 0;
padding-left: 0;
}
.ctools-button-processed .ctools-content a {
background-image: none;
border: medium none;
}
.ctools-dropbutton-processed.open:hover {
border-color: #D0D0D0;
}
.ctools-dropbutton-processed.open {
z-index: 100;
}
.ctools-dropbutton-processed .ctools-link {
border-left: 1px solid #ffffff;
}
.ctools-dropbutton-processed.open .ctools-content {
padding-bottom: 4px;
}
.ctools-dropbutton-processed li a,
.ctools-dropbutton-processed li input {
padding-right: 9px;
}
.ctools-dropbutton-processed.open li + li {
border-top: 1px solid #efefef;
margin-top: 4px;
padding-bottom: 0;
padding-top: 4px;
}
.ctools-twisty:focus {
outline: medium none;
}
.ctools-no-js .ctools-content ul {
margin-bottom: 0;
margin-top: 0;
padding-left: 0;
}
/*
#menu-overview .ctools-button-processed {
position: absolute;
right: 5px;
top: 4px;
}
*/
/*
.ctools-button-processed li a,
.ctools-button-processed input {
background: none;
border: medium;
font-family: inherit;
font-size: 12px;
padding-bottom: 0;
padding-left: 12px;
padding-top: 0;
margin-bottom: 0;
}
.ctools-button-processed input:hover {
background: none;
}
*/
/* @end */
/* Taken from views/css/views-admin.seven.css */
/* @group Buttons */
.ctools-button-processed ul {
margin: 0;
}
/* Override for input elements that are themed like ctools-buttons */
.ctools-button-processed input.form-submit:hover {
background-image: none;
color: #0074BD;
text-shadow: none;
}
.ctools-button-processed input.form-submit:active {
background: none;
border: medium none;
color: #0074BD;
text-shadow: none;
}
/* @end */
/* @group Buttons */
.ctools-button-processed {
background-image:
-moz-linear-gradient(
-90deg,
#ffffff 0px,
#f9f9f9 100%);
background-image:
-webkit-gradient(
linear,
left top,
left bottom,
color-stop(0.0, rgba(255, 255, 255, 1.0)),
color-stop(1.0, rgba(249, 249, 249, 1.0))
);
background-image:
-webkit-linear-gradient(
-90deg,
#ffffff 0px,
#f9f9f9 100%);
background-image:
linear-gradient(
-90deg,
#ffffff 0px,
#f9f9f9 100%);
-moz-border-radius: 11px 11px 11px 11px;
-webkit-border-radius: 11px 11px 11px 11px;
border-radius: 11px 11px 11px 11px;
}
.ctools-button-processed:hover {
background-image:
-moz-linear-gradient(
-90deg,
#ffffff 0px,
#f1f1f1 100%);
background-image:
-webkit-gradient(
linear,
left top,
left bottom,
color-stop(0.0, rgba(255, 255, 255, 1.0)),
color-stop(1.0, rgba(241, 241, 241, 1.0))
);
background-image:
-webkit-linear-gradient(
-90deg,
#ffffff 0px,
#f1f1f1 100%);
background-image:
linear-gradient(
-90deg,
#ffffff 0px,
#f1f1f1 100%);
}
.ctools-dropbutton-processed.open:hover {
background-image:
-moz-linear-gradient(
-90deg,
#ffffff 0px,
#f9f9f9 100%);
background-image:
-webkit-gradient(
linear,
left top,
left bottom,
color-stop(0.0, rgba(255, 255, 255, 1.0)),
color-stop(1.0, rgba(249, 249, 249, 1.0))
);
background-image:
-webkit-linear-gradient(
-90deg,
#ffffff 0px,
#f9f9f9 100%);
background-image:
linear-gradient(
-90deg,
#ffffff 0px,
#f9f9f9 100%);
}
.ctools-dropbutton-processed.open {
-moz-box-shadow: 1px 1px 2px rgba(0,0,0,0.25);
-webkit-box-shadow: 1px 1px 2px rgba(0,0,0,0.25);
box-shadow: 1px 1px 2px rgba(0,0,0,0.25);
}
/* @end */
@@ -0,0 +1,114 @@
<?php
/**
* Created by dreizwo.de.
* User: jakobs
* Date: 16.08.2012
* Time: 13:59:48
* @author markus jakobs <jakobs@dreizwo.de>
*/
require_once 'content_menu_filter.php';
class content_menu_domain_filter implements content_menu_filter {
private $active;
private $domain;
function __construct() {
$this->domain = $this->_content_menu_domainacccess();
$this->active = $this->domain ? TRUE : FALSE;
}
public function addFilterWidget(&$form, &$form_state, $form_id) {
// add a selection filter based only if multilang{
if ($this->active) {
foreach ($this->_content_menu_domain_list() as $did => $dom) {
$options[$did] = $dom['sitename'];
}
$form['domainselect'] = array(
'#type' => 'select',
'#title' => t('Filter menu by domain'),
'#options' => $options,
'#default_value' => $this->domain['domain_id'],
'#ajax' => array(
'callback' => '_content_menu_filter_elements_by_domain',
)
);
$form['#content_menu_filter_widget'][] = 'domainselect';
}
}
public function hideElement($el) {
if ($this->active) {
//hide on different lang
if (isset($el['#item']['options']['domain_menu_access'])) {
//unset if explicit hidden
if (isset($el['#item']['options']['domain_menu_access']['hide']) &&
in_array(
'd' . $this->domain['domain_id'], $el['#item']['options']['domain_menu_access']['hide'])
) {
return TRUE;
}
//if shown empty && not in shown => unset too
if (!empty($el['#item']['options']['domain_menu_access']['show']) &&
!in_array(
'd' . $this->domain['domain_id'], $el['#item']['options']['domain_menu_access']['show'])
) {
return TRUE;
}
}
}
return FALSE;
}
private function _content_menu_domainacccess() {
if (module_exists('domain')) {
$domains = $this->_content_menu_domain_list();
if (isset($_SESSION['content_menu_domain_filter'])) {
return $domains[$_SESSION['content_menu_domain_filter']];
}
if (count($domains) > 1) {
return domain_default(FALSE, FALSE);
}
}
return FALSE;
}
private function _content_menu_domain_list() {
$cache = &drupal_static(__FUNCTION__, array());
if (empty($cache['domains'])) {
$domains = array();
$query = db_select('domain', 'd')
->fields('d',
array(
'domain_id',
'sitename',
'subdomain',
'scheme',
'valid',
'weight',
'is_default'
))
->orderBy('weight');
// Get the domains.
$result = $query->execute();
while ($domain = $result->fetchAssoc()) {
$domains[$domain['domain_id']] = domain_api($domain);
}
$cache['domains'] = $domains;
return $domains;
}
return $cache['domains'];
}
}
function _content_menu_filter_elements_by_domain($form, &$form_state) {
$domain = $form_state['values']['domainselect'];
ctools_include('ajax');
$_SESSION['content_menu_domain_filter'] = $domain;
$commands[] = ctools_ajax_command_reload();
print ajax_render($commands);
exit;
}
@@ -0,0 +1,30 @@
<?php
/**
* Created by dreizwo.de.
* User: jakobs
* Date: 16.08.2012
* Time: 14:00:29
* @author markus jakobs <jakobs@dreizwo.de>
*/
interface content_menu_filter {
/**
* @abstract
* @param $el the menuitem
* @return true if a element should be hidden
*/
public function hideElement($el);
/**
* @abstract
* @param $form
* @param $form_state
* @param $form_id
* @return add the filter widget,
* to display the filter on top its recommended to add
* $form['#content_menu_filter_widget'][] = 'name_of_filter_widget';
* otherwise the filter will be displayed as child after the table
*/
public function addFilterWidget(&$form, &$form_state, $form_id);
}
@@ -0,0 +1,95 @@
<?php
/**
* Created by dreizwo.de.
* User: jakobs
* Date: 16.08.2012
* Time: 14:00:17
* @author markus jakobs <jakobs@dreizwo.de>
*/
require_once 'content_menu_filter.php';
class content_menu_language_filter implements content_menu_filter {
private $active;
private $language;
function __construct($menu_name) {
$this->active = $this->_content_menu_multilanguage_support($menu_name);
$this->language = $this->_content_menu_language();
}
public function addFilterWidget(&$form, &$form_state, $form_id) {
if ($this->active) {
$options = array(
'' => t('-- Current (@lang) --', array('@lang' => t($GLOBALS['language']->name))),
'all' => t('-- All --'),
);
foreach (language_list() as $key => $lang) {
$options[$key] = t($lang->name);
}
$form['langselect'] = array(
'#type' => 'select',
'#title' => t('Filter menu by language'),
'#options' => $options,
'#default_value' => $this->language,
// @todo Remove ctools dependency as ajax is actually not used.
// Refactor to use own form and submit handler instead.
'#ajax' => array(
'callback' => '_content_menu_filter_elements_by_language',
)
);
$form['#content_menu_filter_widget'][] = 'langselect';
}
}
public function hideElement($el) {
// If this filter is active...
$lang = $this->language;
if ($this->active && ($lang != 'all')) {
if ($lang == '') {
$lang = $GLOBALS['language']->language;
}
// Check every menu item with a specific language...
if (isset($el['#item']['language']) && ($el['#item']['language'] != LANGUAGE_NONE)) {
if ($el['#item']['language'] != $lang) {
return TRUE;
}
}
}
return FALSE;
}
private function _content_menu_multilanguage_support($menuname) {
$i18n_mode = 0;
$menu = menu_load($menuname);
$i18n_mode = $menu && isset($menu['i18n_mode']) ? $menu['i18n_mode'] : 0;
return (drupal_multilingual() && ($i18n_mode != 0));
}
private function _content_menu_language() {
$lang = '';
if ($this->active) {
if (isset($_SESSION['content_menu_lang_filter'])) {
$lang = $_SESSION['content_menu_lang_filter'];
}
}
return $lang;
}
}
function _content_menu_filter_elements_by_language($form, &$form_state) {
$lang = $form_state['values']['langselect'];
ctools_include('ajax');
$_SESSION['content_menu_lang_filter'] = $lang;
if ($lang = '') {
unset($_SESSION['content_menu_lang_filter']);
}
$commands[] = ctools_ajax_command_reload();
print ajax_render($commands);
exit;
}
@@ -0,0 +1,274 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave,
Cambridge, MA 02139, USA. Everyone is permitted to copy and distribute
verbatim copies of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your freedom to
share and change it. By contrast, the GNU General Public License is
intended to guarantee your freedom to share and change free software--to
make sure the software is free for all its users. This General Public License
applies to most of the Free Software Foundation's software and to any other
program whose authors commit to using it. (Some other Free Software
Foundation software is covered by the GNU Library General Public License
instead.) You can apply it to your programs, too.
When we speak of free software, we are referring to freedom, not price. Our
General Public Licenses are designed to make sure that you have the
freedom to distribute copies of free software (and charge for this service if
you wish), that you receive source code or can get it if you want it, that you
can change the software or use pieces of it in new free programs; and that
you know you can do these things.
To protect your rights, we need to make restrictions that forbid anyone to
deny you these rights or to ask you to surrender the rights. These restrictions
translate to certain responsibilities for you if you distribute copies of the
software, or if you modify it.
For example, if you distribute copies of such a program, whether gratis or for
a fee, you must give the recipients all the rights that you have. You must make
sure that they, too, receive or can get the source code. And you must show
them these terms so they know their rights.
We protect your rights with two steps: (1) copyright the software, and (2)
offer you this license which gives you legal permission to copy, distribute
and/or modify the software.
Also, for each author's protection and ours, we want to make certain that
everyone understands that there is no warranty for this free software. If the
software is modified by someone else and passed on, we want its recipients
to know that what they have is not the original, so that any problems
introduced by others will not reflect on the original authors' reputations.
Finally, any free program is threatened constantly by software patents. We
wish to avoid the danger that redistributors of a free program will individually
obtain patent licenses, in effect making the program proprietary. To prevent
this, we have made it clear that any patent must be licensed for everyone's
free use or not licensed at all.
The precise terms and conditions for copying, distribution and modification
follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND
MODIFICATION
0. This License applies to any program or other work which contains a notice
placed by the copyright holder saying it may be distributed under the terms
of this General Public License. The "Program", below, refers to any such
program or work, and a "work based on the Program" means either the
Program or any derivative work under copyright law: that is to say, a work
containing the Program or a portion of it, either verbatim or with
modifications and/or translated into another language. (Hereinafter, translation
is included without limitation in the term "modification".) Each licensee is
addressed as "you".
Activities other than copying, distribution and modification are not covered
by this License; they are outside its scope. The act of running the Program is
not restricted, and the output from the Program is covered only if its contents
constitute a work based on the Program (independent of having been made
by running the Program). Whether that is true depends on what the Program
does.
1. You may copy and distribute verbatim copies of the Program's source
code as you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice and
disclaimer of warranty; keep intact all the notices that refer to this License
and to the absence of any warranty; and give any other recipients of the
Program a copy of this License along with the Program.
You may charge a fee for the physical act of transferring a copy, and you
may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion of it,
thus forming a work based on the Program, and copy and distribute such
modifications or work under the terms of Section 1 above, provided that you
also meet all of these conditions:
a) You must cause the modified files to carry prominent notices stating that
you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in whole or in
part contains or is derived from the Program or any part thereof, to be
licensed as a whole at no charge to all third parties under the terms of this
License.
c) If the modified program normally reads commands interactively when run,
you must cause it, when started running for such interactive use in the most
ordinary way, to print or display an announcement including an appropriate
copyright notice and a notice that there is no warranty (or else, saying that
you provide a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this License.
(Exception: if the Program itself is interactive but does not normally print such
an announcement, your work based on the Program is not required to print
an announcement.)
These requirements apply to the modified work as a whole. If identifiable
sections of that work are not derived from the Program, and can be
reasonably considered independent and separate works in themselves, then
this License, and its terms, do not apply to those sections when you distribute
them as separate works. But when you distribute the same sections as part
of a whole which is a work based on the Program, the distribution of the
whole must be on the terms of this License, whose permissions for other
licensees extend to the entire whole, and thus to each and every part
regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest your rights to
work written entirely by you; rather, the intent is to exercise the right to
control the distribution of derivative or collective works based on the
Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of a
storage or distribution medium does not bring the other work under the scope
of this License.
3. You may copy and distribute the Program (or a work based on it, under
Section 2) in object code or executable form under the terms of Sections 1
and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable source
code, which must be distributed under the terms of Sections 1 and 2 above
on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three years, to give
any third party, for a charge no more than your cost of physically performing
source distribution, a complete machine-readable copy of the corresponding
source code, to be distributed under the terms of Sections 1 and 2 above on
a medium customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer to distribute
corresponding source code. (This alternative is allowed only for
noncommercial distribution and only if you received the program in object
code or executable form with such an offer, in accord with Subsection b
above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source code
means all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation and
installation of the executable. However, as a special exception, the source
code distributed need not include anything that is normally distributed (in
either source or binary form) with the major components (compiler, kernel,
and so on) of the operating system on which the executable runs, unless that
component itself accompanies the executable.
If distribution of executable or object code is made by offering access to
copy from a designated place, then offering equivalent access to copy the
source code from the same place counts as distribution of the source code,
even though third parties are not compelled to copy the source along with the
object code.
4. You may not copy, modify, sublicense, or distribute the Program except as
expressly provided under this License. Any attempt otherwise to copy,
modify, sublicense or distribute the Program is void, and will automatically
terminate your rights under this License. However, parties who have received
copies, or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
5. You are not required to accept this License, since you have not signed it.
However, nothing else grants you permission to modify or distribute the
Program or its derivative works. These actions are prohibited by law if you
do not accept this License. Therefore, by modifying or distributing the
Program (or any work based on the Program), you indicate your acceptance
of this License to do so, and all its terms and conditions for copying,
distributing or modifying the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the original
licensor to copy, distribute or modify the Program subject to these terms and
conditions. You may not impose any further restrictions on the recipients'
exercise of the rights granted herein. You are not responsible for enforcing
compliance by third parties to this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues), conditions
are imposed on you (whether by court order, agreement or otherwise) that
contradict the conditions of this License, they do not excuse you from the
conditions of this License. If you cannot distribute so as to satisfy
simultaneously your obligations under this License and any other pertinent
obligations, then as a consequence you may not distribute the Program at all.
For example, if a patent license would not permit royalty-free redistribution
of the Program by all those who receive copies directly or indirectly through
you, then the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply and
the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any patents or
other property right claims or to contest validity of any such claims; this
section has the sole purpose of protecting the integrity of the free software
distribution system, which is implemented by public license practices. Many
people have made generous contributions to the wide range of software
distributed through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing to
distribute software through any other system and a licensee cannot impose
that choice.
This section is intended to make thoroughly clear what is believed to be a
consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in certain
countries either by patents or by copyrighted interfaces, the original copyright
holder who places the Program under this License may add an explicit
geographical distribution limitation excluding those countries, so that
distribution is permitted only in or among countries not thus excluded. In such
case, this License incorporates the limitation as if written in the body of this
License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will be
similar in spirit to the present version, but may differ in detail to address new
problems or concerns.
Each version is given a distinguishing version number. If the Program specifies
a version number of this License which applies to it and "any later version",
you have the option of following the terms and conditions either of that
version or of any later version published by the Free Software Foundation. If
the Program does not specify a version number of this License, you may
choose any version ever published by the Free Software Foundation.
10. If you wish to incorporate parts of the Program into other free programs
whose distribution conditions are different, write to the author to ask for
permission. For software which is copyrighted by the Free Software
Foundation, write to the Free Software Foundation; we sometimes make
exceptions for this. Our decision will be guided by the two goals of
preserving the free status of all derivatives of our free software and of
promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE,
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT
PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE
STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
NECESSARY SERVICING, REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR
AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR
ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL,
SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
ARISING OUT OF THE USE OR INABILITY TO USE THE
PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA
OR DATA BEING RENDERED INACCURATE OR LOSSES
SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE
PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN
IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF
THE POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
@@ -0,0 +1,15 @@
// $Id: README.txt,v 1.3 2010/10/29 10:31:08 anrikun Exp $
MENU ADMIN PER MENU
http://drupal.org/project/menu_admin_per_menu
DESCRIPTION
By default, Drupal 7 allows only users with "Administer menus and menu items" to add, modify or delete menu items.
In case you want for instance to let certain users manage Main menu or Navigation menu but not Management menu, this module provides this functionality.
INSTALLATION
Please read instructions at: http://drupal.org/project/menu_admin_per_menu
CONTACT
Henri MEDOT <henri.medot[AT]absyx[DOT]fr>
http://www.absyx.fr
@@ -0,0 +1,14 @@
; $Id: menu_admin_per_menu.info,v 1.4 2011/01/22 22:23:55 anrikun Exp $
name = Menu Admin per Menu
description = Allows to give roles per menu admin permissions without giving them full administrer menu permission.
package = Administration
core = 7.x
dependencies[] = menu
files[] = menu_admin_per_menu.module
; Information added by drupal.org packaging script on January 1, 1970 - 00:00
version = "7.x-1.0"
core = "7.x"
project = "menu_admin_per_menu"
datestamp = "1295735798"
@@ -0,0 +1,152 @@
<?php
// $Id: menu_admin_per_menu.module,v 1.6 2010/10/29 10:31:08 anrikun Exp $
/**
* @file menu_admin_per_menu.module
* Main file for the menu_admin_per_menu module.
*
* By default, Drupal allows only users with administrer menu permission to add, modify or delete menu items.
* In case you want for instance to let certain users manage primary links or secondary links but not navigation menu,
* this module provides this functionality.
* Developped by Henri MEDOT <henri.medot[AT]absyx[DOT]fr>
* http://www.absyx.fr
*/
/**
* Implementation of hook_permission().
*/
function menu_admin_per_menu_permission() {
$perms = array();
$menus = menu_get_menus();
foreach ($menus as $name => $title) {
$perms['administer '. $name .' menu items'] = array('title' => t('Administer %menu menu items', array('%menu' => $title)));
}
return $perms;
}
/**
* Implementation of hook_menu_alter()
*/
function menu_admin_per_menu_menu_alter(&$items) {
$items['admin/structure/menu']['page callback'] = '_menu_admin_per_menu_menu_overview_page';
$items['admin/structure/menu']['access callback'] = '_menu_admin_per_menu_access';
unset($items['admin/structure/menu']['access arguments']);
$items['admin/structure/menu/manage/%menu']['access callback'] = '_menu_admin_per_menu_menu_access';
$items['admin/structure/menu/manage/%menu']['access arguments'] = array(4);
$items['admin/structure/menu/manage/%menu/add']['access callback'] = '_menu_admin_per_menu_menu_access';
$items['admin/structure/menu/manage/%menu/add']['access arguments'] = array(4);
$items['admin/structure/menu/item/%menu_link/edit']['access callback'] = '_menu_admin_per_menu_menu_link_access';
$items['admin/structure/menu/item/%menu_link/edit']['access arguments'] = array(4);
$items['admin/structure/menu/item/%menu_link/reset']['access callback'] = '_menu_admin_per_menu_menu_link_access';
$items['admin/structure/menu/item/%menu_link/reset']['access arguments'] = array(4);
$items['admin/structure/menu/item/%menu_link/delete']['access callback'] = '_menu_admin_per_menu_menu_link_access';
$items['admin/structure/menu/item/%menu_link/delete']['access arguments'] = array(4);
}
function _menu_admin_per_menu_menu_overview_page() {
if (user_access('administer menu')) {
return menu_overview_page();
}
$result = db_query("SELECT * FROM {menu_custom} ORDER BY title", array(), array('fetch' => PDO::FETCH_ASSOC));
$header = array(t('Title'), array('data' => t('Operations'), 'colspan' => '2'));
$rows = array();
foreach ($result as $menu) {
if (user_access('administer '. $menu['menu_name'] .' menu items')) {
$row = array(theme('menu_admin_overview', array('title' => $menu['title'], 'name' => $menu['menu_name'], 'description' => $menu['description'])));
$row[] = array('data' => l(t('list links'), 'admin/structure/menu/manage/' . $menu['menu_name']));
$row[] = array('data' => l(t('add link'), 'admin/structure/menu/manage/' . $menu['menu_name'] . '/add'));
$rows[] = $row;
}
}
return theme('table', array('header' => $header, 'rows' => $rows));
}
function _menu_admin_per_menu_access() {
if (user_access('administer menu')) {
return TRUE;
}
$perms = array_keys(menu_admin_per_menu_permission());
foreach ($perms as $perm) {
if (user_access($perm)) {
return TRUE;
}
}
return FALSE;
}
function _menu_admin_per_menu_menu_access($menu = NULL) {
if (user_access('administer menu')
|| user_access('administer '. $menu['menu_name'] .' menu items')) {
return TRUE;
}
return FALSE;
}
function _menu_admin_per_menu_menu_link_access($menu_link = NULL) {
if (user_access('administer menu')
|| user_access('administer '. $menu_link['menu_name'] .' menu items')) {
return TRUE;
}
return FALSE;
}
/**
* Implementation of hook_form_alter()
*/
function menu_admin_per_menu_form_alter(&$form, $form_state, $form_id) {
if (isset($form['menu']['link']['parent']) && !user_access('administer menu')) {
$form['menu']['#access'] = FALSE;
if (_menu_admin_per_menu_filter_parent_options($form['menu']['link'])) {
$option_keys = array_keys($form['menu']['link']['parent']['#options']);
$form['menu']['#access'] = TRUE;
if (empty($form['menu']['link']['mlid']['#value']) && !in_array($form['menu']['link']['parent']['#default_value'], $option_keys)) {
$form['menu']['link']['parent']['#default_value'] = $option_keys[0];
}
}
}
}
function _menu_admin_per_menu_filter_parent_options(&$element) {
$perm_menus = _menu_admin_per_menu_get_perm_menus();
if ((count($perm_menus) > 0) && is_array($element['parent']['#options'])) {
$has_mlid = !empty($element['mlid']['#value']);
$default_value = $element['parent']['#default_value'];
$option_keys = array_keys($element['parent']['#options']);
foreach ($option_keys as $option_key) {
list($menu, $item) = explode(':', $option_key);
if (!in_array($menu, $perm_menus)) {
unset($element['parent']['#options'][$option_key]);
if ($has_mlid && ($option_key == $default_value)) {
return FALSE;
}
}
}
return count($element['parent']['#options']) > 0;
}
return FALSE;
}
function _menu_admin_per_menu_get_perm_menus() {
$perm_menus = array();
$menus = menu_get_menus();
foreach ($menus as $name => $title) {
if (user_access('administer '. $name .' menu items')) {
$perm_menus[] = $name;
}
}
return $perm_menus;
}
/**
* Implementation of hook_form_FORM_ID_alter()
*/
function menu_admin_per_menu_form_menu_edit_item_alter(&$form, &$form_state, $form_id) {
if (isset($form['parent']) && !user_access('administer menu') && _menu_admin_per_menu_filter_parent_options($form)) {
$option_keys = array_keys($form['parent']['#options']);
if (empty($form['mlid']['#value']) && !in_array($form['parent']['#default_value'], $option_keys)) {
$form['parent']['#default_value'] = $option_keys[0];
}
}
}
@@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
@@ -0,0 +1,20 @@
<?php
class me_node_creation_CrumbsMonoPlugin implements crumbs_MonoPlugin {
function describe($api) {
$api->setTitle('Set breadcrumbs for placeholder pages.');
}
function findParent($path, $item) {
switch ($item['route']) {
case 'node/add/%/mlid/%':
$mlid = $item['fragments'][4];
return "mlid/$mlid/under-construction";
case 'mlid/%/under-construction':
// Let the menu.hierarchy.* plugin do its thing
break;
}
}
}
@@ -0,0 +1,56 @@
<?php
/**
* Page callback for node/add/%node_type/mlid/%menu_editor_mlid
*/
function me_node_creation_create_node($type, $menu_item) {
global $user;
drupal_set_title(t('Create @name', array('@name' => $type->name)), PASS_THROUGH);
$node = (object)array(
'uid' => $user->uid,
'name' => (isset($user->name) ? $user->name : ''),
'type' => $type->type,
'language' => LANGUAGE_NONE,
'me_node_creation_menu_item' => $menu_item,
);
module_load_include('pages.inc', 'node');
$form = drupal_get_form($type->type . '_node_form', $node);
return $form;
}
function _me_node_creation_form_alter(&$form, $node) {
$menu_item = $node->me_node_creation_menu_item;
unset($form['menu']);
$mlid_text = $menu_item['mlid'];
$mlid_path = "admin/structure/menu/item/$mlid_text/edit";
if ($mlid_router_item = menu_get_item($mlid_path)) {
if ($mlid_router_item['access']) {
$mlid_text = l($mlid_text, $mlid_path);
}
}
$txt = t('The created node will be associated with the chosen menu item (!mlid),<br/>with link title "@title"', array(
'!mlid' => $mlid_text,
'@title' => $menu_item['link_title'],
));
$txt = "<p>$txt</p>";
$form['me_node_creation'] = array(
'#type' => 'markup',
'#markup' => $txt,
'#weight' => -20,
);
$form['title']['#default_value'] = $menu_item['link_title'];
// $form['#me_node_creation_menu_item'] = $menu_item;
// $form['#submit'][] = 'me_node_creation_node_form_submit';
}
@@ -0,0 +1,14 @@
name = Menu Editor - Node creation
description = Menu item placeholders for node creation.
package = Menu
core = 7.x
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"
core = "7.x"
project = "menu_editor"
datestamp = "1380586819"
@@ -0,0 +1,197 @@
<?php
/**
* Implements hook_permission()
*/
function me_node_creation_permission() {
return array(
'see menu_editor placeholder pages' => array(
'title' => t('See menu_editor placeholder pages'),
),
);
}
/**
* Implements hook_menu()
*/
function me_node_creation_menu() {
$items = array();
$items['node/add/%node_type/mlid/%menu_editor_menu_link'] = array(
'load arguments' => array(2, 4),
'title' => 'Create a node',
'page callback' => 'me_node_creation_create_node',
'page arguments' => array(2, 4),
'file' => 'me_node_creation.create.inc',
'access callback' => 'me_node_creation_create_node_access',
'access arguments' => array(2),
);
$items['mlid/%menu_editor_menu_link/under-construction'] = array(
'title' => 'Under Construction',
'title callback' => 'menu_editor_placeholder_title',
'title arguments' => array(1),
'page callback' => 'menu_editor_placeholder_page',
'page arguments' => array(1),
'file' => 'me_node_creation.placeholder.inc',
'access arguments' => array('see menu_editor placeholder pages'),
'weight' => 0,
);
return $items;
}
/**
* Implements hook_form_alter()
*/
function me_node_creation_form_alter(&$form, &$form_state, $form_id) {
if (empty($form['#node_edit_form']) || empty($form['#node'])) {
return;
}
$node = $form['#node'];
if (empty($node->me_node_creation_menu_item)) {
return;
}
module_load_include('create.inc', 'me_node_creation');
return _me_node_creation_form_alter($form, $node);
}
/**
* Implements hook_node_insert()
*/
function me_node_creation_node_insert($node) {
$menu_item = @$node->me_node_creation_menu_item;
if (!$menu_item) {
return;
}
$mlid = $menu_item['mlid'];
$nid = $node->nid;
switch ($menu_item['link_path']) {
case "node/add/$node->type/mlid/$mlid":
case "mlid/$mlid/under-construction":
$menu_item['link_path'] = "node/$nid";
$menu_item['router_path'] = "node/%";
$menu_item['options'] = array();
menu_link_save($menu_item);
}
}
/**
* Implements hook_crumbs_plugins()
*/
function me_node_creation_crumbs_plugins($api) {
$api->monoPlugin();
}
// 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.
*/
function menu_editor_menu_link_load($mlid) {
static $_cache = array();
if (is_numeric($mlid) && $mlid) {
if (isset($_cache[$mlid])) {
return $_cache[$mlid];
}
$query = db_select('menu_links', 'ml');
$query->leftJoin('menu_router', 'm', 'm.path = ml.router_path');
$query->fields('ml');
// Weight should be taken from {menu_links}, not {menu_router}.
$query->addField('ml', 'weight', 'link_weight');
$query->fields('m');
$query->condition('ml.mlid', $mlid);
if ($item = $query->execute()->fetchAssoc()) {
$_cache[$mlid] =& $item;
$item['weight'] = $item['link_weight'];
$item['load_functions'] = unserialize($item['load_functions']);
_menu_link_translate($item);
return $item;
}
}
return FALSE;
}
// Title callbacks
// -----------------------------------------------------------------------------
/**
* Title callback for mlid/%menu_link/under-construction
*
* @param array $item
* The menu link, as returned by menu_link_load()
* @return string
* The title, to be used in tabs, breadcrumbs and menus
*/
function menu_editor_placeholder_title($item) {
// _menu_link_translate($item);
return $item['link_title'];
}
/**
* Title for menu links or tabs.
* The page title can be different!
*
* @param $type_arg
* @param $item
*/
function me_node_creation_title($type_arg, $item) {
foreach (node_type_get_types() as $type_name => $type_object) {
if ($type_name == $type_arg) {
return "New $type_object->name";
}
}
return $type->name;
}
// Access callbacks
// -----------------------------------------------------------------------------
/**
* Access callback for node/add/%node_type/mlid/%menu_editor_mlid
*/
function me_node_creation_create_node_access($type) {
if (!is_object($type)) {
ddebug_backtrace();
return FALSE;
}
return node_access('create', $type->type);
}
// Utility
// -----------------------------------------------------------------------------
/**
* @return array
* Array of placeholders
*/
function me_node_creation_menu_editor_placeholders() {
$placeholders = array(
'<new>' => 'mlid/@mlid/under-construction',
'<new page>' => NULL
);
foreach (node_type_get_types() as $type_name => $type_info) {
$placeholders["<new $type_name>"] = "node/add/$type_name/mlid/@mlid";
}
// we want that <new page> is first, if this content type exists.
// if not, we remove this placeholder.
if (!isset($placeholders['<new page>'])) {
unset($placeholders['<new page>']);
}
return $placeholders;
}
@@ -0,0 +1,38 @@
<?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.
*/
function menu_editor_placeholder_page($item) {
drupal_set_title(t('!link_title - Under Construction', array(
'!link_title' => $item['link_title'],
)));
$html = '';
foreach (node_type_get_types() as $type_name => $type_info) {
if (me_node_creation_create_node_access($type_info)) {
$link_html = l($type_info->name, "node/add/$type_name/mlid/$item[mlid]");
$html .= "<li>$link_html</li>";
}
}
// TODO: Provide themeable output, or find another solution.
$txt = t('We are working on it.');
if ($html) {
$txt_admin = t("Replace this placeholder link with real content:");
return <<<EOT
<p>$txt</p>
<p>$txt_admin</p>
<ul>$html</ul>
EOT;
} else {
return <<<EOT
<p>$txt</p>
EOT;
}
}
@@ -0,0 +1,12 @@
name = Menu Editor path autocomplete
description = Autocomplete for Menu Editor path field.
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"
core = "7.x"
project = "menu_editor"
datestamp = "1380586819"
@@ -0,0 +1,105 @@
<?php
/**
* @file
* Find node paths on menu item creation via autocomplete.
*
* This is a shameless clone of
* http://drupal.org/project/mpac
* by stBorchert
*/
/**
* Implements hook_menu().
*
* @return An array of menu items.
*/
function me_path_autocomplete_menu() {
$items = array();
$items['mepac/autocomplete'] = array(
'title' => 'Menu path autocomplete',
'description' => 'Autocomplete callback for menu path autocomplete',
'page callback' => 'me_path_autocomplete',
'access callback' => 'user_access',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Find nodes and URL aliases based on title.
* @param $string
* Title of element to find.
* @return
* List of elements with path as key.
*/
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;
foreach (module_invoke_all('menu_editor_placeholders') as $placeholder_code => $placeholder_path) {
if (!strlen($string) || count(explode($string, $placeholder_code)) > 1) {
$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();
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();
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";
}
}
}
drupal_json_output($matches);
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Change path field to autocomplete field.
*/
function me_path_autocomplete_form_menu_editor_overview_form_alter(&$form, &$form_state) {
foreach (element_children($form) as $element_key) {
$form[$element_key]['link_path']['#autocomplete_path'] = 'mepac/autocomplete';
}
}
@@ -0,0 +1,614 @@
<?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.
*/
function menu_editor_overview_form($form, &$form_state, $menu) {
global $menu_admin;
$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.*
FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path
WHERE ml.menu_name = :menu
ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC";
$result = db_query($sql, array(':menu' => $menu['menu_name']), array('fetch' => PDO::FETCH_ASSOC));
$links = array();
foreach ($result as $item) {
$links[] = $item;
}
$tree = menu_tree_data($links);
$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;
menu_tree_check_access($tree, $node_links);
$menu_admin = FALSE;
$form = array('#tree' => TRUE);
$form['#multilingual_menu'] = FALSE;
$form['#translatable_nodes'] = FALSE;
$max_root_weight = _menu_editor_overview_tree_form($form, $form_state, $tree);
// default values for all new menu items..
$default_values = array(
'link_title' => '',
'link_path' => '<front>',
'description' => '',
'hidden' => true,
'expanded' => false,
'weight' => 0,
// 'mlid' => NULL, // this is different for every single one
'plid' => 0,
'language' => LANGUAGE_NONE,
);
foreach (menu_editor_get_placeholders() as $placeholder_code => $placeholder_path) {
// take the first placeholder as default link path instead of <front>
$default_values['link_path'] = $placeholder_code;
break;
}
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']);
$form[$item_key]['weight']['#default_value'] = $max_root_weight + $i + 1;
$form[$item_key]['#item'] = array();
$form[$item_key]['#attributes'] = array('class' => 'menu-new');
$form[$item_key]['drag']['#markup'] = t('New menu item');
}
$form['#menu'] = $menu;
if (element_children($form)) {
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
}
else {
$form['empty_menu'] = array('#value' => t('There are no menu items yet.'));
}
return $form;
}
/**
* Recursive helper function for menu_overview_form().
*/
function _menu_editor_overview_tree_form(&$form, &$form_state, $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'];
$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'];
if (!$plid && $weight > $max_root_weight) {
// this is a root level item
$max_root_weight = $weight;
}
$path = $item['link_path'];
if (!empty($item['options']['query'])) {
if (is_array($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'];
}
}
if (isset($item['options']['fragment'])) {
$path .= '#'. $item['options']['fragment'];
}
$default_values = array(
'link_title' => $item['link_title'],
'link_path' => $path,
'description' => isset($item['options']['attributes']['title']) ? $item['options']['attributes']['title'] : '',
'hidden' => !$item['hidden'],
'expanded' => $item['expanded'],
'weight' => $weight,
'plid' => $plid,
'depth' => 1,
);
$form[$item_key] = _menu_editor_overview_tree_form_item($item['mlid'], $default_values, $form['#multilingual_menu']);
$form[$item_key]['#item'] = $item;
$form[$item_key]['#attributes'] = $item['hidden'] ? array('class' => 'menu-disabled') : array('class' => 'menu-enabled');
$form[$item_key]['drag']['#markup'] = l($item['title'], $item['href'], $item['localized_options']) . ($item['hidden'] ? ' ('. t('disabled') .')' : '');
// Include i18n support.
if (module_exists('i18n_menu')) {
$item['language'] = i18n_menu_item_get_language($item);
$node_item = ($node = i18n_menu_item_get_node($item)) && i18n_menu_node_supported_type($node->type);
if (!$node_item && i18n_menu_mode($item['menu_name'], I18N_MODE_TRANSLATE)) {
$form[$item_key]['language'] = array('#title' => NULL) + i18n_element_language_select($item);
$form['#multilingual_menu'] = TRUE;
// If the term to be added will be a translation of a source term,
// set the default value of the option list to the target language and
// create a form element for storing the translation set of the source term.
if (isset($_GET['translation']) && isset($_GET['target']) && ($source_item = menu_link_load($_GET['translation']))) {
if (!empty($source_item['i18n_tsid'])) {
$translation_set = i18n_translation_set_load($source_item['i18n_tsid']);
}
else {
// Create object and stick the source information in the translation set.
$translation_set = i18n_translation_set_build('menu_link')
->add_item($source_item);
}
$form[$item_key]['link_path']['#default_value'] = $source_item['link_path'];
// Maybe we should disable the 'link_path' and 'parent' form elements?
// $form['link_path']['#disabled'] = TRUE;
// $form['parent']['#disabled'] = TRUE;
$form[$item_key]['language']['#default_value'] = $_GET['target'];
$form[$item_key]['language']['#disabled'] = TRUE;
}
}
else {
$form[$item_key]['language'] = array(
'#type' => 'value',
'#value' => $item['language'],
);
}
// Aside from the usual conditions from i18n_menu_form_menu_edit_item_alter(), also
// check if the return of the language name isn't "Undefined". This is caused when
// choosing "Translate mode" to be "No multilingual options for menu items. Only the
// menu will be translatable." but one of the menu items is a node which
// is translatable.
if ($node_item && i18n_langcode($item['language'])) {
$form[$item_key]['lang_message'] = array(
'#type' => 'markup',
'#title' => t('Language'),
'#markup' => i18n_language_name($item['language']),
);
$form['#translatable_nodes'] = TRUE;
}
}
// Only items created by the menu module can be deleted.
if ($item['module'] == 'menu' || $item['updated'] == 1) {
$form[$item_key]['delete'] = array(
'#type' => 'checkbox',
'#title' => t('delete'),
'#default_value' => false,
);
}
}
// process child elements
if ($data['below']) {
_menu_editor_overview_tree_form($form, $form_data, $data['below']);
}
}
return $max_root_weight;
}
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']) {
$default_values['link_path'] = $code;
}
}
$element = array();
$element['link_title'] = array(
'#type' => 'textfield',
'#size' => 25,
);
$element['link_path'] = array(
'#type' => 'textfield',
'#size' => 25,
);
$element['description'] = array(
'#type' => 'textarea',
'#cols' => 8,
'#rows' => 1,
'#resizable' => FALSE,
);
$element['hidden'] = array(
'#type' => 'checkbox',
);
$element['expanded'] = array(
'#type' => 'checkbox',
);
$element['weight'] = array(
// The original form uses a select box for the weight.
// We use a textfield instead, to save memory on server side
// and to reduce page size.
'#type' => 'textfield',
'#size' => 4,
'#element_validate' => array('_menu_editor_valid_weight'),
);
$element['mlid'] = array(
'#type' => 'hidden',
'#value' => $item_mlid,
);
$element['plid'] = array(
'#type' => 'textfield',
'#size' => 6,
);
// If this is a new menu item, simply provide i18n_menu select options.
if (strpos($item_mlid, 'new') === 0 && $multilingual_menu) {
$element['language'] = array('#title' => NULL) + i18n_element_language_select();
}
foreach ($default_values as $key => $value) {
if (isset($element[$key])) {
$element[$key]['#default_value'] = $value;
}
}
return $element;
}
/**
* Weight textfield validation function
* Stolen from http://drupal.org/project/tiny_menu_editor
* Big thanks to Dmitriy.trt
*/
function _menu_editor_valid_weight($element, &$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.'));
}
}
}
function menu_editor_overview_form_validate($form, &$form_state) {
$form_values = &$form_state['values'];
// Check existing items.
foreach (element_children($form) as $item_key) {
// Check if these are menu items.
if (strpos($item_key, 'mlid-') !== FALSE) {
$element = &$form[$item_key];
if (isset($element['link_path'])) {
menu_editor_validate_item($element, $element['link_path']['#value'], $item_key . '][');
}
}
}
// allow new items to be dynamically added via javascript,
// that have not been in the form originally.
foreach ($form_state['input'] as $item_key => $item) {
if (preg_match('/^mlid-new\d+$/', $item_key)) {
if (menu_editor_overview_form_validate_new_item($item)) {
$form_values[$item_key] = $item;
}
}
}
}
/**
* Validate form values for a menu link being added or edited.
*/
function menu_editor_validate_item(&$element, $link_path, $error_key_prefix) {
$placeholders = menu_editor_get_placeholders();
if (isset($placeholders[$link_path])) {
// it would be hard to check access,
// because we don't necessarily know the mlid.
// Thus, we simply grant access for all placeholders.
return;
}
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;
}
$item = $element['#item'];
$normal_path = drupal_get_normal_path($link_path);
$item['link_path'] = $normal_path;
if (!url_is_external($normal_path)) {
$parsed_link = parse_url($normal_path);
if (isset($parsed_link['query'])) {
$item['options']['query'] = drupal_get_query_array($parsed_link['query']);
}
if (isset($parsed_link['fragment'])) {
$item['options']['fragment'] = $parsed_link['fragment'];
}
$item['link_path'] = $parsed_link['path'];
}
if (!trim($item['link_path']) || !drupal_valid_path($item['link_path'])) {
form_set_error($error_key_prefix . 'link_path', t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $item['link_path'])));
}
}
/**
* validate a menu item that was dynamically added through javascript
*
* @param unknown_type $item
*/
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()
*/
function menu_editor_overview_form_submit($form, &$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,
// the child item could be saved with an invalid path past its immediate
// parent. To prevent this, save items in the form in the same order they
// are sent by $_POST, ensuring parents are saved first, then their children.
// See http://drupal.org/node/181126#comment-632270
$item_keys = array_flip(array_keys($form_state['input'])); // Get the $_POST order.
$form_values = array_merge($item_keys, $form_state['values']); // Update our original form with the new order.
$menu_name = $form['#menu']['menu_name'];
$updated_items = array();
$fields = array('expanded', 'weight', 'plid', 'link_title', 'link_path', 'description');
foreach ($form_values as $item_key => $v) {
if (isset($form[$item_key]['#item'])) {
$element = $form[$item_key];
if (!is_numeric($v['mlid'])) {
// add new item
unset($v['mlid']);
if (!is_string($v['link_title']) || empty($v['link_title'])) {
continue;
}
if (!is_string($v['link_path']) || empty($v['link_path'])) {
continue;
}
$element['#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
// doing menu_link_save().
if (isset($v[$field])) {
$element['#item'][$field] = $v[$field];
}
}
$updated_items[$item_key] = $element['#item'];
} else if (!empty($v['delete'])) {
// delete existing item
if (is_numeric($v['mlid'])) {
menu_link_delete($v['mlid']);
}
continue;
} else {
// update existing item
// Update any fields that have changed in this menu item.
foreach ($fields as $field) {
if ($v[$field] != $element[$field]['#default_value']) {
$element['#item'][$field] = $v[$field];
$updated_items[$item_key] = $element['#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;
$updated_items[$item_key] = $element['#item'];
}
// 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) {
$element['#item']['language'] = $v['language'];
$updated_items[$item_key] = $element['#item'];
}
}
// description is a special case
if (isset($updated_items[$item_key]['description'])) {
$updated_items[$item_key]['options']['attributes']['title'] = $updated_items[$item_key]['description'];
}
}
}
// placeholders to change the link path
$placeholders = menu_editor_get_placeholders();
// Save all our changed items to the database.
$errors = array();
$mlids = array();
foreach ($updated_items as $item_key => $item) {
$item['customized'] = 1;
// check the link path
$link_path = &$item['link_path'];
$link_path_placeholder = NULL;
// placeholders
if (isset($placeholders[$link_path])) {
if (isset($item['mlid']) && is_numeric($item['mlid'])) {
$link_path = str_replace('@mlid', $item['mlid'], $placeholders[$link_path]);
}
else {
$link_path_placeholder = $placeholders[$link_path];
// use a dummy link path,
// until we know the correct mlid.
$link_path = '<front>';
}
}
// clean the link path
if (isset($link_path)) {
$link_path = drupal_get_normal_path($link_path);
if (!url_is_external($link_path)) {
$parsed_link = parse_url($link_path);
if (isset($parsed_link['query'])) {
$item['options']['query'] = drupal_get_query_array($parsed_link['query']);
}
else {
unset($item['options']['query']);
}
if (isset($parsed_link['fragment'])) {
$item['options']['fragment'] = $parsed_link['fragment'];
}
else {
unset($item['options']['fragment']);
}
if ($link_path != $parsed_link['path']) {
$link_path = $parsed_link['path'];
}
}
if (!trim($link_path) || !drupal_valid_path($link_path)) {
// invalid link path, discard this item
continue;
}
}
// drupal_set_message('<pre>' . print_r($item, true) . '</pre>');
if (!empty($item['plid']) && !is_numeric($item['plid'])) {
if (isset($mlids["mlid-$item[plid]"])) {
$item['plid'] = $mlids["mlid-$item[plid]"];
}
else {
unset($item['plid']);
}
}
$mlid = menu_link_save($item);
if (is_numeric($mlid)) {
// remember as a plid for child items
$mlids[$item_key] = $mlid;
if (isset($link_path_placeholder)) {
// overwrite the dummy link path
$link_path = str_replace('@mlid', $item['mlid'], $link_path_placeholder);
menu_link_save($item);
}
}
else {
$errors[] = $item_key;
}
}
if (!empty($errors)) {
drupal_set_message(t('There were errors saving the following menu links:<br/>' . implode('<br/>', $errors)), 'error');
}
}
/**
* Theme the menu overview form into a table.
*
* @ingroup themeable
*/
function theme_menu_editor_overview_form($variables) {
$form = $variables['form'];
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'];
drupal_add_tabledrag('menu-overview', 'match', 'parent', 'menu-plid', 'menu-plid', 'menu-mlid', TRUE, MENU_MAX_DEPTH - 1);
drupal_add_tabledrag('menu-overview', 'order', 'sibling', 'menu-weight');
$header = array();
$header[] = t('Menu item');
$header[] = t('Title');
$header[] = t('Path');
$header[] = array('data' => t('Descr.', array(), array('context' => 'Abbr: "Description"')), 'class' => 'description');
$header[] = array('data' => t('En.', array(), array('context' => 'Abbr: "Enabled"')), 'class' => 'checkbox');
$header[] = array('data' => t('Exp.', array(), array('context' => 'Abbr: "Expanded"')), 'class' => 'checkbox');
$header[] = t('Weight');
if ($i18n_menu) {
$header[] = t('Language');
}
$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'])) {
$element = &$form[$item_key];
// Add special classes to be used for tabledrag.js.
$element['plid']['#attributes']['class'] = array('menu-plid');
$element['mlid']['#attributes']['class'] = array('menu-mlid');
$element['weight']['#attributes']['class'] = array('menu-weight');
// Change the parent field to a hidden. This allows any value but hides the field.
$element['plid']['#type'] = 'hidden';
// Adjust tab index to allow vertical tabbing
foreach (array('link_title', 'link_path', 'description', 'hidden', 'expanded') as $i => $key) {
$element[$key]['#attributes']['tabindex'] = $i+2;
}
$element['link_path']['#attributes']['tabindex'] = 2;
$cells = array();
$size = isset($element['#item']['depth']) ? $element['#item']['depth'] : 1;
$cells['drag'] = array(
'data' => theme('indentation', array('size' => $size - 1)) . drupal_render($element['drag']),
'class' => 'drag',
);
$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['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) {
if (isset($element['lang_message'])) {
$cells['language'] = array('data' => drupal_render($element['lang_message']));
}
else {
$cells['language'] = array('data' => drupal_render($element['language']), 'class' => 'select');
}
}
$cells['delete'] = array('data' => drupal_render($element['delete']), 'class' => 'delete-checkbox');
$row = array_merge(array('data' => $cells), $element['#attributes']);
$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' : '';
}
$rows[$item_key] = $row;
}
}
$output = '';
// allow other modules to change the table data.
drupal_alter('menu_editor_overview_table', $header, $rows);
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'menu-overview')));
$output .= drupal_render_children($form);
return $output;
}
@@ -0,0 +1,56 @@
form#menu-editor-overview-form th {
white-space:nowrap; /* we don't want linebreaks in the title cells */
}
form#menu-editor-overview-form td {
vertical-align:middle;
}
form#menu-editor-overview-form td.description {
width:3em; /* shrink to smallest possible width */
}
form#menu-editor-overview-form td.checkbox {
width:1em; /* shrink to smallest possible width */
white-space:nowrap;
}
form#menu-editor-overview-form td.title-edit .form-item,
form#menu-editor-overview-form td.path-edit .form-item,
form#menu-editor-overview-form td.description .form-item {
padding-right:4px; /* compensate the 100% width */
position:relative;
zoom:1; /* hasLayout hack for IE6, IE7 */
}
form#menu-editor-overview-form td.title-edit input,
form#menu-editor-overview-form td.path-edit input,
form#menu-editor-overview-form td.description input {
border-width:1px;
margin-top:0;
margin-bottom:0;
width:100%;
}
form#menu-editor-overview-form td.description textarea {
border-width:1px;
margin-top:0;
margin-bottom:0;
width:100%;
height:1em;
resize:none; /* prevent chrome and safari textarea resizing */
}
form#menu-editor-overview-form .focus-description-column td.description {
width:250px;
}
form#menu-editor-overview-form .focus-description-column tr.focus td.description div.form-item {
height:auto !important;
zoom:1; /* hasLayout hack for IE6, IE7 */
}
form#menu-editor-overview-form .focus-description-column tr.focus td.description textarea {
height:60px !important;
}
@@ -0,0 +1,13 @@
name = Menu Editor
description = Improved interface for menu editing.
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"
core = "7.x"
project = "menu_editor"
datestamp = "1380586819"
@@ -0,0 +1,67 @@
(function($) {
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>&nbsp;'+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();
$('td.drag', this).each(function(){
$(this).css('width', w+'px');
});
}
// get reference css for textareas
var ref_input = $('td.path-edit input', this);
var h = ref_input.height();
var ref_css = {
'height': h + 'px',
'padding-top': ref_input.css('padding-top'),
'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');
$('tr.focus', table).removeClass('focus');
$(this).parents('tr').slice(0, 1).addClass('focus');
});
$('td:not(.description) input', this).focus(function(){
table.removeClass('focus-description-column');
$('tr.focus', table).removeClass('focus');
$(this).parents('tr').slice(0, 1).addClass('focus');
});
});
}
};
})(jQuery);
@@ -0,0 +1,92 @@
<?php
/**
* Implementation of hook_menu().
*/
function menu_editor_menu() {
$items['admin/structure/menu/manage/%menu/poweredit'] = array(
'title' => 'Power Edit',
'page callback' => 'drupal_get_form',
'page arguments' => array('menu_editor_overview_form', 4),
// 'title callback' => 'menu_editor_overview_title',
// 'title arguments' => array(3),
'access callback' => 'menu_editor_form_access',
'access arguments' => array(4),
'type' => MENU_LOCAL_TASK,
'file' => 'menu_editor.admin.inc',
);
return $items;
}
/**
* Implements hook_permission().
*/
function menu_editor_permission() {
$menus = menu_get_menus(TRUE);
$perm = array();
foreach ($menus as $menu_machine_name => $menu_display_name) {
$perm["menu edit $menu_machine_name"] = array(
'title' => t("Menu editor: Edit @menu", array('@menu' => $menu_display_name)),
);
}
return $perm;
}
function menu_editor_form_access($menu) {
return
user_access('administer menu') ||
user_access("menu edit $menu[menu_name]")
;
}
// function menu_editor_admin_menu() {
// $result = db_query("SELECT * FROM {menu_custom} ORDER BY title");
// $items = array();
// while ($menu = db_fetch_array($result)) {
// $items[] = array(
// 'title' => $menu['title'],
// 'path' => 'admin/build/menu-customize/'. $menu['menu_name'] . '/poweredit',
// 'parent_path' => 'admin/build/menu/list',
// 'weight' => 100,
// );
// }
// return $items;
// }
/**
* Implemenation of hook_theme().
*/
function menu_editor_theme() {
return array(
'menu_editor_overview_form' => array(
'file' => 'menu_editor.admin.inc',
'render element' => 'form',
),
);
}
/**
* Title callback for the menu overview page and links.
*/
function menu_editor_overview_title($menu) {
return $menu['title'];
}
function menu_editor_get_placeholders() {
static $placeholders;
if (!isset($placeholders)) {
$placeholders = module_invoke_all('menu_editor_placeholders');
}
return $placeholders;
}
function menu_editor_get_path_for_placeholder($placeholder, $mlid) {
$placeholders = menu_editor_get_placeholders();
if (isset($placeholders[$placeholder])) {
return str_replace('%mlid', $mlid, $placeholders[$placeholder]);
}
return $placeholder;
}
@@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
@@ -0,0 +1,45 @@
-- SUMMARY --
"Multi path autocomplete" helps anyone who creates menu items on
admin/build/menu/*/add to enter the path to nodes.
It changes the input field for the menu path to an autocomplete text field so
you can simply enter the title of the node and will get a list with all
matching values. If you select one of them its path will be placed into the
textfield.
If path.module is enabled autocomplete is working for URL aliases, too.
For a full description of the module, visit the project page:
http://drupal.org/project/mpac
To submit bug reports and feature suggestions, or to track changes:
http://drupal.org/project/issues/mpac
-- REQUIREMENTS --
None.
-- INSTALLATION --
* Install as usual, see http://drupal.org/node/70151 for further information.
-- DEVELOPER NOTES --
You can alter the list of results by using hook_mpac_autocomplete_paths().
Example:
<code><?php
function MODULENAME_mpac_autocomplete_paths_alter(&$matches, $title) {
$matches['custom/path/1'] = t('My custom autocomplete result');
}
?></code>
-- CONTACT --
Current maintainers:
* Stefan Borchert (stborchert) - http://drupal.org/user/36942
@@ -0,0 +1,20 @@
<?php
/**
* @file
* Administrative functions and forms for mpac.module.
*/
function mpac_settings_form() {
$form = array();
$form['mpac_max_items'] = array(
'#type' => 'select',
'#title' => t('Maximum number of items'),
'#description' => t('Select the maximum number of items in an autocomplete popup provided by mpac.'),
'#default_value' => variable_get('mpac_max_items', 20),
'#options' => drupal_map_assoc(array(10, 20, 50, 100)),
);
return system_settings_form($form);
}
@@ -0,0 +1,15 @@
name = Multi path autocomplete
description = "Find paths on menu item creation, shortcut creation or url alias creation via autocomplete."
core = 7.x
; Files to load.
files[] = mpac.module
files[] = mpac.admin.inc
configure = admin/config/search/mpac
; Information added by drupal.org packaging script on 2013-01-30
version = "7.x-1.2"
core = "7.x"
project = "mpac"
datestamp = "1359567543"
+225
View File
@@ -0,0 +1,225 @@
<?php
/**
* @file
* Find node paths on menu item creation via autocomplete.
*/
/**
* Implement hook_menu().
*
* @return An array of menu items.
*/
function mpac_menu() {
$items = array();
$items['mpac/autocomplete'] = array(
'title' => 'Multi path autocomplete',
'description' => 'Autocomplete callback for Multi path autocomplete',
'page callback' => 'mpac_autocomplete',
'access callback' => 'user_access',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['admin/config/search/mpac'] = array(
'title' => 'Multi path autocomplete',
'description' => 'Administer settings for Multi path autocomplete',
'page callback' => 'drupal_get_form',
'page arguments' => array('mpac_settings_form'),
'access callback' => 'user_access',
'access arguments' => array('administer site configuration'),
'file' => 'mpac.admin.inc',
);
return $items;
}
/**
* Find nodes, shortcuts and URL aliases based on title.
*
* @return
* List of elements with path as key.
*/
function mpac_autocomplete() {
$args = arg();
// Strip off the first 2 arguments ("mpac" and "autocomplete").
$args = array_slice($args, 2);
// Get the type of autocomplete we would like to display results for.
$type = array_shift($args);
// Validate type.
if (!in_array($type, array('alias', 'menu', 'shortcut'))) {
// The given type is not supported.
return;
}
if (count($args) == 0) {
// No more arguments so there is nothing to do for MPAC.
return;
}
// Prepare the search query (if an argument contains a forward slash it has
// been splitted into two arguments so join it once again).
$query = implode('/', $args);
$matches = array();
$title = filter_xss_admin($query);
// Get a list of all nodes where the title matches the given string.
$matches = _mpac_get_matches_for_nodes($title);
if (($type == 'menu') && module_exists('path')) {
// Get a list of all URL aliases where the destination matches the given
// string.
$matches = array_merge($matches, _mpac_get_matches_for_aliases($title));
}
if (($type == 'shortcut') && module_exists('shortcut')) {
// Get a list of menu items containing the given string in their title.
$matches = array_merge($matches, _mpac_get_matches_for_shortcuts($title));
if (module_exists('path')) {
// Get matching url aliases.
$matches = array_merge($matches, _mpac_get_matches_for_aliases($title));
}
}
// Sort result list.
natsort($matches);
// Allow other modules to add paths.
drupal_alter('mpac_autocomplete_paths', $matches, $title);
// Reduce results to maximum number of items.
$matches = array_slice($matches, 0, variable_get('mpac_max_items', 20));
// Print results.
drupal_json_output($matches);
}
/**
* Implement hook_form_FORM_ID_alter().
*
* Change path field to autocomplete field.
*/
function mpac_form_menu_edit_item_alter(&$form, &$form_state) {
if ($form['link_path']['#type'] == 'textfield') {
$form['link_path']['#autocomplete_path'] = 'mpac/autocomplete/menu';
$form['link_path']['#description'] .= '<br />' . t("You may enter the title of the node you'd like to link to to get a list of all possible matches.");
if (module_exists('path')) {
$form['link_path']['#description'] .= ' ' . t('Matches marked with %marker are URL aliases.', array('%marker' => t('*')));
}
}
}
/**
* Implement hook_form_FORM_ID_alter().
*
* Change path field for URL aliases to autocomplete field.
*/
function mpac_form_path_admin_form_alter(&$form, &$form_state) {
if ($form['source']['#type'] == 'textfield') {
$form['source']['#autocomplete_path'] = 'mpac/autocomplete/alias';
$form['source']['#description'] .= '<br />' . t("You may enter the title of the node you'd like to link to to get a list of all possible matches.");
}
}
/**
* Implement hook_form_FORM_ID_alter().
*
* Change path field for new shortcuts to autocomplete field.
*/
function mpac_form_shortcut_link_add_alter(&$form, &$form_state) {
if ($form['shortcut_link']['link_path']['#type'] == 'textfield') {
$form['shortcut_link']['link_path']['#autocomplete_path'] = 'mpac/autocomplete/shortcut';
$form['shortcut_link']['link_path']['#description'] .= '<br />' . t("You may enter the title of a node or a page you'd like to link to to get a list of all possible matches.");
if (module_exists('path')) {
$form['shortcut_link']['link_path']['#description'] .= ' ' . t('Matches marked with %marker are URL aliases.', array('%marker' => t('*')));
}
}
}
/**
* Implement hook_form_FORM_ID_alter().
*
* Change path field for existing shortcuts to autocomplete field.
*/
function mpac_form_shortcut_link_edit_alter(&$form, &$form_state) {
if ($form['shortcut_link']['link_path']['#type'] == 'textfield') {
$form['shortcut_link']['link_path']['#autocomplete_path'] = 'mpac/autocomplete/shortcut';
$form['shortcut_link']['link_path']['#description'] .= '<br />' . t("You may enter the title of a node or a page you'd like to link to to get a list of all possible matches.");
if (module_exists('path')) {
$form['shortcut_link']['link_path']['#description'] .= ' ' . t('Matches marked with %marker are URL aliases.', array('%marker' => t('*')));
}
}
}
/**
* Helper function to find all nodes containing the given title.
*
* @param $title
* The title to search for.
*/
function _mpac_get_matches_for_nodes($title = '') {
$matches = array();
if ($title == '') {
return $matches;
}
$query = db_select('node', 'n')->extend('PagerDefault');
$query->condition('title', '%' . $title . '%', 'LIKE');
$result = $query
->fields('n')
->limit(variable_get('mpac_max_items', 20))
->execute();
foreach ($result as $node) {
// Add node path and title to list.
if (node_access('view', $node) && $node->status) {
$matches['node/' . $node->nid] = check_plain($node->title);
}
}
return $matches;
}
/**
* Helper function to find all url aliases containing the given title in their
* destination string.
*
* @param $title
* The title to search for.
*/
function _mpac_get_matches_for_aliases($title = '') {
$matches = array();
if ($title == '') {
return $matches;
}
$query = db_select('url_alias')->extend('PagerDefault');
$query->condition('alias', '%' . $title . '%', 'LIKE');
$result = $query
->fields('url_alias')
->limit(variable_get('mpac_max_items', 20))
->execute();
foreach ($result as $alias) {
$matches[$alias->source] = check_plain($alias->alias) . t('*');
}
return $matches;
}
/**
* Helper function to find all menu items containing the given string in their
* title.
*
* @param $title
* The title to search for.
*/
function _mpac_get_matches_for_shortcuts($title = '') {
$matches = array();
if ($title == '') {
return $matches;
}
$query = db_select('menu_router')->extend('PagerDefault');
$query->condition('title', '%' . $title . '%', 'LIKE');
$query->where('path NOT LIKE :percent', array(':percent' => '%\%%'));
$result = $query
->fields('menu_router')
->limit(variable_get('mpac_max_items', 20))
->execute();
foreach ($result as $menu_item) {
$matches[$menu_item->path] = check_plain($menu_item->title);
}
return $matches;
}