initial commit of starter install drupal 7
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+56
@@ -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;
|
||||
}
|
||||
+38
@@ -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;
|
||||
}
|
||||
}
|
||||
+12
@@ -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"
|
||||
|
||||
+105
@@ -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> '+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;
|
||||
}
|
||||
Reference in New Issue
Block a user