first import
This commit is contained in:
339
sites/all/modules/nodereference_url/LICENSE.txt
Normal file
339
sites/all/modules/nodereference_url/LICENSE.txt
Normal file
@@ -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.
|
83
sites/all/modules/nodereference_url/README.txt
Normal file
83
sites/all/modules/nodereference_url/README.txt
Normal file
@@ -0,0 +1,83 @@
|
||||
|
||||
The Node Reference URL Widget module adds a new widget to the Node Reference
|
||||
CCK field type. It auto-populates a node reference field with a value from the
|
||||
URL, and does not allow this value to be changed once set.
|
||||
|
||||
Node Reference URL Widget was written by Nate Haug.
|
||||
|
||||
This Module Made by Robots: http://www.lullabot.com
|
||||
|
||||
Dependencies
|
||||
------------
|
||||
* Node Reference (part of References)
|
||||
|
||||
Install
|
||||
-------
|
||||
Installing the Node Reference URL Widget is simple:
|
||||
|
||||
1) Copy the nodereference_url folder to the sites/all/modules folder in your
|
||||
installation.
|
||||
|
||||
2) Enable the module using Administer -> Modules (admin/modules)
|
||||
|
||||
3) Add or edit a Node Reference field from admin/structure/types/manage/[type]/fields.
|
||||
When configuring the field, use the "Reference from URL" option.
|
||||
|
||||
4) Follow on-screen help text to configure your Node Reference URL Widget.
|
||||
|
||||
Advanced: Build your own links
|
||||
------------------------------
|
||||
Normally you can prepopulate a Node Reference URL widget simply by creating a
|
||||
link with the following structure:
|
||||
|
||||
As HTML:
|
||||
<a href="/node/add/story/10">Add a story</a>
|
||||
|
||||
Or in PHP code:
|
||||
<a href="<?php print url('node/add/story/' . $node->nid); ?>">Add a story</a>
|
||||
|
||||
However if using multiple Node Reference fields, you can populate them by
|
||||
using a query string instead of embedding the IDs directly in the URL. Assuming
|
||||
you had two fields, named "field_ref_a" and "field_ref_b", the URL to
|
||||
prepopulate both of them at the same time would look like this:
|
||||
|
||||
In HTML:
|
||||
<a href="/node/add/story?ref_a=10&ref_b=20">Add a story</a>
|
||||
|
||||
Or in PHP code:
|
||||
<a href="<?php print url('node/add/story', array('query' => array('ref_a' => $nid1, 'ref_b' => $nid2))); ?>">Add a story</a>
|
||||
|
||||
Advanced: Support for non-standard URLs
|
||||
---------------------------------------
|
||||
By default Node Reference URL Widget will only work with node form paths that
|
||||
match the standard Drupal install: "node/add/%type", where %type is a node type
|
||||
like "blog" or "story". If you want to use Node Reference URL Widget on
|
||||
non-standard URLs, you may do so by informing Node Reference URL Widget of these
|
||||
special paths.
|
||||
|
||||
To do so, add additional paths to your settings.php with the following code:
|
||||
|
||||
$conf['nodereference_url_paths'] = array(
|
||||
'node/add/%type/%nid',
|
||||
'node/%/add/%type/%nid',
|
||||
);
|
||||
|
||||
Only two tokens are supported:
|
||||
%type: The node type that will be created.
|
||||
%nid: The node ID that will be referenced.
|
||||
|
||||
The % wildcard may be used when including other dynamic IDs.
|
||||
|
||||
In the above example, Node Reference URL Widget will work at either
|
||||
"node/add/story/2" or "node/1/add/story/2", where "2" is the node ID being
|
||||
referenced. Important to note: The first URL will be used in the links that Node
|
||||
Reference URL Widget provides. If needing advanced configuration of links, look
|
||||
into the Custom Links module: http://drupal.org/project/custom_links.
|
||||
|
||||
Support
|
||||
-------
|
||||
If you experience a problem with this module or have a problem, file a
|
||||
request or issue in the Node Reference URL Widget queue at
|
||||
http://drupal.org/project/issues/nodereference_url. DO NOT POST IN THE FORUMS.
|
||||
Posting in the issue queues is a direct line of communication with the module
|
||||
authors.
|
13
sites/all/modules/nodereference_url/nodereference_url.info
Normal file
13
sites/all/modules/nodereference_url/nodereference_url.info
Normal file
@@ -0,0 +1,13 @@
|
||||
name = Node Reference URL Widget
|
||||
description = Adds an additional widget to the Node Reference field that prepopulates a reference by the URL.
|
||||
dependencies[] = node_reference
|
||||
files[] = nodereference_url.module
|
||||
package = Fields
|
||||
core = 7.x
|
||||
|
||||
; Information added by drupal.org packaging script on 2011-09-24
|
||||
version = "7.x-1.12"
|
||||
core = "7.x"
|
||||
project = "nodereference_url"
|
||||
datestamp = "1316903507"
|
||||
|
536
sites/all/modules/nodereference_url/nodereference_url.module
Normal file
536
sites/all/modules/nodereference_url/nodereference_url.module
Normal file
@@ -0,0 +1,536 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Adds a "URL" widget to the Node Reference field.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
function nodereference_url_theme() {
|
||||
return array(
|
||||
'nodereference_url' => array(
|
||||
'render element' => 'element',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_alter().
|
||||
*/
|
||||
function nodereference_url_form_alter(&$form, &$form_state, $form_id) {
|
||||
if ($form_id == 'field_ui_field_edit_form' && isset($form['#instance']) && $form['#instance']['widget']['type'] == 'nodereference_url') {
|
||||
// Hide settings that don't apply to this widget.
|
||||
$form['field']['cardinality']['#type'] = 'value';
|
||||
$form['instance']['description']['#title'] = t('Fallback widget help text');
|
||||
$form['instance']['description']['#weight'] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_widget_info().
|
||||
*/
|
||||
function nodereference_url_field_widget_info() {
|
||||
return array(
|
||||
'nodereference_url' => array(
|
||||
'label' => t('Reference from URL'),
|
||||
'description' => t('Node Reference calculated from URL'),
|
||||
'field types' => array('node_reference'),
|
||||
'settings' => array(
|
||||
'fallback' => 'select',
|
||||
'node_link' => array(),
|
||||
'edit_fallback' => 0,
|
||||
'autocomplete_match' => 'contains',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_node_view().
|
||||
*/
|
||||
function nodereference_url_node_view($node, $view_mode, $langcode) {
|
||||
$links = nodereference_url_build_all_links($node, $view_mode);
|
||||
$node->content['links']['nodereference_url'] = array(
|
||||
'#theme' => 'links__node__nodereference',
|
||||
'#links' => $links,
|
||||
'#attributes' => array('class' => array('links', 'inline')),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an array of links for nodereference_url widgets that point to this node.
|
||||
*
|
||||
* @param $node
|
||||
* A fully loaded node object.
|
||||
* @param $teaser
|
||||
*
|
||||
* @return
|
||||
* An array of links for use with theme_links().
|
||||
*/
|
||||
function nodereference_url_build_all_links($node, $view_mode) {
|
||||
$links = array();
|
||||
$fields = field_info_instances('node');
|
||||
$instances = array();
|
||||
foreach ($fields as $target_type => $field) {
|
||||
foreach ($field as $field_name => $instance) {
|
||||
if ($instance['widget']['type'] == 'nodereference_url') {
|
||||
$instances[$target_type][$field_name] = $instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($instances as $target_type => $instances_group) {
|
||||
$alt_format = count($instances_group) > 1;
|
||||
foreach ($instances_group as $field_name => $instance) {
|
||||
$link_settings = $instance['widget']['settings']['node_link'];
|
||||
if (isset($link_settings[$view_mode])) {
|
||||
if ($link = nodereference_url_build_link($node, $instance, $view_mode, $alt_format)) {
|
||||
$links[$target_type .'_'. $field_name] = $link;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an individual link.
|
||||
*
|
||||
* Checks to ensure that the current node can be referenced by the field, ensures
|
||||
* the current user has permission to create the field's node type, and builds
|
||||
* the link based on the field's settings.
|
||||
*
|
||||
* @param $node
|
||||
* A fully loaded node object.
|
||||
* @param $instance
|
||||
* A field instance.
|
||||
* @param $teaser
|
||||
* Optional. The current display mode of the node. Defaults to 'full'.
|
||||
* @param $alt_format
|
||||
* Optional. Use the alternative (safer but more verbose) format for
|
||||
* generating the link. Defaults to FALSE.
|
||||
*
|
||||
* @return
|
||||
* An array containing properties to build a single link.
|
||||
*/
|
||||
function nodereference_url_build_link($node, $instance, $view_mode = 'full', $alt_format = FALSE) {
|
||||
$link = array();
|
||||
|
||||
// Load the $field, which contains field-level configuration (such as the
|
||||
// Views and content type settings).
|
||||
$field = field_info_field($instance['field_name']);
|
||||
|
||||
// Check if this widget is using a views listing.
|
||||
if (module_exists('views') && !empty($field['settings']['view']['view_name'])) {
|
||||
// TODO: Remove legacy function after final release of References module.
|
||||
if (function_exists('node_reference_potential_references')) {
|
||||
$referenceable = (bool) node_reference_potential_references($field, array('ids' => array($node->nid), 'limit' => 1));
|
||||
}
|
||||
else {
|
||||
$referenceable = (bool) _node_reference_potential_references($field, '', NULL, array($node->nid), 1);
|
||||
}
|
||||
}
|
||||
// Otherwise restrict by node type.
|
||||
else {
|
||||
$referenceable = !empty($field['settings']['referenceable_types'][$node->type]);
|
||||
}
|
||||
|
||||
if ($referenceable && node_access('create', $instance['bundle'])) {
|
||||
$link_settings = $instance['widget']['settings']['node_link'];
|
||||
if (!empty($link_settings[$view_mode])) {
|
||||
$link['title'] = t($link_settings['title']);
|
||||
$link['query'] = array();
|
||||
|
||||
// Get the first "preferred" path for creating Node Reference links.
|
||||
$link_urls = variable_get('nodereference_url_paths', array('node/add/%type/%nid'));
|
||||
|
||||
// Basic wildcard replacement: %type and %nid.
|
||||
$link_url = $link_urls[0];
|
||||
$link_url = str_replace('%type', str_replace('_', '-', $instance['bundle']), $link_url);
|
||||
if ($alt_format) {
|
||||
// The alternative format is used when there are multiple fields on the
|
||||
// node edit form, so we can't just add an parameter at the end for NID.
|
||||
$link_url = preg_replace('!/%nid$!', '', $link_url);
|
||||
$field_name = str_replace('field_', '', $instance['field_name']);
|
||||
$link['query'][$field_name] = $node->nid;
|
||||
}
|
||||
else {
|
||||
$link_url = str_replace('%nid', $node->nid, $link_url);
|
||||
}
|
||||
$link['href'] = $link_url;
|
||||
|
||||
if (!empty($link_settings['hover_title'])) {
|
||||
$link['attributes']['title'] = t($link_settings['hover_title']);
|
||||
}
|
||||
if (!empty($link_settings['destination'])) {
|
||||
if ($link_settings['destination'] == 'source') {
|
||||
$link['query']['destination'] = isset($_REQUEST['destination']) ? $_REQUEST['destination'] : $_GET['q'];
|
||||
}
|
||||
elseif ($link_settings['destination'] == 'node') {
|
||||
$link['query']['destination'] = drupal_get_path_alias('node/'. $node->nid);
|
||||
}
|
||||
}
|
||||
if (module_exists('og_context')) {
|
||||
// First try to get context based on the current page URL.
|
||||
$group_entity = og_get_context_by_url();
|
||||
|
||||
// Otherwise try getting the context based on the node being referenced.
|
||||
if (!$group_entity) {
|
||||
$group_entity = og_context();
|
||||
}
|
||||
|
||||
if ($group_entity) {
|
||||
$link['query']['gids'] = array($group_entity->gid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for themers to easily create a link.
|
||||
*
|
||||
* This function should be used in custom themes, rather than making manual
|
||||
* links because it first checks a user's access before showing the link. If
|
||||
* the user does not have access to create the node then an empty string will
|
||||
* be returned.
|
||||
*
|
||||
* @param $node
|
||||
* The node object that will be referenced.
|
||||
* @param $field_name
|
||||
* The name of the Node Reference field.
|
||||
* @param $type_name
|
||||
* The name of node type that contains the Node Reference field.
|
||||
* @param $attributes
|
||||
* Optional. An array of additional attributes to add to the link.
|
||||
*/
|
||||
function nodereference_url_create_link($node, $field_name, $type_name, $attributes = array()) {
|
||||
$output = '';
|
||||
$instance = field_info_instance('node', $field_name, $type_name);
|
||||
$instance['widget']['settings']['node_link']['full'] = TRUE;
|
||||
if ($link = nodereference_url_build_link($node, $instance)) {
|
||||
$options = array();
|
||||
$link_attributes = isset($link['attributes']) ? (array) $link['attributes'] : array();
|
||||
$options['attributes'] = $attributes + $link_attributes;
|
||||
if ($link['query']) {
|
||||
$options['query'] = $link['query'];
|
||||
}
|
||||
$output = l($link['title'], $link['href'], $options);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements of hook_elements_info().
|
||||
*
|
||||
* Any FAPI callbacks needed for individual widgets can be declared here,
|
||||
* and the element will be passed to those callbacks for processing.
|
||||
*
|
||||
* Drupal will automatically theme the element using a theme with
|
||||
* the same name as the hook_elements key.
|
||||
*
|
||||
* Autocomplete_path is not used by text_widget but other widgets can use it
|
||||
* (see nodereference and userreference).
|
||||
*/
|
||||
function nodereference_url_element_info() {
|
||||
return array(
|
||||
'nodereference_url' => array(
|
||||
'#input' => TRUE,
|
||||
'#columns' => array('nid'),
|
||||
'#delta' => 0,
|
||||
'#process' => array('_nodereference_url_process'),
|
||||
'#theme' => 'nodereference_url',
|
||||
'#theme_wrappers' => array('form_element'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_widget_settings_form().
|
||||
*/
|
||||
function nodereference_url_field_widget_settings_form($field, $instance) {
|
||||
$widget = $instance['widget'];
|
||||
$defaults = field_info_widget_settings($widget['type']);
|
||||
$settings = array_merge($defaults, $widget['settings']);
|
||||
|
||||
$form = array();
|
||||
if ($widget['type'] == 'nodereference_url') {
|
||||
$form['fallback'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Fallback behavior'),
|
||||
'#options' => array(
|
||||
'autocomplete' => t('Use autocomplete widget'),
|
||||
'select' => t('Use select list widget'),
|
||||
'page_not_found' => t('Display page not found error'),
|
||||
'leave_blank' => t('Leave the field blank'),
|
||||
),
|
||||
'#default_value' => isset($settings['fallback']) ? $settings['fallback'] : 'autocomplete',
|
||||
'#description' => t('If no content is referenced in the URL, determine how the form should be handled.'),
|
||||
'#required' => TRUE,
|
||||
'#element_validate' => array('nodereference_url_fallback_validate'),
|
||||
'#weight' => -11,
|
||||
);
|
||||
$form['autocomplete_match'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Autocomplete matching'),
|
||||
'#default_value' => $settings['autocomplete_match'],
|
||||
'#options' => array(
|
||||
'starts_with' => t('Starts with'),
|
||||
'contains' => t('Contains'),
|
||||
),
|
||||
'#description' => t('Select the method used to collect autocomplete suggestions. <br /> Note that <em>Contains</em> can cause performance issues on sites with thousands of nodes.'),
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
':input[name="instance[widget][settings][fallback]"]' => array('value' => 'autocomplete'),
|
||||
),
|
||||
),
|
||||
'#weight' => -10,
|
||||
);
|
||||
$form['edit_fallback'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Use fallback behavior when editing content'),
|
||||
'#default_value' => isset($settings['edit_fallback']) ? $settings['edit_fallback'] : FALSE,
|
||||
'#weight' => -9,
|
||||
);
|
||||
|
||||
$form['node_link'] = array(
|
||||
'#tree' => TRUE,
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Referenceable node links'),
|
||||
'#element_validate' => array('nodereference_url_node_link_validate'),
|
||||
'#description' => t('These settings will automatically make a link on nodes that can be referenced. Clicking the link will take the user to the new node form and prepopulate the value of this node reference field.'),
|
||||
);
|
||||
$form['node_link']['teaser'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Create link on the teaser view'),
|
||||
'#default_value' => isset($settings['node_link']['teaser']) ? $settings['node_link']['teaser'] : FALSE,
|
||||
);
|
||||
$form['node_link']['full'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Create link on the full view'),
|
||||
'#default_value' => isset($settings['node_link']['full']) ? $settings['node_link']['full'] : TRUE,
|
||||
);
|
||||
$form['node_link']['title'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Link title'),
|
||||
'#default_value' => isset($settings['node_link']['title']) ? $settings['node_link']['title'] : '',
|
||||
'#description' => t('The title is the visible text for the link. This is required if you enable the content links.'),
|
||||
);
|
||||
$form['node_link']['hover_title'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Link hover title'),
|
||||
'#default_value' => isset($settings['node_link']['hover_title']) ? $settings['node_link']['hover_title'] : '',
|
||||
'#description' => t('Text shown while hovering over the link.'),
|
||||
);
|
||||
$form['node_link']['destination'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Return path'),
|
||||
'#default_value' => isset($settings['node_link']['destination']) ? $settings['node_link']['destination'] : 'default',
|
||||
'#options' => array(
|
||||
'default' => t('The new node (no redirect)'),
|
||||
'node' => t('The referenced node'),
|
||||
'source' => t('The previous page'),
|
||||
),
|
||||
'#description' => t('After creating the new node through the link, determine where the user should be redirected.'),
|
||||
);
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_widget_error().
|
||||
*/
|
||||
function nodereference_url_field_widget_error($element, $error, $form, &$form_state) {
|
||||
form_error($element['nid'], $error['message']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Element validation function to ensure invalid options are not selected.
|
||||
*/
|
||||
function nodereference_url_fallback_validate($element, &$form_state) {
|
||||
if ($form_state['values']['instance']['required'] && $form_state['values']['instance']['widget']['settings']['fallback'] == 'leave_blank') {
|
||||
form_error($element, t('The fallback behavior cannot be left blank if this field is also required.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Element validation function that makes title required when creating a link.
|
||||
*/
|
||||
function nodereference_url_node_link_validate($element, &$form_state, $form) {
|
||||
$link_settings = $form_state['values']['instance']['widget']['settings']['node_link'];
|
||||
if (($link_settings['teaser'] || $link_settings['full']) && empty($link_settings['title'])) {
|
||||
form_error($element['title'], t('A link title must be specified if creating links on referenceable content.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_widget_form().
|
||||
*/
|
||||
function nodereference_url_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
|
||||
$field_name = $field['field_name'];
|
||||
$field_name_url = preg_replace('/^field_/', '', $field_name);
|
||||
$referenced_nid = NULL;
|
||||
$fallback = $instance['widget']['settings']['fallback'];
|
||||
|
||||
// Check for an existing NID.
|
||||
if (isset($items[$delta]['nid']) && is_numeric($items[$delta]['nid'])) {
|
||||
$referenced_nid = $items[$delta]['nid'];
|
||||
}
|
||||
// Check in the input array (used during AJAX requests).
|
||||
elseif (!empty($form_state['input'][$field_name][$langcode][$delta]['nid'])) {
|
||||
$referenced_nid = $form_state['input'][$field_name][$langcode][$delta]['nid'];
|
||||
}
|
||||
// Check for a reference in the query string.
|
||||
elseif (isset($_GET[$field_name_url]) && is_numeric($_GET[$field_name_url])) {
|
||||
$referenced_nid = $_GET[$field_name_url];
|
||||
}
|
||||
// Pull from the URL.
|
||||
else {
|
||||
$referenced_nid = nodereference_url_get_nid($field_name);
|
||||
}
|
||||
|
||||
// Check that the NID is a valid reference.
|
||||
if (!empty($referenced_nid)) {
|
||||
// TODO: Remove legacy function after final release of References module.
|
||||
if (function_exists('node_reference_potential_references')) {
|
||||
$reference = node_reference_potential_references($field, array('ids' => array($referenced_nid), 'limit' => 1));
|
||||
}
|
||||
else {
|
||||
$reference = _node_reference_potential_references($field, '', 'equals', array($referenced_nid), 1);
|
||||
}
|
||||
if (empty($reference)) {
|
||||
$referenced_nid = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// If no NID is available or editing this field, use the fallback behavior.
|
||||
if (empty($referenced_nid) || (!empty($instance['widget']['settings']['edit_fallback']) && (empty($form['#node_edit_form']) || !empty($form['#node']->{$field_name}[$langcode])))) {
|
||||
// If not on a node/add page (such as editing a node that does not yet have
|
||||
// a reference), switch to using an autocomplete widget.
|
||||
if (in_array($fallback, array('page_not_found', 'leave_blank')) && nodereference_url_get_nid($field_name) === FALSE) {
|
||||
$fallback = 'autocomplete';
|
||||
}
|
||||
|
||||
// Page not found error.
|
||||
// Check for the form_build_id to prevent throwing a page not found on
|
||||
// manual builds. See http://drupal.org/node/397606.
|
||||
if ($fallback == 'page_not_found') {
|
||||
drupal_set_message(t('To create a new @type, a referenced piece of content must be specified in the link you followed.', array('@type' => $field['bundles']['node'][0])), 'error');
|
||||
drupal_not_found();
|
||||
exit();
|
||||
}
|
||||
// Fallback to select list.
|
||||
elseif ($fallback == 'select') {
|
||||
$element += array(
|
||||
'#type' => 'select',
|
||||
'#default_value' => isset($items[$delta]['nid']) ? $items[$delta]['nid'] : NULL,
|
||||
'#options' => array('' => t('- None -')) + node_reference_options_list($field),
|
||||
);
|
||||
}
|
||||
// Fallback to autocomplete.
|
||||
elseif ($fallback == 'autocomplete') {
|
||||
$element += array(
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => isset($items[$delta]['nid']) ? $items[$delta]['nid'] : NULL,
|
||||
'#autocomplete_path' => 'node_reference/autocomplete/' . $instance['entity_type'] . '/' . $instance['bundle'] . '/' . $field['field_name'],
|
||||
'#value_callback' => 'node_reference_autocomplete_value',
|
||||
'#element_validate' => array('node_reference_autocomplete_validate'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($referenced_nid) && (empty($element['#type']))) {
|
||||
$element += array(
|
||||
'#title' => $instance['label'],
|
||||
'#type' => 'nodereference_url',
|
||||
'#field_name' => $field_name,
|
||||
'#default_value' => $referenced_nid,
|
||||
);
|
||||
}
|
||||
|
||||
return array('nid' => $element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process an individual element.
|
||||
*
|
||||
* Build the form element. When creating a form using FAPI #process,
|
||||
* note that $element['#value'] is already set.
|
||||
*/
|
||||
function _nodereference_url_process($element, $form_state, $form) {
|
||||
if (isset($element['#value']) && is_numeric($element['#value']) && ($node = node_load($element['#value']))) {
|
||||
$element['#display_title'] = check_plain($node->title);
|
||||
}
|
||||
else {
|
||||
$element['#display_title'] = t('Referenced content not found.');
|
||||
}
|
||||
|
||||
$element['nid'] = array(
|
||||
'#type' => 'hidden',
|
||||
'#value' => isset($element['#value']) ? $element['#value'] : $element['#value'],
|
||||
'#parents' => $element['#parents'],
|
||||
);
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the current URL and pull the referenced node from it.
|
||||
*/
|
||||
function nodereference_url_get_nid($field_name) {
|
||||
$add_urls = variable_get('nodereference_url_paths', array('node/add/%type/%nid'));
|
||||
$field_name_url = preg_replace('/^field_/', '', $field_name);
|
||||
$referenced_nid = NULL;
|
||||
|
||||
foreach ($add_urls as $url) {
|
||||
$args = explode('/', $url);
|
||||
foreach ($args as $part => $arg) {
|
||||
// Set the target NID if matching on this part of the URL.
|
||||
if ($arg == '%nid') {
|
||||
$referenced_nid = arg($part);
|
||||
}
|
||||
// Set the target NID based on the field name, allowing for multiple
|
||||
// references in the same URL.
|
||||
elseif ($arg == '%' . $field_name_url) {
|
||||
$referenced_nid = arg($part);
|
||||
}
|
||||
// Skip any other wildcards in the URL.
|
||||
elseif (strpos($arg, '%') === 0) {
|
||||
continue;
|
||||
}
|
||||
// Arguments must line up exactly if they're not a wildcard.
|
||||
elseif (arg($part) != $arg) {
|
||||
$referenced_nid = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($referenced_nid) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $referenced_nid;
|
||||
}
|
||||
|
||||
/**
|
||||
* FAPI theme for an individual elements.
|
||||
*
|
||||
* This theme function controls the display of the widget when an existing item
|
||||
* is being referenced.
|
||||
*
|
||||
* $element['#display_title'] contains the title of the item being referenced.
|
||||
* $element['#field_name'] contains the field name.
|
||||
* $element['#delta] is the position of this element in the group.
|
||||
*/
|
||||
function theme_nodereference_url($variables) {
|
||||
$element = $variables['element'];
|
||||
$output = $element['#display_title'];
|
||||
$output .= drupal_render_children($element);
|
||||
return $output;
|
||||
}
|
Reference in New Issue
Block a user