first import
This commit is contained in:
87
sites/all/modules/references/CHANGELOG.txt
Normal file
87
sites/all/modules/references/CHANGELOG.txt
Normal file
@@ -0,0 +1,87 @@
|
||||
References 7.x-2.0
|
||||
==================
|
||||
|
||||
Note for users upgrading from References 7.x-2.0-beta3:
|
||||
There were a couple changes in the way 'References' views are handled
|
||||
("referenceable nodes/users defined by a view"), which might require
|
||||
double-checking those existing on your site:
|
||||
- The 'label' (node title or user name) is no longer automatically added if not
|
||||
included in the view. If some of your 'References' views currently do not
|
||||
include it, you might want to add it explicitly, else it will no longer appear
|
||||
in the widgets.
|
||||
- The HTML generated by the view is no longer stripped out before being handed
|
||||
to "checkboxes / radios" widgets, thus allowing advanced formatting. You might
|
||||
want to check for Reference views having fields configured to display "as
|
||||
links", since the (probably unwanted) <a> tags generated by Views are not
|
||||
removed anymore.
|
||||
|
||||
Note for users upgrading from CCK D6:
|
||||
- The Refernces project integrates with the content_migrate module present in
|
||||
CCK 7.x-2.x-dev to allow the migration of field definitions and field values
|
||||
from D6 nodereference and userreference fields. Field values are safely
|
||||
migrated, and a best effort is made for the field definitions, but the settings
|
||||
for widgets and formatters might need to be manually checked and adjusted after
|
||||
the migration.
|
||||
- The "referenceable nodes/users defined by a view" feature is now supported
|
||||
through the dedicated 'References' views Display type, as opposed to using the
|
||||
'default' display in D6. A temporary backward-compatibility layer is included
|
||||
and the existing views should keep working as expected (if they have been
|
||||
properly adapted/migrated from D6 themselves), but it is highly recommended to
|
||||
edit them and add an explicit 'References' display - submitting the "field
|
||||
settings" will lose the currently selected view if it doesn't have a
|
||||
'References' display.
|
||||
- The remarks in "Note for users upgrading from beta3" above also apply.
|
||||
|
||||
#1157530 by yched: Fixed node-specific code in references.module code.
|
||||
#1157746 by yched: Fixed 'match' option not working in views.
|
||||
#1149600 by dafeder, yched: fix 'Undefined index error' in
|
||||
_[user|node]_reference_view_settings_validate().
|
||||
#1045019 by Les Lim, Steven Jones, rickvug, and KarenS: Added devel_generate
|
||||
integration.
|
||||
#1230550 by yched: Dispaly a warning about manual Views edits during D6 field
|
||||
migration.
|
||||
#1083902 by dereine, derhasi: Added backreference views relationships.
|
||||
#1157538 by yched: Enhance previews for 'References' views displays.
|
||||
#1094406 by h0tw1r3: Added Account for the 'view own unpublished content' perm
|
||||
when displaying referenced nodes.
|
||||
#1183300 by Pasqualle: Remove maxlength from noderef autocomplete widget.
|
||||
#1236096 by Dave Reid: fix fatal error on prepare_view (followup to #1094406)
|
||||
#1275096 by Scyther, dereine, and jenlampton: Fix column not found error for nid.
|
||||
#1275096 by jboese, dereine: Fix column not found error for nid (take 2).
|
||||
#1341148 by plach: Fix Check views_access() when using Views to get the potential
|
||||
references.
|
||||
#1085576 by henrrrik, stamina, yched: Added "raw ID" and "raw path" formatters.
|
||||
#1051624 by Stalski: Added "rendered user in a given view mode" formatter for
|
||||
user_reference fields.
|
||||
#988856 by Nephele, johnv, rickmanelius, BlakeLucchesi ... : Added Feeds mapper
|
||||
for node_reference and user_reference fields.
|
||||
#1219224 by kunago, michaelfavia, yched: Added support for optgroups in select
|
||||
widget (for referenceable nodes/users provided by a view).
|
||||
#1194086 by Dave Reid, mariagwyn, yched: Display entity labels through entity_label()
|
||||
(formatters only for now)
|
||||
#1288852 by yched: Fixed "Trying to get property of non-object" with fatal error
|
||||
on user_reference fields using a view (when the view does not include the
|
||||
user name as a field).
|
||||
#1378086 by yched: Stop implicitly adding the 'node title / user name' field in
|
||||
Reference views if it is not present in the view definition.
|
||||
#1155946 by yched: allow HTML in "checkboxes / radios" widgets (for lists of
|
||||
referenceable targets generated by views).
|
||||
#1139238 by wondex, s_leu: Add relevant meta data in the 'potential_references'
|
||||
db query to allow smart alteration.
|
||||
|
||||
References 7.x-2.0-beta3
|
||||
========================
|
||||
|
||||
This release primarily aims at facilitating synchronized releases of 3rd party
|
||||
modules making use of the node_reference_potential_references() function.
|
||||
|
||||
#1154998 by yched: Rename _node_reference_potential_references() to
|
||||
node_reference_potential_references().
|
||||
|
||||
References 7.x-2.0-beta2
|
||||
========================
|
||||
|
||||
Initial beta release (starting directly at beta2, the beta1 git tag got borched)
|
||||
|
||||
Note : If you installed a previous 7.x-2.x dev version, it is recommended to
|
||||
clear your sites caches after deploying this release.
|
339
sites/all/modules/references/LICENSE.txt
Normal file
339
sites/all/modules/references/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.
|
36
sites/all/modules/references/README.txt
Normal file
36
sites/all/modules/references/README.txt
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
-- SUMMARY --
|
||||
|
||||
The References project contains straight ports of the node_reference and
|
||||
user_reference modules to the Drupal 7 API.
|
||||
|
||||
For a full description of the module, visit the project page:
|
||||
http://drupal.org/project/references
|
||||
|
||||
-- REQUIREMENTS --
|
||||
|
||||
None.
|
||||
|
||||
CCK for Drupal 7 is /not/ a requirement for these modules.
|
||||
|
||||
-- GOALS AND LIMITATIONS --
|
||||
|
||||
It is not envisioned as a final solution, but as a way to actually deploy
|
||||
Drupal 7 from release day on sites using node and user references much as on
|
||||
Drupal 6, until a native entity relationships Drupal 7 module becomes a usable
|
||||
alternative.
|
||||
|
||||
As of 2010-11-30, is looks like a candidate for that usable alternative might
|
||||
someday be project Relation:
|
||||
http://drupal.org/project/relation
|
||||
|
||||
In short: use these modules now, but be ready to migrate to a different entity
|
||||
referencing solution during the D7 life cycle.
|
||||
|
||||
-- CONTACT --
|
||||
|
||||
Current maintainers:
|
||||
|
||||
* References: Frederic G. MARAND (fgm) - http://drupal.org/user/27985
|
||||
* CCK D7: Yves CHEDEMOIS (yched) - http://drupal.org/user/39567
|
||||
|
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
// $Id: nodereference.devel_generate.inc,v 1.1 2010/01/28 21:06:42 weitzman Exp $
|
||||
|
||||
function node_reference_devel_generate($object, $field, $instance, $bundle) {
|
||||
if (field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_CUSTOM) {
|
||||
return devel_generate_multiple('_node_reference_devel_generate', $object, $field, $instance, $bundle);
|
||||
}
|
||||
else {
|
||||
return _node_reference_devel_generate($object, $field, $instance, $bundle);
|
||||
}
|
||||
}
|
||||
|
||||
function _node_reference_devel_generate($object, $field, $instance, $bundle) {
|
||||
$object_field = array();
|
||||
$allowed_values = node_reference_potential_references($field);
|
||||
// unset($allowed_values[0]);
|
||||
if (!empty($allowed_values)) {
|
||||
// Just pick one of the specified allowed values.
|
||||
$object_field['nid'] = array_rand($allowed_values);
|
||||
}
|
||||
return $object_field;
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
name = Node Reference
|
||||
description = Defines a field type for referencing one node from another.
|
||||
package = Fields
|
||||
core = 7.x
|
||||
dependencies[] = field
|
||||
dependencies[] = references
|
||||
dependencies[] = options
|
||||
files[] = node_reference.test
|
||||
|
||||
; Information added by drupal.org packaging script on 2011-12-22
|
||||
version = "7.x-2.0"
|
||||
core = "7.x"
|
||||
project = "references"
|
||||
datestamp = "1324596643"
|
||||
|
1195
sites/all/modules/references/node_reference/node_reference.module
Normal file
1195
sites/all/modules/references/node_reference/node_reference.module
Normal file
File diff suppressed because it is too large
Load Diff
100
sites/all/modules/references/node_reference/node_reference.test
Normal file
100
sites/all/modules/references/node_reference/node_reference.test
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Initial node_reference tests
|
||||
*/
|
||||
|
||||
/**
|
||||
* Unit tests for referenceability of node types in entity forms.
|
||||
*/
|
||||
class NodeReferenceFormTest extends FieldTestCase {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Node reference',
|
||||
'description' => 'Make sure nodes are referenceable in entity forms.',
|
||||
'group' => 'References',
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp(array('node_reference', 'field_test'));
|
||||
|
||||
$this->langcode = LANGUAGE_NONE;
|
||||
$this->field_name = 'test_node_reference';
|
||||
$this->field = array(
|
||||
'field_name' => $this->field_name,
|
||||
'type' => 'node_reference',
|
||||
'cardinality' => 1,
|
||||
'settings' => array(
|
||||
'referenceable_types' => array_keys(node_type_get_names()),
|
||||
),
|
||||
);
|
||||
$this->field = field_create_field($this->field);
|
||||
$this->instance = array(
|
||||
'field_name' => $this->field_name,
|
||||
'entity_type' => 'test_entity',
|
||||
'bundle' => 'test_bundle',
|
||||
'widget' => array(
|
||||
'type' => 'options_buttons',
|
||||
),
|
||||
);
|
||||
|
||||
$this->instance = field_create_instance($this->instance);
|
||||
|
||||
$this->nodes = array();
|
||||
foreach (node_type_get_names() as $type_name => $type_title) {
|
||||
$this->nodes[$type_name] = $this->drupalCreateNode(array(
|
||||
'type' => $type_name,
|
||||
'title' => $this->randomName(8),
|
||||
));
|
||||
$this->pass(t('Created %type node %nid: %title', array(
|
||||
'%type' => $type_name,
|
||||
'%nid' => $this->nodes[$type_name]->nid,
|
||||
'%title' => $this->nodes[$type_name]->title,
|
||||
)), 'destination creation');
|
||||
}
|
||||
}
|
||||
|
||||
function runReferenceableNodeTest($allowed, $group) {
|
||||
field_update_field(array(
|
||||
'field_name' => $this->field_name,
|
||||
'settings' => array('referenceable_types' => array_keys($allowed)),
|
||||
));
|
||||
$entity = field_test_create_stub_entity();
|
||||
$form = drupal_get_form('field_test_entity_form', $entity);
|
||||
$options = $form[$this->field_name][$this->langcode]['#options'];
|
||||
$this->assertTrue(isset($options['_none']), t('Empty choice offered for reference'), $group);
|
||||
unset($options['_none']);
|
||||
foreach ($this->nodes as $node) {
|
||||
if (isset($allowed[$node->type])) {
|
||||
$this->assertTrue(isset($options[$node->nid]),
|
||||
t('Node of type @type is referenceable', array('@type' => $node->type)),
|
||||
$group);
|
||||
}
|
||||
else {
|
||||
$this->assertFalse(isset($options[$node->nid]),
|
||||
t('Node of type @type is not referenceable', array('@type' => $node->type)),
|
||||
$group);
|
||||
}
|
||||
unset($options[$node->nid]);
|
||||
}
|
||||
$this->assertTrue(empty($options), t('No extra choice is referenceable'), $group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test unlimited referencing
|
||||
*/
|
||||
function testReferenceableNodeTypesAll() {
|
||||
$allowed = node_type_get_names();
|
||||
$this->runReferenceableNodeTest($allowed, t('Unimited referencing'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test referencing a limited list of node types
|
||||
*/
|
||||
function testReferenceableNodeTypesOne() {
|
||||
$allowed = array_slice(node_type_get_names(), 0, 1, TRUE);
|
||||
$this->runReferenceableNodeTest($allowed, t('Limited referencing'));
|
||||
}
|
||||
}
|
305
sites/all/modules/references/references.feeds.inc
Normal file
305
sites/all/modules/references/references.feeds.inc
Normal file
@@ -0,0 +1,305 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Mapper that handles any fields added by the References module (node_reference, user_reference)
|
||||
*
|
||||
* Code is effectively a port of the mapper_for_nodereference_field patch to drupal 7, and borrows
|
||||
* heavily from the nodereference patch
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_feeds_parser_sources_alter().
|
||||
*/
|
||||
function node_reference_feeds_parser_sources_alter(&$sources, $content_type) {
|
||||
if (!empty($content_type)) {
|
||||
$fields = field_info_fields();
|
||||
foreach ($fields as $field) {
|
||||
if ($field['type'] == 'node_reference' && isset($field['bundles']['node']) && in_array($content_type, $field['bundles']['node'])) {
|
||||
$sources['parent:node_reference:'. $field['field_name']] = array(
|
||||
'name' => t('Feed node: Node Reference (nid): @field_name', array('@field_name' => $field['field_name'])),
|
||||
'description' => t('Node References from the parent feed node.'),
|
||||
'callback' => 'node_reference_feeds_get_source',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $sources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for mapping parent node references to child node reference values.
|
||||
*
|
||||
* @param $source
|
||||
* A FeedsSource object.
|
||||
* @param $result
|
||||
* FeedsParserResult object.
|
||||
* @param $key
|
||||
* The key as defined in the _feeds_parser_sources_alter() hook defined above.
|
||||
* @return array
|
||||
* The node ids that the parent node references.
|
||||
*/
|
||||
function node_reference_feeds_get_source(FeedsSource $source, FeedsParserResult $result, $key) {
|
||||
if ($node = node_load($source->feed_nid)) {
|
||||
$results = array();
|
||||
$field = substr($key, 22);
|
||||
if (!empty($node->{$field}['und'])) {
|
||||
foreach ($node->{$field}['und'] as $delta => $value) {
|
||||
$results[] = $value['nid'];
|
||||
}
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_feeds_processor_targets_alter() for node_reference fields
|
||||
*
|
||||
* @see FeedsNodeProcessor::getMappingTargets().
|
||||
*/
|
||||
function node_reference_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) {
|
||||
foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) {
|
||||
$info = field_info_field($name);
|
||||
if ($info['type'] == 'node_reference') {
|
||||
|
||||
$targets[$name . ':title'] = array(
|
||||
'name' => $instance['label'] . t(' (Node reference by node title)'),
|
||||
'callback' => 'references_feeds_set_target',
|
||||
'description' => t('The @label field of the node matched by node title.', array('@label' => $instance['label'])),
|
||||
'real_target' => $name);
|
||||
|
||||
$targets[$name . ':nid'] = array(
|
||||
'name' => $instance['label'] . t(' (Node reference by node ID)'),
|
||||
'callback' => 'references_feeds_set_target',
|
||||
'description' => t('The @label field of the node matched by node ID.', array('@label' => $instance['label'])),
|
||||
'real_target' => $name);
|
||||
|
||||
$targets[$name . ':url'] = array(
|
||||
'name' => $instance['label'] . t(' (Node reference by Feeds URL)'),
|
||||
'callback' => 'references_feeds_set_target',
|
||||
'description' => t('The @label field of the node matched by Feeds URL.', array('@label' => $instance['label'])),
|
||||
'real_target' => $name);
|
||||
|
||||
$targets[$name . ':guid'] = array(
|
||||
'name' => $instance['label'] . t(' (Node reference by Feeds GUID)'),
|
||||
'callback' => 'references_feeds_set_target',
|
||||
'description' => t('The @label field of the node matched by Feeds GUID.', array('@label' => $instance['label'])),
|
||||
'real_target' => $name);
|
||||
|
||||
$targets[$name . ':title:duplicates'] = array(
|
||||
'name' => $instance['label'] . t(' (Node reference by node title) -- allow duplicate nodes'),
|
||||
'callback' => 'references_feeds_set_target',
|
||||
'description' => t('The @label field of the node matched by node title. This target allows duplicate nodes (nodes can appear more than once in a field).', array('@label' => $instance['label'])),
|
||||
'real_target' => $name);
|
||||
|
||||
$targets[$name . ':nid:duplicates'] = array(
|
||||
'name' => $instance['label'] . t(' (Node reference by node ID) -- allow duplicate nodes'),
|
||||
'callback' => 'references_feeds_set_target',
|
||||
'description' => t('The @label field of the node matched by node ID. This target allows duplicate nodes (nodes can appear more than once in a field).', array('@label' => $instance['label'])),
|
||||
'real_target' => $name);
|
||||
|
||||
$targets[$name . ':url:duplicates'] = array(
|
||||
'name' => $instance['label'] . t(' (Node reference by Feeds URL) -- allow duplicate nodes'),
|
||||
'callback' => 'references_feeds_set_target',
|
||||
'description' => t('The @label field of the node matched by Feeds URL.', array('@label' => $instance['label'])),
|
||||
'real_target' => $name);
|
||||
|
||||
$targets[$name . ':guid:duplicates'] = array(
|
||||
'name' => $instance['label'] . t(' (Node reference by Feeds GUID) -- allow duplicate nodes'),
|
||||
'callback' => 'references_feeds_set_target',
|
||||
'description' => t('The @label field of the node matched by Feeds GUID.', array('@label' => $instance['label'])),
|
||||
'real_target' => $name);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Implements hook_feeds_processor_targets_alter() for user_reference fields
|
||||
*
|
||||
* @see FeedsNodeProcessor::getMappingTargets().
|
||||
*
|
||||
*/
|
||||
function user_reference_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) {
|
||||
foreach (field_info_instances($entity_type, $bundle_name) as $name => $instance) {
|
||||
$info = field_info_field($name);
|
||||
if ($info['type'] == 'user_reference') {
|
||||
|
||||
$targets[$name . ':name'] = array(
|
||||
'name' => $instance['label'] . t(' (User reference by user name)'),
|
||||
'callback' => 'references_feeds_set_target',
|
||||
'description' => t('The @label field of the user matched by user name. ', array('@label' => $instance['label'])),
|
||||
'real_target' => $name);
|
||||
|
||||
$targets[$name . ':uid'] = array(
|
||||
'name' => $instance['label'] . t(' (User reference by user ID)'),
|
||||
'callback' => 'references_feeds_set_target',
|
||||
'description' => t('The @label field of the user matched by user ID.', array('@label' => $instance['label'])),
|
||||
'real_target' => $name);
|
||||
|
||||
$targets[$name . ':url'] = array(
|
||||
'name' => $instance['label'] . t(' (User reference by Feeds URL)'),
|
||||
'callback' => 'references_feeds_set_target',
|
||||
'description' => t('The @label field of the node matched by Feeds URL.', array('@label' => $instance['label'])),
|
||||
'real_target' => $name);
|
||||
|
||||
$targets[$name . ':guid'] = array(
|
||||
'name' => $instance['label'] . t(' (User reference by Feeds GUID)'),
|
||||
'callback' => 'references_feeds_set_target',
|
||||
'description' => t('The @label field of the node matched by Feeds GUID.', array('@label' => $instance['label'])),
|
||||
'real_target' => $name);
|
||||
|
||||
$targets[$name . ':name:duplicates'] = array(
|
||||
'name' => $instance['label'] . t(' (User reference by user name) -- allow duplicate users'),
|
||||
'callback' => 'references_feeds_set_target',
|
||||
'description' => t('The @label field of the user matched by user name. This target allows duplicate users (users can appear more than once in a field).', array('@label' => $instance['label'])),
|
||||
'real_target' => $name);
|
||||
|
||||
$targets[$name . ':uid:duplicates'] = array(
|
||||
'name' => $instance['label'] . t(' (User reference by user ID) -- allow duplicate users'),
|
||||
'callback' => 'references_feeds_set_target',
|
||||
'description' => t('The @label field of the user matched by user ID. This target allows duplicate users (users can appear more than once in a field).', array('@label' => $instance['label'])),
|
||||
'real_target' => $name);
|
||||
|
||||
$targets[$name . ':url:duplicates'] = array(
|
||||
'name' => $instance['label'] . t(' (User reference by Feeds URL) -- allow duplicate users'),
|
||||
'callback' => 'references_feeds_set_target',
|
||||
'description' => t('The @label field of the node matched by Feeds URL.', array('@label' => $instance['label'])),
|
||||
'real_target' => $name);
|
||||
|
||||
$targets[$name . ':guid:duplicates'] = array(
|
||||
'name' => $instance['label'] . t(' (User reference by Feeds GUID) -- allow duplicate users'),
|
||||
'callback' => 'references_feeds_set_target',
|
||||
'description' => t('The @label field of the node matched by Feeds GUID.', array('@label' => $instance['label'])),
|
||||
'real_target' => $name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for mapping both node reference and user_reference fields
|
||||
*
|
||||
* Implementation of hook_feeds_set_target().
|
||||
*
|
||||
* @param $source
|
||||
* A FeedsSource object.
|
||||
* @param $entity
|
||||
* The entity to map to.
|
||||
* @param $target
|
||||
* The target key on $entity to map to.
|
||||
* @param $value
|
||||
* The value to map. Can be an array or a string.
|
||||
*/
|
||||
function references_feeds_set_target($source, $entity, $target, $value) {
|
||||
if (empty($value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle comma delimited or non-multiple values.
|
||||
if (!is_array($value)) {
|
||||
$value = array($value);
|
||||
}
|
||||
|
||||
// Determine the field we are matching against, and whether duplicates are allowed.
|
||||
$target_info = explode(':', $target, 3);
|
||||
if (sizeof($target_info) == 3) {
|
||||
list($target, $match_key, $duplicates) = $target_info;
|
||||
}
|
||||
else {
|
||||
list($target, $match_key) = $target_info;
|
||||
}
|
||||
|
||||
// Load field definition.
|
||||
$info = field_info_field($target);
|
||||
// Parameters to handle differences between node references and user references
|
||||
if ($info['type'] == 'user_reference') {
|
||||
$idname = 'uid';
|
||||
$typename = 'user';
|
||||
$validate_function = 'user_reference_potential_references';
|
||||
}
|
||||
else {
|
||||
$idname = 'nid';
|
||||
$typename = 'node';
|
||||
$validate_function = 'node_reference_potential_references';
|
||||
}
|
||||
|
||||
$field = isset($entity->$target) ? $entity->$target : array();
|
||||
if (!isset($field['und'])) {
|
||||
$field['und'] = array();
|
||||
}
|
||||
|
||||
// Match values against nodes and add to field.
|
||||
foreach ($value as $v) {
|
||||
// Create options.
|
||||
$options = array(
|
||||
'string' => $v,
|
||||
'match' => 'equals',
|
||||
'ids' => array(),
|
||||
'limit' => 1,
|
||||
);
|
||||
|
||||
switch ($match_key) {
|
||||
case 'title':
|
||||
case 'name':
|
||||
// Validate node title or user name.
|
||||
if ((is_string($options['string']) && $options['string'] != '') || is_numeric($options['string'])) {
|
||||
// Lookup potential exact matches for the value (limit to one result).
|
||||
$matches = $validate_function($info,$options);
|
||||
// Use the first element of the potential matches.
|
||||
$options['ids']= key($matches);
|
||||
}
|
||||
|
||||
// Alert if no match is found.
|
||||
if (empty($options['ids'])) {
|
||||
drupal_set_message(t('%title does not match an existing '.$typename, array('%title' => $options['string'])));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'nid':
|
||||
case 'uid':
|
||||
// Make sure it is a positive integer.
|
||||
if ((is_int($options['string']) || ctype_digit($options['string'])) && $options['string'] > 0 && $options['string'] !== '') {
|
||||
// Make sure it is a valid node id or user id for this field.
|
||||
$matches = $validate_function($info, array($options['string']));
|
||||
foreach ($matches as $k => $v) {
|
||||
if ($options['string'] == $k) {
|
||||
$options['ids'] = $k;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Alert if no match is found.
|
||||
if (empty($options['ids'])) {
|
||||
drupal_set_message(t('%id is not a valid '.$typename.' id for this field.', array('%id' => $options['string'])));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'guid':
|
||||
case 'url':
|
||||
// get the value from table feeds-item.
|
||||
$result = db_query('SELECT f.entity_id FROM {feeds_item} f WHERE f.'.$match_key.' = :v', array( ':v' => $v) );
|
||||
$options['ids'] = $result->fetchField();
|
||||
|
||||
// Alert if no match is found.
|
||||
if (empty($options['ids'])) {
|
||||
drupal_set_message(t('%id is not a valid '.$typename.' id for this field.', array('%id' => $v)));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (!empty($options['ids'])) {
|
||||
$reference = array($idname => $options['ids']);
|
||||
if (!empty($duplicates)) {
|
||||
// Add the reference, ignoring duplicates.
|
||||
$field['und'][] = $reference;
|
||||
}
|
||||
else if (!in_array($reference, $field['und'])) {
|
||||
// Add the reference only if it doesn't already exist.
|
||||
$field['und'][] = $reference;
|
||||
}
|
||||
|
||||
if ($info['cardinality'] == 1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$entity->{$target} = $field;
|
||||
}
|
18
sites/all/modules/references/references.info
Normal file
18
sites/all/modules/references/references.info
Normal file
@@ -0,0 +1,18 @@
|
||||
name = References
|
||||
description = Defines common base features for the various reference field types.
|
||||
package = Fields
|
||||
core = 7.x
|
||||
dependencies[] = field
|
||||
dependencies[] = options
|
||||
files[] = views/references_handler_relationship.inc
|
||||
files[] = views/references_handler_argument.inc
|
||||
files[] = views/references_plugin_display.inc
|
||||
files[] = views/references_plugin_style.inc
|
||||
files[] = views/references_plugin_row_fields.inc
|
||||
|
||||
; Information added by drupal.org packaging script on 2011-12-22
|
||||
version = "7.x-2.0"
|
||||
core = "7.x"
|
||||
project = "references"
|
||||
datestamp = "1324596643"
|
||||
|
208
sites/all/modules/references/references.module
Normal file
208
sites/all/modules/references/references.module
Normal file
@@ -0,0 +1,208 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Defines common base features for the various reference field types.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Menu access callback for reference autocomplete paths.
|
||||
*
|
||||
* Check for both 'edit' and 'view' access in the unlikely event
|
||||
* a user has edit but not view access.
|
||||
*/
|
||||
function reference_autocomplete_access($entity_type, $bundle, $field_name, $entity = NULL, $account = NULL) {
|
||||
return user_access('access content', $account)
|
||||
&& ($field = field_info_field($field_name))
|
||||
&& field_info_instance($entity_type, $field_name, $bundle)
|
||||
&& field_access('view', $field, $entity_type, $entity, $account)
|
||||
&& field_access('edit', $field, $entity_type, $entity, $account);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_init().
|
||||
*/
|
||||
function references_init() {
|
||||
// Include feeds.module integration.
|
||||
if (module_exists('feeds')) {
|
||||
module_load_include('inc','references','references.feeds');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_views_api().
|
||||
*/
|
||||
function references_views_api() {
|
||||
return array(
|
||||
'api' => 3,
|
||||
'path' => drupal_get_path('module', 'references') . '/views',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_views_plugins().
|
||||
*
|
||||
* Defines some plugins used by the Views modes for
|
||||
* user_reference.
|
||||
*/
|
||||
function references_views_plugins() {
|
||||
$plugins = array(
|
||||
'display' => array(
|
||||
'references' => array(
|
||||
'title' => t('References'),
|
||||
'admin' => t('References'),
|
||||
'help' => 'Selects referenceable entities for a reference field (node_reference, user_reference...)',
|
||||
'handler' => 'references_plugin_display',
|
||||
'uses hook menu' => FALSE,
|
||||
'use ajax' => FALSE,
|
||||
'use pager' => FALSE,
|
||||
'accept attachments' => FALSE,
|
||||
// Custom property, used with views_get_applicable_views() to retrieve
|
||||
// all views with a 'References' display.
|
||||
'references display' => TRUE,
|
||||
),
|
||||
),
|
||||
'style' => array(
|
||||
'references_style' => array(
|
||||
'title' => t('References list'),
|
||||
'help' => 'Returns results as a PHP array of names + rendered rows.',
|
||||
'handler' => 'references_plugin_style',
|
||||
'theme' => 'views_view_unformatted',
|
||||
'uses row plugin' => TRUE,
|
||||
'uses fields' => TRUE,
|
||||
'uses options' => TRUE,
|
||||
'uses grouping' => TRUE,
|
||||
'type' => 'references',
|
||||
'even empty' => TRUE,
|
||||
),
|
||||
),
|
||||
'row' => array(
|
||||
'references_fields' => array(
|
||||
'title' => t('Inline fields'),
|
||||
'help' => t('Displays the fields with an optional template.'),
|
||||
'handler' => 'references_plugin_row_fields',
|
||||
'theme' => 'views_view_fields',
|
||||
'theme path' => drupal_get_path('module', 'views') . '/theme',
|
||||
'theme file' => 'theme.inc',
|
||||
'uses fields' => TRUE,
|
||||
'uses options' => TRUE,
|
||||
'type' => 'references',
|
||||
),
|
||||
),
|
||||
);
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the list of views with a 'references' display, in a format suitable for a 'select' form element..
|
||||
*
|
||||
* @param $entity_type
|
||||
* The entity type.
|
||||
*
|
||||
* @return
|
||||
* An array of eligible views displays.
|
||||
*/
|
||||
function references_get_views_options($entity_type) {
|
||||
// Filter views that contain a 'references' display. This actually returns a
|
||||
// list of displays (the same view appears several times).
|
||||
$displays = views_get_applicable_views('references display');
|
||||
|
||||
// Filter views that list the entity type we want, and group the separate
|
||||
// displays by view.
|
||||
$entity_info = entity_get_info($entity_type);
|
||||
$options = array();
|
||||
foreach ($displays as $data) {
|
||||
list($view, $display_id) = $data;
|
||||
if ($view->base_table == $entity_info['base table']) {
|
||||
$options[$view->name . ':' . $display_id] = $view->name .' - ' . $view->display[$display_id]->display_title;
|
||||
}
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves an array of candidate referenceable entities, defined by a view.
|
||||
*
|
||||
* @param $entity_type
|
||||
* The entity type.
|
||||
* @param $view_name
|
||||
* The name of the view.
|
||||
* @param $display_name
|
||||
* The name of the view's display. This has to be a 'References' display.
|
||||
* @param $args
|
||||
* The array of arguments ("contextual filters") for the view.
|
||||
* @param $options
|
||||
* Array of options to limit the scope of the returned list. This parameter
|
||||
* is similar to the $options parameter for
|
||||
* node_reference_potential_references(). An additional key is required:
|
||||
* - title_field: the name of the column holding entities 'titles' within the
|
||||
* entity base table.
|
||||
*
|
||||
* @return
|
||||
* An array of entities, in the format expected by
|
||||
* node_reference_potential_references().
|
||||
*
|
||||
* @see node_reference_potential_references()
|
||||
* @see _node_reference_potential_references_views()
|
||||
*/
|
||||
function references_potential_references_view($entity_type, $view_name, $display_name, $args, $options) {
|
||||
$entity_info = entity_get_info($entity_type);
|
||||
|
||||
// Check that the view is valid and the display still exists.
|
||||
$view = views_get_view($view_name);
|
||||
if (!$view || $view->base_table != $entity_info['base table'] || !isset($view->display[$display_name])) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// If we have no access to the View an empty result should be returned to
|
||||
// avoid triggering the fallback results.
|
||||
if (!$view->access(array($display_name))) {
|
||||
return array();
|
||||
}
|
||||
|
||||
// Temporary backwards compatibility for fields migrated from CCK D6: accept
|
||||
// 'default' display, but dynamically add a 'references' display out of it.
|
||||
if ($display_name == 'default') {
|
||||
$display_name = $view->add_display('references');
|
||||
}
|
||||
|
||||
$view->set_display($display_name);
|
||||
|
||||
// @todo From merlinofchaos on IRC : arguments using summary view can defeat
|
||||
// the style setting.
|
||||
// We might also need to check if there's an argument, and set its
|
||||
// style_plugin as well.
|
||||
|
||||
// Set additional options to let references_plugin_display::query() narrow
|
||||
// the results.
|
||||
$references_options = array(
|
||||
'ids' => $options['ids'],
|
||||
'title_field' => $options['title_field'],
|
||||
'string' => $options['string'],
|
||||
'match' => $options['match'],
|
||||
);
|
||||
$view->display_handler->set_option('references_options', $references_options);
|
||||
|
||||
// We need the title field for autocomplete widgets, so add it (hidden) if not
|
||||
// present.
|
||||
$fields = $view->get_items('field', $display_name);
|
||||
if (!isset($fields[$options['title_field']])) {
|
||||
$label_options = array(
|
||||
'exclude' => 1,
|
||||
);
|
||||
$view->add_item($display_name, 'field', $entity_info['base table'], $options['title_field'], $label_options);
|
||||
}
|
||||
|
||||
// Limit result set size.
|
||||
$limit = !empty($options['limit']) ? $options['limit'] : 0;
|
||||
$view->display_handler->set_option('pager', array('type' => 'some', 'options' => array('items_per_page' => $limit)));
|
||||
|
||||
// Make sure the query is not cached
|
||||
$view->is_cacheable = FALSE;
|
||||
|
||||
// Get the results.
|
||||
$results = $view->execute_display($display_name, $args);
|
||||
|
||||
return $results;
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
function user_reference_devel_generate($object, $field, $instance, $bundle) {
|
||||
if (field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_CUSTOM) {
|
||||
return devel_generate_multiple('_user_reference_devel_generate', $object, $field);
|
||||
}
|
||||
else {
|
||||
return _user_reference_devel_generate($object, $field);
|
||||
}
|
||||
}
|
||||
|
||||
function _user_reference_devel_generate($object, $field) {
|
||||
$object_field = array();
|
||||
$allowed_values = user_reference_potential_references($field);
|
||||
if (isset($allowed_values[0])) {
|
||||
unset($allowed_values[0]);
|
||||
}
|
||||
if (!empty($allowed_values)) {
|
||||
// Just pick one of the specified allowed values.
|
||||
$object_field['uid'] = array_rand($allowed_values);
|
||||
}
|
||||
return $object_field;
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
name = User Reference
|
||||
description = Defines a field type for referencing a user from a node.
|
||||
package = Fields
|
||||
core = 7.x
|
||||
dependencies[] = field
|
||||
dependencies[] = references
|
||||
dependencies[] = options
|
||||
|
||||
; Information added by drupal.org packaging script on 2011-12-22
|
||||
version = "7.x-2.0"
|
||||
core = "7.x"
|
||||
project = "references"
|
||||
datestamp = "1324596643"
|
||||
|
1221
sites/all/modules/references/user_reference/user_reference.module
Normal file
1221
sites/all/modules/references/user_reference/user_reference.module
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Placeholder for the development of user_reference tests
|
||||
*/
|
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provide handler to replace reference with title.
|
||||
*/
|
||||
class references_handler_argument extends views_handler_argument_numeric {
|
||||
|
||||
/**
|
||||
* Use entity title for % placeholders in argument titles.
|
||||
*/
|
||||
function title_query() {
|
||||
// Use the same table and field than those used for summary lists
|
||||
// ('name table', 'name field').
|
||||
$table_data = views_fetch_data($this->name_table);
|
||||
$table_info = $table_data['table']['join'][$this->table];
|
||||
$table = $table_info['table'];
|
||||
$key_field = $table_info['field'];
|
||||
$title_field = $this->name_field;
|
||||
|
||||
$results = db_select($table, 'base_table')
|
||||
->fields('base_table', array($key_field, $title_field))
|
||||
->condition("base_table.$key_field", $this->value)
|
||||
->execute()
|
||||
// Grab results as 'key => title' array.
|
||||
->fetchAllKeyed();
|
||||
|
||||
// Sanitize titles and put them back in the correct order in an unkeyed
|
||||
// array.
|
||||
$titles = array();
|
||||
foreach ($this->value as $key) {
|
||||
if (isset($results[$key])) {
|
||||
$titles[] = check_plain($results[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return $titles;
|
||||
}
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provide relationship handler for reference fields.
|
||||
*/
|
||||
class references_handler_relationship extends views_handler_relationship {
|
||||
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['delta'] = array('default' => -1);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a delta selector for multiple fields.
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$field = field_info_field($this->definition['field_name']);
|
||||
|
||||
// Only add the delta selector if the field is multiple.
|
||||
if ($field['cardinality']) {
|
||||
$max_delta = ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED) ? 10 : $field['cardinality'];
|
||||
|
||||
$options = array('-1' => t('All'));
|
||||
for ($i = 0; $i < $max_delta; $i++) {
|
||||
$options[$i] = $i + 1;
|
||||
}
|
||||
$form['delta'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => $options,
|
||||
'#default_value' => $this->options['delta'],
|
||||
'#title' => t('Delta'),
|
||||
'#description' => t('The delta allows you to select which item in a multiple value field to key the relationship off of. Select "1" to use the first item, "2" for the second item, and so on. If you select "All", each item in the field will create a new row, which may appear to cause duplicates.'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function ensure_my_table() {
|
||||
$field = field_info_field($this->definition['field_name']);
|
||||
|
||||
if (!isset($this->table_alias)) {
|
||||
$join = $this->get_join();
|
||||
if ($this->options['delta'] != -1 && $field['cardinality']) {
|
||||
$join->extra[] = array(
|
||||
'field' => 'delta',
|
||||
'value' => $this->options['delta'],
|
||||
'numeric' => TRUE,
|
||||
);
|
||||
}
|
||||
$this->table_alias = $this->query->add_table($this->table, $this->relationship, $join);
|
||||
}
|
||||
return $this->table_alias;
|
||||
}
|
||||
}
|
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Handler for references_plugin_display.
|
||||
*/
|
||||
class references_plugin_display extends views_plugin_display {
|
||||
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
// Force the style plugin to 'references_style' and the row plugin to
|
||||
// 'fields'.
|
||||
$options['style_plugin']['default'] = 'references_style';
|
||||
$options['defaults']['default']['style_plugin'] = FALSE;
|
||||
$options['defaults']['default']['style_options'] = FALSE;
|
||||
$options['row_plugin']['default'] = 'references_fields';
|
||||
$options['defaults']['default']['row_plugin'] = FALSE;
|
||||
$options['defaults']['default']['row_options'] = FALSE;
|
||||
|
||||
// Set the display title to an empty string (not used in this display type).
|
||||
$options['title']['default'] = '';
|
||||
$options['defaults']['default']['title'] = FALSE;
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
function get_style_type() {
|
||||
return 'references';
|
||||
}
|
||||
|
||||
function execute() {
|
||||
return $this->view->render($this->display->id);
|
||||
}
|
||||
|
||||
function render() {
|
||||
if (!empty($this->view->result) || !empty($this->view->style_plugin->definition['even empty'])) {
|
||||
return $this->view->style_plugin->render($this->view->result);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function uses_exposed() {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
function query() {
|
||||
$options = $this->get_option('references_options');
|
||||
|
||||
// Play nice with View UI 'preview' : if the view is not executed through
|
||||
// _*_reference_potential_references_views(), don't alter the query.
|
||||
if (empty($options)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure the id field is included in the results, and save its alias
|
||||
// so that references_plugin_style can retrieve it.
|
||||
$this->id_field_alias = $this->view->query->add_field($this->view->base_table, $this->view->base_field);
|
||||
|
||||
// Restrict on the incoming string, or incoming ids.
|
||||
if ($options['string'] !== '') {
|
||||
switch ($options['match']) {
|
||||
case 'equals':
|
||||
$operator = '=';
|
||||
$value = $options['string'];
|
||||
break;
|
||||
|
||||
case 'starts_with':
|
||||
$operator = 'LIKE';
|
||||
$value = db_like($options['string']) . '%';
|
||||
break;
|
||||
|
||||
case 'contains':
|
||||
default:
|
||||
$operator = 'LIKE';
|
||||
$value = '%' . db_like($options['string']) . '%';
|
||||
break;
|
||||
}
|
||||
|
||||
$table_alias = $this->view->query->ensure_table($this->view->base_table);
|
||||
$this->view->query->add_where(NULL, $table_alias . '.' . $options['title_field'], $value, $operator);
|
||||
}
|
||||
elseif ($options['ids']) {
|
||||
$table_alias = $this->view->query->ensure_table($this->view->base_table);
|
||||
$this->view->query->add_where(NULL, $table_alias . '.' . $this->view->base_field, $options['ids'], 'IN');
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Handler for references_plugin_row_fields.
|
||||
*/
|
||||
class references_plugin_row_fields extends views_plugin_row_fields {
|
||||
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['separator'] = array('default' => '-');
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a form for setting options.
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
// Expand the description of the 'Inline field' checkboxes.
|
||||
$form['inline']['#description'] .= '<br>' . t("<strong>Note:</strong> In 'References' displays, all fields will be displayed inline unless an explicit selection of inline fields is made here." );
|
||||
}
|
||||
|
||||
function pre_render($row) {
|
||||
// Force all fields to be inline by default.
|
||||
if (empty($this->options['inline'])) {
|
||||
$fields = $this->view->get_items('field', $this->display->id);
|
||||
$this->options['inline'] = drupal_map_assoc(array_keys($fields));
|
||||
}
|
||||
|
||||
return parent::pre_render($row);
|
||||
}
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Handler for references_plugin_style.
|
||||
*/
|
||||
class references_plugin_style extends views_plugin_style {
|
||||
function render() {
|
||||
$options = $this->display->handler->get_option('references_options');
|
||||
|
||||
// Play nice with View UI 'preview' : if the view is not executed through
|
||||
// _*_reference_potential_references_views(), just display the HTML.
|
||||
if (empty($options)) {
|
||||
return parent::render();
|
||||
}
|
||||
|
||||
$title_field = $options['title_field'];
|
||||
|
||||
// Group the rows according to the grouping field, if specified.
|
||||
$sets = $this->render_grouping($this->view->result, $this->options['grouping']);
|
||||
|
||||
// Grab the alias of the 'id' field added by references_plugin_display.
|
||||
$id_field_alias = $this->display->handler->id_field_alias;
|
||||
|
||||
$results = array();
|
||||
$this->view->row_index = 0;
|
||||
foreach ($sets as $title => $records) {
|
||||
foreach ($records as $label => $values) {
|
||||
// Render the row.
|
||||
$rendered = $this->row_plugin->render($values);
|
||||
// Remove linebreaks and extra spaces introduced by templates.
|
||||
$rendered = preg_replace('/\s+/', ' ', trim($rendered));
|
||||
|
||||
// Collect the rendered row, and the raw title value.
|
||||
$results[$values->{$id_field_alias}] = array(
|
||||
'rendered' => $rendered,
|
||||
'group' => $title,
|
||||
'title' => $this->view->field[$title_field]->get_value($values),
|
||||
);
|
||||
|
||||
$this->view->row_index++;
|
||||
}
|
||||
}
|
||||
unset($this->view->row_index);
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user