first import
This commit is contained in:
69
sites/all/modules/custom_formatters/CHANGELOG.txt
Normal file
69
sites/all/modules/custom_formatters/CHANGELOG.txt
Normal file
@@ -0,0 +1,69 @@
|
||||
Custom Formatters 7.x-2.2, 2012-07-04
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
- Fixed issue with Form builder.
|
||||
- Added support for the Entity token module.
|
||||
- Added Image styles and Token tree Form builder elements.
|
||||
- Added force wrap style to preview debug.
|
||||
- Added Formatter Settings column to export UI.
|
||||
- Added Coder Review integration.
|
||||
- Updated preview integration.
|
||||
- Updated render array/multifield support.
|
||||
- Updated example PHP formatter.
|
||||
- Updated raw HTML debug code.
|
||||
- Updated documentation.
|
||||
- Removed Token module dependency for HTML + Token formatter engine.
|
||||
- Removed obsolete token integration.
|
||||
|
||||
|
||||
Custom Formatters 7.x-2.1, 2012-06-17
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
- #1562472: Fixed issue with menu on export page.
|
||||
- #1519918: Fixed issue with empty tokens.
|
||||
- #1498584: Fixed coder issues.
|
||||
- #1360388: Added support for Render arrays in PHP formatters.
|
||||
- #1350306: Fixed issue with preview.
|
||||
- #1324886: Fixed entity token support.
|
||||
- #1231096: Fixed Insert module integration.
|
||||
- #1198732: Fixed issue with preview when no entities exist.
|
||||
- #1184900 by mbopp: Fixed issue with CTools plugin decleration.
|
||||
- Added Form Builder integration.
|
||||
- Added support for the EditArea real-time syntax highlighter.
|
||||
- Added Entity Label in preview.
|
||||
- Added Devel Generate support to preview.
|
||||
- Added PHP engine DPM of raw HTML option.
|
||||
- Fixed issue with Javascript attachment method.
|
||||
- Updated CTools Export UI integration.
|
||||
- Removed Contextual links support from Insert support.
|
||||
|
||||
|
||||
Custom Formatters 7.x-2.0, 2011-07-01
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
- #1188398: Added Contextual links integration settings.
|
||||
- Added documentation.
|
||||
- Added PHP engine DPM option to preview.
|
||||
|
||||
|
||||
Custom Formatters 7.x-2.0-beta3, 2011-06-15
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
- Added HTML + Token engine Drupal API export.
|
||||
- Added PHP engine Drupal API export.
|
||||
- Added Insert module integration.
|
||||
- Fixed issue with 'Save & Edit' on new formatters.
|
||||
- Fixed issue with Fieldsets states being reverted on AJAX callback.
|
||||
|
||||
|
||||
Custom Formatters 7.x-2.0-beta2, 2011-06-02
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
- Fixed critical install issue.
|
||||
- Removed support for non-fieldable entities.
|
||||
|
||||
|
||||
Custom Formatters 7.x-2.0-beta1, 2011-06-01
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
- Initial 7.x release.
|
339
sites/all/modules/custom_formatters/LICENSE.txt
Normal file
339
sites/all/modules/custom_formatters/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.
|
87
sites/all/modules/custom_formatters/README.txt
Normal file
87
sites/all/modules/custom_formatters/README.txt
Normal file
@@ -0,0 +1,87 @@
|
||||
The Custom Formatters module allows users to easily create custom Field
|
||||
Formatters without the need to write a custom module. Custom Formatters can then
|
||||
be exported as CTools Exportables, Features or Drupal API Field Formatters.
|
||||
|
||||
Custom Formatters was written and is maintained by Stuart Clark (deciphered).
|
||||
- http://stuar.tc/lark
|
||||
- http://twitter.com/Decipher
|
||||
|
||||
|
||||
Features
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
* Two default editor/renderer engines:
|
||||
* HTML + Tokens.
|
||||
* PHP.
|
||||
* Supports for all fieldable entities, including but not limited to:
|
||||
* Drupal Core - Comment, Node, Taxonomy term and User entities.
|
||||
* Field collection module - Field-collection item entity.
|
||||
* Media module - Media entity.
|
||||
* Exportable as:
|
||||
* Drupal API formatter via:
|
||||
* Custom Formatters export interface.
|
||||
* CTools exportable via:
|
||||
* Custom Formatters export interface.
|
||||
* CTools Bulk Export module.
|
||||
* Features module.
|
||||
* Live preview using real entities or Devel Generate.
|
||||
* Integrates with:
|
||||
* Coder Review module - review your Custom Formatter code for Drupal coding
|
||||
standards and more.
|
||||
* Drupal Contextual links module - Adds a hover link for quick editing of
|
||||
Custom Formatters.
|
||||
* Entity tokens module - Leverages entity tokens for Field token support.
|
||||
* Features module - Adds dependent Custom Formatters (from Views or Content
|
||||
types) to Feature.
|
||||
* Form Builder - Drag'n'Drop interface for builder Formatter Settings forms.
|
||||
* Insert module - Exposes Custom Formatters to the Insert module.
|
||||
* Libraries API module and the EditArea javascript library - Adds real-time
|
||||
syntax highlighting.
|
||||
* Token module - Adds the Token tree browser to the HTML + Tokens engine.
|
||||
|
||||
|
||||
Required Modules
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
* Chaos tool suite - http://drupal.org/project/ctools
|
||||
|
||||
|
||||
Recommended Modules
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
* Coder - http://drupal.org/project/coder
|
||||
* Coder Review (via Coder)
|
||||
* Devel - http://drupal.org/project/devel
|
||||
* Devel Generate (via Devel)
|
||||
* Entity - http://drupal.org/project/entity
|
||||
* Entity tokens (via Entity)
|
||||
* Form Builder - http://drupal.org/project/form_builder
|
||||
* Libraries API - http://drupal.org/project/libraries
|
||||
* Token - http://drupal.org/project/token
|
||||
|
||||
|
||||
EditArea - Real-time syntax highlighting
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
The EditArea javascript library adds real-time syntax highlighting, to install
|
||||
it follow these steps:
|
||||
|
||||
1. Download and install the Libraries API module.
|
||||
http://drupal.org/project/libraries
|
||||
|
||||
2. Download the EditArea library and extract and move it into your libraries
|
||||
folder as 'editarea' (eg. sites/all/libraries/editarea).
|
||||
http://sourceforge.net/projects/editarea/files/EditArea/EditArea%200.8.2/editarea_0_8_2.zip/download
|
||||
|
||||
|
||||
Roadmap
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
7.x-2.2
|
||||
- Improve HTML + Tokens engine.
|
||||
|
||||
7.x-2.3
|
||||
- Add Static cache mode (read Formatters from code instead of Database).
|
||||
|
||||
7.x-2.4
|
||||
- Add Display Suite integration.
|
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Hooks provided by the Custom Formatters module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_engine().
|
||||
*/
|
||||
function hook_custom_formatters_engine_info() {
|
||||
$engines = array();
|
||||
|
||||
$engines['MY_MODULE'] = array(
|
||||
'label' => t('MY_MODULE'),
|
||||
'callbacks' => array(
|
||||
'settings form' => 'MYMODULE_engine_settings_form',
|
||||
'render' => 'MYMODULE_engine_render',
|
||||
),
|
||||
'file' => drupal_get_path('module', 'MYMODULE') . '/engines/MYMODULE.inc',
|
||||
);
|
||||
|
||||
return $engines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_defaults().
|
||||
*/
|
||||
function hook_custom_formatters_defaults() {
|
||||
$formatters = array();
|
||||
|
||||
$formatter = new stdClass;
|
||||
$formatter->disabled = FALSE; /* Edit this to true to make a default formatter disabled initially */
|
||||
$formatter->api_version = 2;
|
||||
$formatter->name = 'MYMODULE';
|
||||
$formatter->label = 'MYMODULE';
|
||||
$formatter->description = 'A PHP example formatter; Display a Thumbnail image linked to a Large image.';
|
||||
$formatter->mode = 'php';
|
||||
$formatter->field_types = 'image';
|
||||
$formatter->code = 'foreach (element_children($variables[\'#items\']) as $delta) {
|
||||
$item = $variables[\'#items\'][$delta];
|
||||
$thumbnail = theme(\'image_style\', array(\'style_name\' => \'thumbnail\', \'path\' => $item[\'uri\']));
|
||||
$large = image_style_path(\'large\', $item[\'uri\']);
|
||||
|
||||
print l($thumbnail, file_create_url($large), array(\'html\' => TRUE));
|
||||
}';
|
||||
$formatters['example_php_image'] = $formatter;
|
||||
|
||||
return $formatters;
|
||||
}
|
43
sites/all/modules/custom_formatters/custom_formatters.info
Normal file
43
sites/all/modules/custom_formatters/custom_formatters.info
Normal file
@@ -0,0 +1,43 @@
|
||||
name = Custom Formatters
|
||||
description = Allows users to easily define custom CCK Formatters.
|
||||
dependencies[] = ctools
|
||||
dependencies[] = field
|
||||
package = Fields
|
||||
configure = admin/structure/formatters
|
||||
core = 7.x
|
||||
|
||||
; Formatter engines.
|
||||
files[] = engines/php.inc
|
||||
files[] = engines/token.inc
|
||||
|
||||
; Module integrations.
|
||||
files[] = includes/contextual.inc
|
||||
files[] = includes/ctools.inc
|
||||
files[] = includes/custom_formatters.admin.inc
|
||||
files[] = includes/custom_formatters.inc
|
||||
files[] = includes/devel_generate.inc
|
||||
files[] = includes/features.inc
|
||||
files[] = includes/field.inc
|
||||
files[] = includes/form_builder.inc
|
||||
files[] = includes/help.inc
|
||||
files[] = includes/insert.inc
|
||||
files[] = includes/libraries.inc
|
||||
files[] = includes/node.inc
|
||||
files[] = includes/system.inc
|
||||
files[] = includes/taxonomy.inc
|
||||
files[] = includes/token.inc
|
||||
files[] = includes/user.inc
|
||||
|
||||
; CTools plugins.
|
||||
files[] = plugins/export_ui/custom_formatters.inc
|
||||
files[] = plugins/export_ui/custom_formatters_ui.class.php
|
||||
|
||||
; Core files.
|
||||
files[] = custom_formatters.module
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-11-01
|
||||
version = "7.x-2.2+1-dev"
|
||||
core = "7.x"
|
||||
project = "custom_formatters"
|
||||
datestamp = "1351774192"
|
||||
|
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall functions for the Custom Formatters module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_schema().
|
||||
*/
|
||||
function custom_formatters_schema() {
|
||||
$schema['formatters'] = array(
|
||||
'export' => array(
|
||||
'key' => 'name',
|
||||
'key name' => 'Name',
|
||||
'primary key' => 'name',
|
||||
'identifier' => 'formatter',
|
||||
'default hook' => 'custom_formatters_defaults',
|
||||
'api' => array(
|
||||
'owner' => 'custom_formatters',
|
||||
'api' => 'custom_formatters',
|
||||
'minimum_version' => 2,
|
||||
'current_version' => 2,
|
||||
),
|
||||
),
|
||||
'fields' => array(
|
||||
'name' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 64,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
'label' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 64,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
'description' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => FALSE,
|
||||
'default' => ''
|
||||
),
|
||||
'mode' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 32,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
'field_types' => array(
|
||||
'type' => 'text',
|
||||
'size' => 'medium',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'code' => array(
|
||||
'type' => 'blob'
|
||||
),
|
||||
'fapi' => array(
|
||||
'type' => 'blob'
|
||||
),
|
||||
),
|
||||
'primary key' => array('name'),
|
||||
);
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function custom_formatters_uninstall() {
|
||||
variable_del('custom_formatters_settings');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add FAPI column to Formatters table.
|
||||
*/
|
||||
function custom_formatters_update_7200() {
|
||||
db_add_field('formatters', 'fapi', array('type' => 'blob'));
|
||||
return t('New FAPI column added to Formatters table.');
|
||||
}
|
26
sites/all/modules/custom_formatters/custom_formatters.make
Normal file
26
sites/all/modules/custom_formatters/custom_formatters.make
Normal file
@@ -0,0 +1,26 @@
|
||||
core = 7.x
|
||||
api = 2
|
||||
|
||||
projects[coder][subdir] = "contrib"
|
||||
projects[coder][version] = "1.0"
|
||||
|
||||
projects[ctools][subdir] = "contrib"
|
||||
projects[ctools][version] = "1.0"
|
||||
|
||||
projects[devel][subdir] = "contrib"
|
||||
projects[devel][version] = "1.3"
|
||||
|
||||
projects[form_builder][subdir] = "contrib"
|
||||
projects[form_builder][version] = "1.0"
|
||||
|
||||
projects[libraries][subdir] = "contrib"
|
||||
projects[libraries][version] = "1.0"
|
||||
|
||||
projects[options_element][subdir] = "contrib"
|
||||
projects[options_element][version] = "1.7"
|
||||
|
||||
projects[token][subdir] = "contrib"
|
||||
projects[token][version] = "1.1"
|
||||
|
||||
libraries[editarea][download][type] = "get"
|
||||
libraries[editarea][download][url] = "http://downloads.sourceforge.net/project/editarea/EditArea/EditArea%200.8.2/editarea_0_8_2.zip?r=&ts=1334742944&use_mirror=internode"
|
103
sites/all/modules/custom_formatters/custom_formatters.module
Normal file
103
sites/all/modules/custom_formatters/custom_formatters.module
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains core functions for the Custom Formatters module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include additional files.
|
||||
*/
|
||||
foreach (module_list() as $module) {
|
||||
if (file_exists($file = dirname(__FILE__) . "/includes/{$module}.inc")) {
|
||||
require_once $file;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
function custom_formatters_permission() {
|
||||
return array(
|
||||
'administer custom formatters' => array(
|
||||
'title' => t('Administer Custom Formatters'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function custom_formatters_menu() {
|
||||
$items = array();
|
||||
|
||||
$items['admin/structure/formatters/settings'] = array(
|
||||
'title' => 'Settings',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('custom_formatters_settings_form'),
|
||||
'access arguments' => array('administer custom formatters'),
|
||||
'file' => 'custom_formatters.admin.inc',
|
||||
'file path' => drupal_get_path('module', 'custom_formatters') . '/includes',
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
);
|
||||
|
||||
$items['js/formatters/autocomplete'] = array(
|
||||
'title' => 'Formatters autocomplete',
|
||||
'page callback' => 'custom_formatters_autocomplete',
|
||||
'access arguments' => array('administer custom formatters'),
|
||||
'file' => 'custom_formatters.inc',
|
||||
'file path' => drupal_get_path('module', 'custom_formatters') . '/plugins/export_ui',
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function custom_formatters_formatter_is_active($formatter) {
|
||||
$field_types = drupal_explode_tags($formatter->field_types);
|
||||
$field_info = field_info_fields();
|
||||
|
||||
foreach (field_info_instances() as $bundles) {
|
||||
foreach ($bundles as $fields) {
|
||||
foreach ($fields as $field) {
|
||||
if (in_array($field_info[$field['field_name']]['type'], $field_types)) {
|
||||
foreach ($field['display'] as $display) {
|
||||
if ($display['type'] == "custom_formatters_{$formatter->name}") {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function custom_formatters_crud_load($formatter) {
|
||||
$formatters = custom_formatters_crud_load_all();
|
||||
return isset($formatters[$formatter]) ? $formatters[$formatter] : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function custom_formatters_crud_load_all($flush_cache = FALSE) {
|
||||
$formatters = &drupal_static(__FUNCTION__, array());
|
||||
|
||||
if (!$formatters || $flush_cache) {
|
||||
ctools_include('export');
|
||||
foreach (ctools_export_crud_load_all('formatters') as $formatter) {
|
||||
if (empty($formatter->disabled)) {
|
||||
$formatters[$formatter->name] = $formatter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $formatters;
|
||||
}
|
102
sites/all/modules/custom_formatters/engines/php.export.tpl.php
Normal file
102
sites/all/modules/custom_formatters/engines/php.export.tpl.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
?>
|
||||
/**
|
||||
* Implements hook_field_formatter_info().
|
||||
*/
|
||||
function <?php echo $module; ?>_field_formatter_info() {
|
||||
return array(
|
||||
'<?php echo $module; ?>_<?php echo $item->name; ?>' => array(
|
||||
'label' => t('<?php echo $item->label; ?>'),
|
||||
'field types' => array('<?php echo implode('\', \'', drupal_explode_tags($item->field_types)); ?>'),
|
||||
<?php if (isset($item->form)) : ?>
|
||||
'settings' => array(
|
||||
<?php foreach ($item->form as $form_key => $element) : ?>
|
||||
'<?php echo $form_key; ?>' => <?php if (is_array($element['#default_value'])) : ?>
|
||||
array(
|
||||
<?php foreach ($element['#default_value'] as $key => $value) : ?>
|
||||
<?php echo is_integer($key) ? $key : "'{$key}'"; ?> => '<?php echo $value; ?>',
|
||||
<?php endforeach; ?>
|
||||
),
|
||||
<?php else: ?>
|
||||
'<?php echo $element['#default_value']; ?>',
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
),
|
||||
<?php endif; ?>
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
<?php if (isset($item->form)) : ?>
|
||||
/**
|
||||
* Implements hook_field_formatter_settings_summary().
|
||||
*/
|
||||
function <?php echo $module; ?>_field_formatter_settings_summary($field, $instance, $view_mode) {
|
||||
$display = $instance['display'][$view_mode];
|
||||
$settings = $display['settings'];
|
||||
|
||||
$summary = '';
|
||||
|
||||
if ($display['type'] == '<?php echo $module; ?>_<?php echo $item->name; ?>') {
|
||||
<?php foreach (element_children($item->form) as $key) : ?>
|
||||
// <?php echo $item->form[$key]['#title'] ?>.
|
||||
$value = empty($settings['<?php echo $key; ?>']) ? '<em>' . t('Empty') . '</em>' : $settings['<?php echo $key; ?>'];
|
||||
$value = is_array($value) ? implode(', ', array_filter($value)) : $value;
|
||||
$summary .= "<?php echo $item->form[$key]['#title'] ?>: {$value}<br />";
|
||||
<?php endforeach; ?>
|
||||
}
|
||||
|
||||
return $summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_settings_form().
|
||||
*/
|
||||
function <?php echo $module; ?>_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
|
||||
$display = $instance['display'][$view_mode];
|
||||
$settings = $display['settings'];
|
||||
|
||||
<?php foreach (explode("\n", $item->fapi) as $line) : ?>
|
||||
<?php echo $line . "\n"; ?>
|
||||
<?php endforeach; ?>
|
||||
return $form;
|
||||
}
|
||||
<?php endif; ?>
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_view().
|
||||
*/
|
||||
function <?php echo $module; ?>_field_formatter_view($obj_type, $object, $field, $instance, $langcode, $items, $display) {
|
||||
$element = array();
|
||||
|
||||
// Build variables array for formatter.
|
||||
$variables = array(
|
||||
'#obj_type' => $obj_type,
|
||||
'#object' => $object,
|
||||
'#field' => $field,
|
||||
'#instance' => $instance,
|
||||
'#langcode' => $langcode,
|
||||
'#items' => $items,
|
||||
'#display' => $display,
|
||||
);
|
||||
|
||||
if (function_exists($function = "{$display['module']}_field_formatter_{$display['type']}")) {
|
||||
$element[0] = array(
|
||||
'#markup' => $function($variables),
|
||||
);
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Field Formatter; <?php echo $item->label; ?>.
|
||||
*/
|
||||
function <?php echo $module; ?>_field_formatter_<?php echo $module; ?>_<?php echo $item->name; ?>($variables) {
|
||||
<?php foreach (explode("\n", $item->code) as $line) : ?>
|
||||
<?php echo $line . "\n"; ?>
|
||||
<?php endforeach; ?>
|
||||
}
|
135
sites/all/modules/custom_formatters/engines/php.inc
Normal file
135
sites/all/modules/custom_formatters/engines/php.inc
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Token engine for Custom Formatters modules.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function custom_formatters_engine_php_theme_alter(&$theme) {
|
||||
$theme['custom_formatters_php_export'] = array(
|
||||
'variables' => array(
|
||||
'item' => NULL,
|
||||
'module' => NULL,
|
||||
),
|
||||
'template' => 'php.export',
|
||||
'path' => drupal_get_path('module', 'custom_formatters') . '/engines',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings form callback for Custom Formatters PHP engine.
|
||||
*/
|
||||
function custom_formatters_engine_php_settings_form(&$form) {
|
||||
$form['code']['#description'] = t('Enter the PHP code that will be evaluated. You should NOT include %php tags. The $variables object is available.', array('%php' => '<?php ?>'));
|
||||
$form['code']['#attributes']['class'][] = 'syntax-php';
|
||||
|
||||
$form['settings'] = array(
|
||||
'#type' => 'container',
|
||||
);
|
||||
|
||||
// Additional debugging modes.
|
||||
$form['preview']['options']['dpm'] = array(
|
||||
'#type' => 'container',
|
||||
);
|
||||
$form['preview']['options']['dpm']['vars'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Output <strong>$variables</strong> array (requires <a href="http://drupal.org/project/devel">Devel</a> module).'),
|
||||
'#default_value' => module_exists('devel'),
|
||||
'#disabled' => !module_exists('devel'),
|
||||
);
|
||||
$form['preview']['options']['dpm']['html'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Output raw HTML (requires <a href="http://drupal.org/project/devel">Devel</a> module).'),
|
||||
'#default_value' => module_exists('devel'),
|
||||
'#disabled' => !module_exists('devel'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render callback for Custom Formatters PHP engine.
|
||||
*/
|
||||
function custom_formatters_engine_php_render($formatter, $obj_type, $object, $field, $instance, $langcode, $items, $display) {
|
||||
global $theme_path, $theme_info, $conf;
|
||||
|
||||
// Store current theme path.
|
||||
$old_theme_path = $theme_path;
|
||||
|
||||
// Restore theme_path to the theme, as long as php_eval() executes,
|
||||
// so code evaluated will not see the caller module as the current theme.
|
||||
// If theme info is not initialized get the path from theme_default.
|
||||
if (!isset($theme_info)) {
|
||||
$theme_path = drupal_get_path('theme', $conf['theme_default']);
|
||||
}
|
||||
else {
|
||||
$theme_path = dirname($theme_info->filename);
|
||||
}
|
||||
|
||||
// Build variables array for formatter.
|
||||
$variables = array(
|
||||
'#obj_type' => $obj_type,
|
||||
'#object' => $object,
|
||||
'#field' => $field,
|
||||
'#instance' => $instance,
|
||||
'#langcode' => $langcode,
|
||||
'#items' => $items,
|
||||
'#display' => $display,
|
||||
);
|
||||
|
||||
ob_start();
|
||||
$output = eval($formatter->code);
|
||||
$output = !empty($output) ? $output : ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
// Preview debugging; Show the available variables data.
|
||||
if (module_exists('devel') && isset($formatter->preview) && $formatter->preview['options']['dpm']['vars']) {
|
||||
dpm($variables);
|
||||
}
|
||||
|
||||
// Recover original theme path.
|
||||
$theme_path = $old_theme_path;
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export callback for Custom Formatters PHP engine.
|
||||
*/
|
||||
function custom_formatters_engine_php_export($item, $module) {
|
||||
$formatter = clone $item;
|
||||
|
||||
if (isset($formatter->fapi)) {
|
||||
ob_start();
|
||||
eval($formatter->fapi);
|
||||
ob_get_clean();
|
||||
|
||||
if (isset($form)) {
|
||||
$formatter->form = $form;
|
||||
}
|
||||
}
|
||||
|
||||
// Modify #default_value for hook_field_formatter_settings_form() export.
|
||||
include drupal_get_path('module', 'form_builder') . '/examples/form_builder_examples.module';
|
||||
foreach (element_children($form) as $key) {
|
||||
if (isset($form[$key]['#default_value'])) {
|
||||
unset($form[$key]['#default_value']);
|
||||
}
|
||||
$form[$key]['#default_value'] = "[default-value::{$key}]";
|
||||
}
|
||||
$formatter->fapi = form_builder_examples_export_recurse($form);
|
||||
preg_match_all('/\'\[default-value::(.*)?\]\'/', $formatter->fapi, $matches, PREG_SET_ORDER);
|
||||
foreach ($matches as $match) {
|
||||
$formatter->fapi = str_replace($match[0], "\$settings['{$match[1]}']", $formatter->fapi);
|
||||
}
|
||||
|
||||
return theme('custom_formatters_php_export', array('item' => $formatter, 'module' => $module));
|
||||
}
|
||||
|
||||
/**
|
||||
* Help callback for Custom Formatters PHP engine.
|
||||
*/
|
||||
function custom_formatters_engine_php_help() {
|
||||
return t('A PHP Formatter is essentially a standard Drupal API Field Formatter, the primary difference is that all availble parameters have been bundled into a <strong>$variables</strong> array for ease of use.') . "<br />\n"
|
||||
. t('The Formatter should be PHP code that returns either a value or <a href="http://drupal.org/node/930760">Render Array</a> and it should NOT include <em><?php ?></em> tags.') . "\n";
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
?>
|
||||
/**
|
||||
* Implements hook_field_formatter_info().
|
||||
*/
|
||||
function <?php echo $module; ?>_field_formatter_info() {
|
||||
return array(
|
||||
'<?php echo $module; ?>_<?php echo $item->name; ?>' => array(
|
||||
'label' => t('<?php echo $item->label; ?>'),
|
||||
'field types' => array('<?php echo implode('\', \'', drupal_explode_tags($item->field_types)); ?>'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_view().
|
||||
*/
|
||||
function <?php echo $module; ?>_field_formatter_view($obj_type, $object, $field, $instance, $langcode, $items, $display) {
|
||||
$element = array();
|
||||
$pattern = "<?php echo addslashes($item->code); ?>";
|
||||
|
||||
$info = token_get_info("{$field['type']}-field");
|
||||
$field_value = $info['field-value-type'];
|
||||
|
||||
$output = '';
|
||||
foreach ($items as $item) {
|
||||
$output .= token_replace($pattern, array(
|
||||
$obj_type => $object,
|
||||
$field_value => $item,
|
||||
'item' => $item,
|
||||
));
|
||||
}
|
||||
$element[0] = array(
|
||||
'#markup' => $output,
|
||||
);
|
||||
|
||||
return $element;
|
||||
}
|
81
sites/all/modules/custom_formatters/engines/token.inc
Normal file
81
sites/all/modules/custom_formatters/engines/token.inc
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Token engine for Custom Formatters modules.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements custom_formatters_engine_hook_theme_alter().
|
||||
*/
|
||||
function custom_formatters_engine_token_theme_alter(&$theme) {
|
||||
$theme['custom_formatters_token_export'] = array(
|
||||
'variables' => array(
|
||||
'item' => NULL,
|
||||
'module' => NULL,
|
||||
),
|
||||
'template' => 'token.export',
|
||||
'path' => drupal_get_path('module', 'custom_formatters') . '/engines',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings form callback for Custom Formatters Token engine.
|
||||
*/
|
||||
function custom_formatters_engine_token_settings_form(&$form, $form_state, $item) {
|
||||
$form['code']['#attributes']['class'][] = 'syntax-html';
|
||||
|
||||
// Additional debugging modes.
|
||||
$form['preview']['options']['dpm'] = array(
|
||||
'#type' => 'container',
|
||||
);
|
||||
$form['preview']['options']['dpm']['html'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Output raw HTML (requires !devel module).', array('!devel' => l(t('Devel'), 'http://drupal.org/project/devel'))),
|
||||
'#default_value' => module_exists('devel'),
|
||||
'#disabled' => !module_exists('devel'),
|
||||
);
|
||||
|
||||
$options = array();
|
||||
foreach (field_info_field_types() as $type => $field) {
|
||||
$options[$field['module']][$type] = $field['label'];
|
||||
}
|
||||
$form['field_types']['#type'] = 'select';
|
||||
$form['field_types']['#options'] = $options;
|
||||
unset($form['field_types']['#description']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render callback for Custom Formatters Token engine.
|
||||
*/
|
||||
function custom_formatters_engine_token_render($formatter, $obj_type, $object, $field, $instance, $langcode, $items, $display) {
|
||||
$element = array();
|
||||
|
||||
foreach ($items as $delta => $item) {
|
||||
$text = $formatter->code;
|
||||
$token_data = array(
|
||||
$obj_type => $object,
|
||||
'item' => $item,
|
||||
);
|
||||
drupal_alter('custom_formatters_token_data', $token_data, $text, $field);
|
||||
$element[$delta] = array(
|
||||
'#markup' => token_replace($text, $token_data, array('clear' => TRUE))
|
||||
);
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export callback for Custom Formatters Token engine.
|
||||
*/
|
||||
function custom_formatters_engine_token_export($item, $module) {
|
||||
return theme('custom_formatters_token_export', array('item' => $item, 'module' => $module));
|
||||
}
|
||||
|
||||
/**
|
||||
* Help callback for Custom Formatters Token engine.
|
||||
*/
|
||||
function custom_formatters_engine_token_help() {
|
||||
return t('A HTML + Token Formatter utilizes Drupal Tokens and the Token module to create easy yet powerful formatters.') . "<br />\n"
|
||||
. t('All available Tokens can be navigated via the Tokens fieldset displayed below the Formatter field.');
|
||||
}
|
BIN
sites/all/modules/custom_formatters/images/icon-image_styles.png
Normal file
BIN
sites/all/modules/custom_formatters/images/icon-image_styles.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
BIN
sites/all/modules/custom_formatters/images/icon-token_tree.png
Normal file
BIN
sites/all/modules/custom_formatters/images/icon-token_tree.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Coder Review module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_form_alter_alter() on behalf of
|
||||
* coder_review.module.
|
||||
*/
|
||||
function coder_review_custom_formatters_form_alter_alter(&$form, &$form_state, $form_id) {
|
||||
if (in_array($form_id, array('ctools_export_ui_edit_item_form', 'ctools_export_ui_edit_item_wizard_form')) && isset($form['#formatters']) && 'php' == $form['info']['mode']['#default_value']) {
|
||||
drupal_add_css(drupal_get_path('module', 'coder_review') . '/coder_review.css');
|
||||
|
||||
$form['engine']['coder_review'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Coder Review'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
);
|
||||
|
||||
$reviews = _coder_review_settings_form(_coder_review_get_default_settings('files'), $system = array(), $files = array());
|
||||
$form['engine']['coder_review']['reviews'] = array_merge($reviews['coder_reviews_group'], array(
|
||||
'#collapsed' => TRUE,
|
||||
));
|
||||
|
||||
$form['engine']['coder_review']['review'] = array(
|
||||
'#type' => 'container',
|
||||
'#prefix' => '<div id="coder-review-wrapper">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
|
||||
$form['engine']['coder_review']['button'] = array(
|
||||
'#type' => 'button',
|
||||
'#value' => t('Review'),
|
||||
'#ajax' => array(
|
||||
'callback' => 'custom_formatters_coder_review',
|
||||
'wrapper' => 'coder-review-wrapper',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajax callback for Custom Formatters Coder Review integration.
|
||||
*/
|
||||
function custom_formatters_coder_review(&$form, $form_state) {
|
||||
$directory = 'public://custom_formatters/coder_review';
|
||||
if (file_prepare_directory($directory, FILE_CREATE_DIRECTORY)) {
|
||||
global $base_url;
|
||||
|
||||
$md5 = md5($form_state['values']['code']);
|
||||
file_unmanaged_save_data("<?php\n/**\n * @file\n */\n\n{$form_state['values']['code']}", "{$directory}/{$md5}.php", FILE_EXISTS_REPLACE);
|
||||
$file = str_replace($base_url . base_path(), '', file_create_url("{$directory}/{$md5}.php"));
|
||||
|
||||
$form_state = array(
|
||||
'storage' => array(
|
||||
'coder_reviews' => $form_state['values']['coder_reviews'],
|
||||
'coder_severity' => $form_state['values']['coder_severity'],
|
||||
'coder_file_list' => $file,
|
||||
'coder_files' => 1,
|
||||
)
|
||||
);
|
||||
$review = coder_review_page_form(array(), $form_state, 'files');
|
||||
|
||||
$form['engine']['coder_review']['review'][$file] = $review[$file]['output'];
|
||||
foreach ($form['engine']['coder_review']['review'][$file]['#results'] as &$result) {
|
||||
// Adjust the line numbering.
|
||||
$result = preg_replace('/\/\>Line (\d+):(.*?<pre>)/e', '"/>Line " . ($1 - 5) . ":$2"', $result);
|
||||
}
|
||||
unset($form['engine']['coder_review']['review'][$file]['#filename']);
|
||||
|
||||
file_unmanaged_delete("{$directory}/{$md5}.php");
|
||||
}
|
||||
|
||||
drupal_get_messages(NULL, TRUE);
|
||||
return $form['engine']['coder_review']['review'];
|
||||
}
|
100
sites/all/modules/custom_formatters/includes/contextual.inc
Normal file
100
sites/all/modules/custom_formatters/includes/contextual.inc
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contextual links module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_form_alter_alter() on behalf of
|
||||
* contextual.module.
|
||||
*/
|
||||
function contextual_custom_formatters_form_alter_alter(&$form, $form_state, $form_id) {
|
||||
if ($form_id == 'custom_formatters_settings_form') {
|
||||
$settings = variable_get('custom_formatters_settings', array('contextual' => 1));
|
||||
|
||||
$form['settings']['contextual'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Contextual links integration'),
|
||||
'#default_value' => isset($settings['contextual']) ? $settings['contextual'] : 1,
|
||||
'#options' => array(
|
||||
0 => t('Disabled'),
|
||||
1 => t('Enabled on all Formatters except those listed'),
|
||||
2 => t('Enabled on only the listed Formatters'),
|
||||
),
|
||||
);
|
||||
|
||||
$form['settings']['contextual_list'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#default_value' => isset($settings['contextual_list']) ? $settings['contextual_list'] : '',
|
||||
'#description' => t('Specify Formatters by using their machine names. Enter one machine name per line.'),
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
'input[name="settings[contextual]"]' => array('checked' => FALSE),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_field_formatter_view_element_alter() on
|
||||
* behalf of contextual.module.
|
||||
*
|
||||
* Adds contextual links to Custom Formatter fields.
|
||||
*/
|
||||
function contextual_custom_formatters_field_formatter_view_element_alter(&$element, $formatter) {
|
||||
if (_custom_formatters_contextual_access($formatter->name, $element)) {
|
||||
foreach (element_children($element) as $delta) {
|
||||
$element[$delta] = array(
|
||||
'markup' => $element[$delta],
|
||||
'contextual_links' => array(
|
||||
'#type' => 'contextual_links',
|
||||
'#contextual_links' => array('custom_formatters' => array('admin/structure/formatters/list', array($formatter->name, 'edit'))),
|
||||
'#element' => $element[$delta],
|
||||
),
|
||||
'#prefix' => '<div class="contextual-links-region">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function _custom_formatters_contextual_access($name, $element) {
|
||||
if (isset($element[0]['#cf_options']['#contextual_links']) && $element[0]['#cf_options']['#contextual_links'] == FALSE) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$user_access = user_access('access contextual links') && user_access('administer custom formatters');
|
||||
if (!$user_access) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$settings = variable_get('custom_formatters_settings', array('contextual' => 1));
|
||||
$contextual = isset($settings['contextual']) ? $settings['contextual'] : 1;
|
||||
$list = array_unique(explode("\r\n", isset($settings['contextual_list']) ? $settings['contextual_list'] : ''));
|
||||
|
||||
switch ($contextual) {
|
||||
case 0:
|
||||
return FALSE;
|
||||
|
||||
case 1:
|
||||
return !in_array($name, $list) ? TRUE : FALSE;
|
||||
|
||||
case 2:
|
||||
return in_array($name, $list) ? TRUE : FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu_contextual_links_alter().
|
||||
*/
|
||||
function custom_formatters_menu_contextual_links_alter(&$links, $router_item, $root_path) {
|
||||
if ($root_path == 'admin/structure/formatters/list/%/edit') {
|
||||
$links['custom_formatters-edit'] = array_merge(
|
||||
$router_item,
|
||||
array(
|
||||
'title' => 'Edit formatter',
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
50
sites/all/modules/custom_formatters/includes/ctools.inc
Normal file
50
sites/all/modules/custom_formatters/includes/ctools.inc
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Chaos tool suite module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_init() on behalf of ctools.module.
|
||||
*/
|
||||
function ctools_custom_formatters_init() {
|
||||
if (strstr(request_uri(), 'system/ajax') && in_array($_POST['form_id'], array('ctools_export_ui_edit_item_form', 'custom_formatters_export_ui_export_form'))) {
|
||||
require_once drupal_get_path('module', 'custom_formatters') . '/plugins/export_ui/custom_formatters.inc';
|
||||
|
||||
/**
|
||||
* Temporary fix for CTools #AJAX issue.
|
||||
* @See http://drupal.org/node/1142812
|
||||
*/
|
||||
ctools_include('export');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_ctools_plugin_api().
|
||||
*/
|
||||
function custom_formatters_ctools_plugin_api() {
|
||||
list($module, $api) = func_get_args();
|
||||
if ($module == 'custom_formatters' && $api == 'custom_formatters') {
|
||||
return array('version' => 2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_ctools_plugin_directory().
|
||||
*/
|
||||
function custom_formatters_ctools_plugin_directory($module, $plugin) {
|
||||
if ($module == 'ctools' && !empty($plugin)) {
|
||||
return "plugins/{$plugin}";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_theme_alter() on behalf of ctools.module.
|
||||
*/
|
||||
function ctools_custom_formatters_theme_alter(&$theme) {
|
||||
$theme['custom_formatters_export_ui_form_preview'] = array(
|
||||
'render element' => 'form',
|
||||
'file' => 'custom_formatters.inc',
|
||||
'path' => drupal_get_path('module', 'custom_formatters') . '/plugins/export_ui'
|
||||
);
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Custom Formatters Administration functionality.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function custom_formatters_settings_form($form, $form_state) {
|
||||
$settings = variable_get('custom_formatters_settings', array('label_prefix' => TRUE, 'label_prefix_value' => t('Custom')));
|
||||
|
||||
$form['settings'] = array(
|
||||
'#type' => 'container',
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
|
||||
$form['settings']['label_prefix'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Use Label prefix?'),
|
||||
'#description' => t('If checked, all Custom Formatters labels will be prefixed with a set value.'),
|
||||
'#default_value' => $settings['label_prefix'],
|
||||
);
|
||||
|
||||
$form['settings']['label_prefix_value'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Label prefix'),
|
||||
'#default_value' => $settings['label_prefix_value'],
|
||||
'#states' => array(
|
||||
'invisible' => array(
|
||||
'input[name="settings[label_prefix]"]' => array('checked' => FALSE),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$form['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save'),
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function custom_formatters_settings_form_validate($form, $form_state) {
|
||||
if ($form_state['values']['settings']['label_prefix'] && empty($form_state['values']['settings']['label_prefix_value'])) {
|
||||
form_set_error('settings][label_prefix_value', t('A label prefix must be defined if you wish to use the prefix.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function custom_formatters_settings_form_submit($form, $form_state) {
|
||||
drupal_set_message(t('Custom Formatters settings have been updated.'));
|
||||
variable_set('custom_formatters_settings', $form_state['values']['settings']);
|
||||
field_cache_clear();
|
||||
}
|
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Custom Formatters module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_engine().
|
||||
*/
|
||||
function custom_formatters_custom_formatters_engine_info() {
|
||||
$engines = array();
|
||||
|
||||
// PHP engine.
|
||||
$engines['php'] = array(
|
||||
'label' => t('PHP'),
|
||||
'callbacks' => array(
|
||||
'settings form' => 'custom_formatters_engine_php_settings_form',
|
||||
'render' => 'custom_formatters_engine_php_render',
|
||||
'export' => 'custom_formatters_engine_php_export',
|
||||
'help' => 'custom_formatters_engine_php_help',
|
||||
),
|
||||
'file' => drupal_get_path('module', 'custom_formatters') . '/engines/php.inc',
|
||||
);
|
||||
|
||||
// Token engine.
|
||||
$engines['token'] = array(
|
||||
'label' => t('HTML + Tokens'),
|
||||
'callbacks' => array(
|
||||
'settings form' => 'custom_formatters_engine_token_settings_form',
|
||||
'render' => 'custom_formatters_engine_token_render',
|
||||
'export' => 'custom_formatters_engine_token_export',
|
||||
'help' => 'custom_formatters_engine_token_help',
|
||||
),
|
||||
'file' => drupal_get_path('module', 'custom_formatters') . '/engines/token.inc',
|
||||
);
|
||||
|
||||
return $engines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_defaults().
|
||||
*/
|
||||
function custom_formatters_custom_formatters_defaults() {
|
||||
$formatters = array();
|
||||
|
||||
$formatter = new stdClass();
|
||||
$formatter->disabled = TRUE; /* Edit this to true to make a default formatter disabled initially */
|
||||
$formatter->api_version = 2;
|
||||
$formatter->name = 'example_php_image';
|
||||
$formatter->label = 'Example: Image (PHP)';
|
||||
$formatter->description = 'A PHP example formatter; Display a Thumbnail image linked to a Large image.';
|
||||
$formatter->mode = 'php';
|
||||
$formatter->field_types = 'image';
|
||||
$formatter->code = '// Formatter settings.
|
||||
$settings = $variables[\'#display\'][\'settings\'];
|
||||
|
||||
$element = array();
|
||||
foreach ($variables[\'#items\'] as $delta => $item) {
|
||||
$element[$delta] = array(
|
||||
\'#type\' => \'link\',
|
||||
\'#href\' => file_create_url(image_style_path($settings[\'destination_image_style\'], $item[\'uri\'])),
|
||||
\'#title\' => theme(\'image_style\', array(
|
||||
\'style_name\' => $settings[\'source_image_style\'],
|
||||
\'path\' => $item[\'uri\'],
|
||||
)),
|
||||
\'#options\' => array(
|
||||
\'html\' => TRUE,
|
||||
),
|
||||
);
|
||||
}
|
||||
return $element;';
|
||||
$formatter->fapi = '$form = array();
|
||||
$form[\'source_image_style\'] = array(
|
||||
\'#title\' => t(\'Source image styles\'),
|
||||
\'#multiple_toggle\' => \'1\',
|
||||
\'#required\' => \'0\',
|
||||
\'#type\' => \'custom_formatters_image_styles\',
|
||||
\'#weight\' => \'0\',
|
||||
);
|
||||
$form[\'destination_image_style\'] = array(
|
||||
\'#title\' => t(\'Destination image styles\'),
|
||||
\'#multiple_toggle\' => \'1\',
|
||||
\'#required\' => \'0\',
|
||||
\'#type\' => \'custom_formatters_image_styles\',
|
||||
\'#weight\' => \'1\',
|
||||
);
|
||||
';
|
||||
$formatters['example_php_image'] = $formatter;
|
||||
|
||||
$formatter = new stdClass();
|
||||
$formatter->disabled = TRUE; /* Edit this to true to make a default formatter disabled initially */
|
||||
$formatter->api_version = 2;
|
||||
$formatter->name = 'example_token_image';
|
||||
$formatter->label = 'Example: Image (HTML + Token)';
|
||||
$formatter->description = 'A HTML + Tokens example formatter; Display a Thumbnail image linked to a Large image.';
|
||||
$formatter->mode = 'token';
|
||||
$formatter->field_types = 'image';
|
||||
$formatter->code = '<a href="[image-field-value:styles:url:large]"><img src="[image-field-value:styles:url:thumbnail]" alt="[image-field-value:alt]" title="[image-field-value:title]" /></a>';
|
||||
$formatters['example_token_image'] = $formatter;
|
||||
|
||||
return $formatters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_theme_alter().
|
||||
*/
|
||||
function custom_formatters_custom_formatters_theme_alter(&$theme) {
|
||||
$engines = module_invoke_all('custom_formatters_engine_info');
|
||||
foreach (element_children($engines) as $engine) {
|
||||
if (isset($engines[$engine]['file']) && file_exists($engines[$engine]['file'])) {
|
||||
require_once $engines[$engine]['file'];
|
||||
}
|
||||
if (function_exists($function = "custom_formatters_engine_{$engine}_theme_alter")) {
|
||||
$function($theme);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Devel Generate module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_form_alter_alter on behalf of
|
||||
* devel_generate.module.
|
||||
*/
|
||||
function devel_generate_custom_formatters_form_alter_alter(&$form, &$form_state, $form_id) {
|
||||
if (in_array($form_id, array('ctools_export_ui_edit_item_form', 'ctools_export_ui_edit_item_wizard_form')) && isset($form['#formatters'])) {
|
||||
$item = !empty($form_state['values']) ? $form_state['values'] : (array) $form_state['item'];
|
||||
$entity_type = !empty($item['preview']['entity_type']) ? $item['preview']['entity_type'] : 'node';
|
||||
|
||||
$info = module_invoke_all('custom_formatters_devel_generate_info');
|
||||
if (in_array($entity_type, array_keys($info)) && count($form['engine']['preview']['field']['#options']) > 0) {
|
||||
$form['engine']['preview']['entity']['#options']['devel_generate'] = 'Devel generate';
|
||||
$form['engine']['preview']['entity']['#disabled'] = FALSE;
|
||||
$form['engine']['preview']['button']['#ajax']['callback'] = 'custom_formatters_export_ui_form_js_preview_devel_generate';
|
||||
$form['engine']['preview']['button']['#disabled'] = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit callback for Custom Formatters live preview via Devel Generate.
|
||||
*/
|
||||
function custom_formatters_export_ui_form_js_preview_devel_generate($form, $form_state) {
|
||||
$info = module_invoke_all('custom_formatters_devel_generate_info');
|
||||
if ($form_state['values']['preview']['entity'] !== 'devel_generate' || !function_exists($function = $info[$form_state['values']['preview']['entity_type']]['process callback'])) {
|
||||
return custom_formatters_export_ui_form_js_preview($form, $form_state);
|
||||
}
|
||||
$object = $function($form_state);
|
||||
return custom_formatters_export_ui_form_js_preview($form, $form_state, $object);
|
||||
}
|
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Entity tokens module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_token_tree_types_alter() on behalf of
|
||||
* entity_tokens.module.
|
||||
*/
|
||||
function entity_token_custom_formatters_token_tree_types_alter(&$token_types, $field_type) {
|
||||
module_load_include('inc', 'entity_token', 'entity_token.tokens');
|
||||
$fields = array();
|
||||
foreach (field_info_fields() as $name => $field) {
|
||||
if ($field['type'] == $field_type) {
|
||||
$fields[] = str_replace('_', '-', $name);
|
||||
}
|
||||
}
|
||||
$info = module_exists('token') ? token_get_info() : token_info();
|
||||
foreach ($fields as $field) {
|
||||
foreach (element_children($info['tokens']) as $type) {
|
||||
if (isset($info['tokens'][$type][$field])) {
|
||||
$token_info = $info['tokens'][$type][$field];
|
||||
if (!empty($token_info['entity-token']) && isset($token_info['type']) && entity_token_types_chained($token_info['type'])) {
|
||||
$token_types[] = $token_info['type'];
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_token_data_alter() on behalf of
|
||||
* entity_token.module.
|
||||
*/
|
||||
function entity_token_custom_formatters_token_data_alter(&$token_data, &$text, $field) {
|
||||
module_load_include('inc', 'entity_token', 'entity_token.tokens');
|
||||
$field_name = str_replace('_', '-', $field['field_name']);
|
||||
$info = module_exists('token') ? token_get_info() : token_info();
|
||||
foreach (element_children($info['tokens']) as $type) {
|
||||
if (isset($info['tokens'][$type][$field_name])) {
|
||||
$token_info = $info['tokens'][$type][$field_name];
|
||||
if (!empty($token_info['entity-token']) && isset($token_info['type']) && entity_token_types_chained($token_info['type'])) {
|
||||
$token_types = entity_token_types_chained();
|
||||
$item_token_type = entity_property_list_extract_type($token_info['type']);
|
||||
|
||||
// List tokens.
|
||||
if (isset($token_types[$item_token_type])) {
|
||||
$entity_info = entity_get_info($token_types[$item_token_type]);
|
||||
$entity = entity_load($token_types[$item_token_type], array($token_data['item'][$entity_info['entity keys']['id']]));
|
||||
$token_data[$token_info['type']] = array($entity[$token_data['item'][$entity_info['entity keys']['id']]]);
|
||||
$text = str_replace('[list:', "[{$token_info['type']}:", $text);
|
||||
}
|
||||
|
||||
// Structural tokens.
|
||||
elseif ('struct' == $token_info['type']) {
|
||||
$entity_info = entity_get_info($field['type']);
|
||||
if (isset($entity_info['entity keys'])) {
|
||||
$entity = entity_load($field['type'], array($token_data['item'][$entity_info['entity keys']['id']]));
|
||||
$token_data['struct'] = entity_metadata_wrapper($field['type'], $entity[$token_data['item'][$entity_info['entity keys']['id']]]);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
23
sites/all/modules/custom_formatters/includes/features.inc
Normal file
23
sites/all/modules/custom_formatters/includes/features.inc
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Features module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_features_pipe_component_alter().
|
||||
*/
|
||||
function custom_formatters_features_pipe_field_alter(&$pipe, $data, $export) {
|
||||
foreach ($data as $id) {
|
||||
list($entity_type, $bundle_name, $field_name) = explode('-', $id);
|
||||
$field = field_info_instance($entity_type, $field_name, $bundle_name);
|
||||
foreach ($field['display'] as $display) {
|
||||
if (isset($display['module']) && $display['module'] == 'custom_formatters') {
|
||||
$formatter = custom_formatters_crud_load(drupal_substr($display['type'], 18));
|
||||
if ($formatter && isset($formatter->export_type) && $formatter->export_type == EXPORT_IN_DATABASE) {
|
||||
$pipe['formatters'][$formatter->name] = $formatter->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
127
sites/all/modules/custom_formatters/includes/field.inc
Normal file
127
sites/all/modules/custom_formatters/includes/field.inc
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Field module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_info().
|
||||
*/
|
||||
function custom_formatters_field_formatter_info() {
|
||||
$formatters = array();
|
||||
$settings = variable_get('custom_formatters_settings', array('label_prefix' => TRUE, 'label_prefix_value' => t('Custom')));
|
||||
|
||||
foreach (custom_formatters_crud_load_all(TRUE) as $key => $formatter) {
|
||||
$label = $settings['label_prefix'] ? "{$settings['label_prefix_value']}: {$formatter->label}" : $formatter->label;
|
||||
$formatters["custom_formatters_{$key}"] = array(
|
||||
'label' => $label,
|
||||
'field types' => drupal_explode_tags($formatter->field_types),
|
||||
);
|
||||
|
||||
if (isset($formatter->fapi)) {
|
||||
ob_start();
|
||||
eval($formatter->fapi);
|
||||
ob_get_clean();
|
||||
|
||||
if (isset($form)) {
|
||||
$formatters["custom_formatters_{$key}"]['settings'] = array();
|
||||
foreach ($form as $form_key => $element) {
|
||||
$formatters["custom_formatters_{$key}"]['settings'][$form_key] = isset($element['#default_value']) ? $element['#default_value'] : '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $formatters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_settings_summary().
|
||||
*/
|
||||
function custom_formatters_field_formatter_settings_summary($field, $instance, $view_mode) {
|
||||
$display = $instance['display'][$view_mode];
|
||||
$settings = $display['settings'];
|
||||
$formatter = custom_formatters_crud_load(drupal_substr($display['type'], 18));
|
||||
|
||||
$summary = '';
|
||||
|
||||
if (isset($formatter->fapi)) {
|
||||
ob_start();
|
||||
eval($formatter->fapi);
|
||||
ob_get_clean();
|
||||
|
||||
if (isset($form)) {
|
||||
foreach ($form as $key => $element) {
|
||||
if (isset($element['#type']) && !in_array($element['#type'], array('fieldset'))) {
|
||||
$value = empty($settings[$key]) ? '<em>' . t('Empty') . '</em>' : $settings[$key];
|
||||
$value = is_array($value) ? implode(', ', array_filter($value)) : $value;
|
||||
$summary .= "{$element['#title']}: {$value}<br />";
|
||||
}
|
||||
}
|
||||
$summary = !empty($summary) ? $summary : ' ';
|
||||
}
|
||||
}
|
||||
|
||||
return $summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_settings_form().
|
||||
*/
|
||||
function custom_formatters_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
|
||||
$display = $instance['display'][$view_mode];
|
||||
$settings = $display['settings'];
|
||||
$formatter = custom_formatters_crud_load(drupal_substr($display['type'], 18));
|
||||
|
||||
$element = array();
|
||||
|
||||
if (isset($formatter->fapi)) {
|
||||
ob_start();
|
||||
eval($formatter->fapi);
|
||||
ob_get_clean();
|
||||
|
||||
if (isset($form)) {
|
||||
$element = $form;
|
||||
foreach (array_keys($element) as $key) {
|
||||
$element[$key]['#default_value'] = $settings[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_view().
|
||||
*/
|
||||
function custom_formatters_field_formatter_view($obj_type, $object, $field, $instance, $langcode, $items, $display, $formatter = NULL) {
|
||||
$element = array();
|
||||
|
||||
$formatter = empty($formatter) ? custom_formatters_crud_load(drupal_substr($display['type'], 18)) : $formatter;
|
||||
if (isset($formatter) && !empty($items)) {
|
||||
$engines = module_invoke_all('custom_formatters_engine_info');
|
||||
$engine = $formatter->mode;
|
||||
if (isset($engines[$engine]['file']) && file_exists($engines[$engine]['file'])) {
|
||||
require_once $engines[$engine]['file'];
|
||||
}
|
||||
|
||||
if (function_exists($function = $engines[$engine]['callbacks']['render'])) {
|
||||
$element = $function($formatter, $obj_type, $object, $field, $instance, $langcode, $items, $display);
|
||||
if (is_string($element)) {
|
||||
$element = array(
|
||||
array(
|
||||
'#markup' => $element,
|
||||
),
|
||||
);
|
||||
}
|
||||
foreach (element_children($element) as $delta) {
|
||||
$element[$delta]['#cf_options'] = isset($display['#cf_options']) ? $display['#cf_options'] : array();
|
||||
}
|
||||
}
|
||||
|
||||
// Allow other modules to modify the element.
|
||||
drupal_alter('custom_formatters_field_formatter_view_element', $element, $formatter);
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
208
sites/all/modules/custom_formatters/includes/form_builder.inc
Normal file
208
sites/all/modules/custom_formatters/includes/form_builder.inc
Normal file
@@ -0,0 +1,208 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Form Builder module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_form_alter_alter() on behalf of
|
||||
* form_builder.module.
|
||||
*/
|
||||
function form_builder_custom_formatters_form_alter_alter(&$form, &$form_state, $form_id) {
|
||||
if (in_array($form_id, array('ctools_export_ui_edit_item_form', 'ctools_export_ui_edit_item_wizard_form')) && isset($form['#formatters']) && isset($form['engine']['settings'])) {
|
||||
if ($form_state['op'] == 'add' || ($form_state['op'] == 'edit' && !custom_formatters_formatter_is_active($form_state['item']))) {
|
||||
drupal_add_css(drupal_get_path('module', 'custom_formatters') . '/styles/custom_formatters.form_builder.css');
|
||||
|
||||
$form['engine']['settings'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Formatter settings'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
|
||||
module_load_include('inc', 'form_builder', 'includes/form_builder.admin');
|
||||
module_load_include('inc', 'form_builder', 'includes/form_builder.api');
|
||||
module_load_include('inc', 'form_builder', 'includes/form_builder.cache');
|
||||
|
||||
$form_type = 'custom_formatters';
|
||||
$form_id = drupal_substr($form['#build_id'], 0, 32);
|
||||
|
||||
// Set the current form type (used for display of the sidebar block).
|
||||
form_builder_active_form($form_type, $form_id);
|
||||
|
||||
// Load the current state of the form.
|
||||
$form_structure = _custom_formatters_form_builder_load_form($form['#item'], $form_id);
|
||||
|
||||
$form['engine']['settings']['preview'] = form_builder_preview($form, $form_state, $form_structure, $form_type, $form_id);
|
||||
$form['#submit'][] = 'custom_formatters_form_builder_submit';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function custom_formatters_form_builder_submit($form, &$form_state) {
|
||||
module_load_include('inc', 'form_builder', 'includes/form_builder.admin');
|
||||
module_load_include('inc', 'form_builder', 'includes/form_builder.api');
|
||||
module_load_include('inc', 'form_builder', 'includes/form_builder.cache');
|
||||
|
||||
// @TODO - Reproduce this functionality or require form_builder_examples.module.
|
||||
include drupal_get_path('module', 'form_builder') . '/examples/form_builder_examples.module';
|
||||
|
||||
$form_id = drupal_substr($form['form_build_id']['#value'], 0, 32);
|
||||
$form_cache = form_builder_cache_load('custom_formatters', $form_id);
|
||||
if (is_array($form_cache)) {
|
||||
$form_state['item']->fapi = form_builder_examples_export_recurse($form_cache);
|
||||
}
|
||||
|
||||
// Remove the cached form_builder form.
|
||||
form_builder_cache_delete('custom_formatters', $form_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Form Builder form.
|
||||
*/
|
||||
function _custom_formatters_form_builder_load_form($formatter, $form_id) {
|
||||
$form = array();
|
||||
|
||||
// Load form from cache during AJAX callback.
|
||||
if (strstr(request_uri(), 'system/ajax')) {
|
||||
$form = form_builder_cache_load('custom_formatters', $form_id);
|
||||
}
|
||||
|
||||
// Load form from formatter.
|
||||
elseif (!empty($formatter->name) && isset($formatter->fapi)) {
|
||||
ob_start();
|
||||
eval($formatter->fapi);
|
||||
ob_get_clean();
|
||||
|
||||
if (isset($form)) {
|
||||
foreach ($form as $key => &$element) {
|
||||
$element['#key'] = $key;
|
||||
$element['#form_builder'] = array(
|
||||
'element_id' => $key,
|
||||
'element_type' => $element['#type'],
|
||||
'configurable' => TRUE,
|
||||
'removable' => TRUE,
|
||||
);
|
||||
}
|
||||
}
|
||||
form_builder_cache_save('custom_formatters', $form_id, $form);
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_builder_types().
|
||||
*/
|
||||
function custom_formatters_form_builder_types() {
|
||||
$fields = array();
|
||||
|
||||
$fields['select'] = array(
|
||||
'title' => t('Select list'),
|
||||
'properties' => array(
|
||||
'title',
|
||||
'description',
|
||||
'default_value',
|
||||
'required',
|
||||
'options',
|
||||
'multiple', // Handled by options element.
|
||||
'key_type', // Handled by options element.
|
||||
'key_type_toggle', // Handled by options element.
|
||||
'key_type_toggled', // Handled by options element.
|
||||
'key',
|
||||
),
|
||||
'default' => array(
|
||||
'#title' => t('New select list'),
|
||||
'#type' => 'select',
|
||||
'#options' => array('1' => 'one', '2' => 'two', '3' => 'three'),
|
||||
'#multiple_toggle' => TRUE,
|
||||
),
|
||||
);
|
||||
|
||||
$fields['checkboxes'] = array(
|
||||
'title' => t('Checkboxes'),
|
||||
'properties' => array(
|
||||
'title',
|
||||
'description',
|
||||
'default_value',
|
||||
'required',
|
||||
'options',
|
||||
'multiple',
|
||||
'key_type', // Handled by options element.
|
||||
'key_type_toggle', // Handled by options element.
|
||||
'key_type_toggled', // Handled by options element.
|
||||
'key',
|
||||
),
|
||||
'default' => array(
|
||||
'#title' => t('New checkboxes'),
|
||||
'#type' => 'checkboxes',
|
||||
'#options' => array('one' => 'one', 'two' => 'two', 'three' => 'three'),
|
||||
),
|
||||
);
|
||||
|
||||
$fields['radios'] = array(
|
||||
'title' => t('Radios'),
|
||||
'properties' => array(
|
||||
'title',
|
||||
'description',
|
||||
'default_value',
|
||||
'required',
|
||||
'options',
|
||||
'key_type', // Handled by options element.
|
||||
'key_type_toggle', // Handled by options element.
|
||||
'key_type_toggled', // Handled by options element.
|
||||
'key',
|
||||
),
|
||||
'default' => array(
|
||||
'#title' => t('New radios'),
|
||||
'#type' => 'radios',
|
||||
'#options' => array('one' => 'one', 'two' => 'two', 'three' => 'three'),
|
||||
),
|
||||
);
|
||||
|
||||
$fields['textfield'] = array(
|
||||
'title' => t('Textfield'),
|
||||
'properties' => array(
|
||||
'title',
|
||||
'description',
|
||||
'field_prefix',
|
||||
'field_suffix',
|
||||
'default_value',
|
||||
'required',
|
||||
'size',
|
||||
'key',
|
||||
),
|
||||
'default' => array(
|
||||
'#title' => t('New textfield'),
|
||||
'#type' => 'textfield',
|
||||
),
|
||||
);
|
||||
|
||||
$fields['textarea'] = array(
|
||||
'title' => t('Textarea'),
|
||||
'properties' => array(
|
||||
'title',
|
||||
'description',
|
||||
'default_value',
|
||||
'required',
|
||||
'rows',
|
||||
'cols',
|
||||
'key',
|
||||
),
|
||||
'default' => array(
|
||||
'#title' => t('New textarea'),
|
||||
'#type' => 'textarea',
|
||||
),
|
||||
);
|
||||
|
||||
// Allow other modules to modify the fields.
|
||||
drupal_alter('custom_formatters_form_builder_types', $fields);
|
||||
|
||||
return array(
|
||||
'custom_formatters' => $fields
|
||||
);
|
||||
}
|
109
sites/all/modules/custom_formatters/includes/help.inc
Normal file
109
sites/all/modules/custom_formatters/includes/help.inc
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Help module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_help().
|
||||
*/
|
||||
function custom_formatters_help($path, $arg) {
|
||||
switch ($path) {
|
||||
case 'admin/help#custom_formatters':
|
||||
$output = '<h3>' . t('Table of Contents') . "</h3>\n"
|
||||
. '<a href="#about">' . t('About') . '</a> | <a href="#create">' . t('Creating a Formatter') . '</a> | <a href="#test">' . t('Testing a Formatter') . '</a> | <a href="#use">' . t('Using a Formatter') . '</a> | <a href="#cfcom">' . t('CustomFormatters.com') . "</a>\n"
|
||||
. "<p> </p>\n"
|
||||
. '<h3><a name="about"></a>' . t('About') . "</h3>\n"
|
||||
. "<p>\n"
|
||||
. ' ' . t('The Custom Formatters module is a utility to simplify the creation of Field Formatters, which can be used to theme the output of a Field via the Field UI, Views, Display Suite, Wysiwyg Fields and many other modules.') . "\n"
|
||||
. "</p>\n"
|
||||
. "<p>\n"
|
||||
. ' ' . t('Field Formatters created within the Custom Formatters interface can be used as is or exported as either a standard Drupal API Field Formatter or as a Custom Formatters CTools Exportable.')
|
||||
. "</p>\n"
|
||||
. "<p> </p>\n"
|
||||
. '<h3><a name="create"></a>' . t('Creating a Formatter') . "</h3>\n"
|
||||
. "<p>\n"
|
||||
. ' ' . t('Formatters can be created via the Formatters interface (!cfui) by clicking the !add button.', array('!cfui' => l(t('Administration » Structure » Formatters'), 'admin/structure/formatters', array('html' => TRUE)), '!add' => l(t('Add'), 'admin/structure/formatters/add'))) . "<br />\n"
|
||||
. "</p>\n"
|
||||
. "<p>\n"
|
||||
. ' ' . t('The Formatter add/edit form may vary based on the Format you choose, but in general all Formatters should consist of the following:') . "\n"
|
||||
. "</p>\n"
|
||||
. "<dl>\n"
|
||||
. ' <dt><strong>' . t('Formatter name / Machine name') . "</strong></dt>\n"
|
||||
. ' <dd>' . t('The Formatter name and the Machine name, in general generated via the same field, are the Human readable name and the unique identifier for the Formatter.') . "</dd>\n"
|
||||
. ' <dt><strong>' . t('Description') . "</strong></dt>\n"
|
||||
. ' <dd>' . t('Used purely for administration purposes, displays as a tooltip on the Formatters UI and in the Formatter add/edit form only.') . "</dd>\n"
|
||||
. ' <dt><strong>' . t('Format') . "</strong></dt>\n"
|
||||
. " <dd>\n"
|
||||
. ' ' . t('The format that the Formatter is to be created in, may change the Formatters add/edit form.') . "<br />\n"
|
||||
. ' ' . t('Two format engines are supplied out of the box, <strong>PHP</strong> and <strong>HTML + Tokens</strong>.') . "\n"
|
||||
. " </dd>\n"
|
||||
. ' <dt><strong>' . t('Field type(s)') . "</strong></dt>\n"
|
||||
. " <dd>\n"
|
||||
. ' ' . t('Which field type(s) the Formatter will apply to (file, image, text, etc).') . "<br />\n"
|
||||
. ' ' . t('The value of this field should be the machine name of the field type, not the name of a field you have created on a Content type, available values will be auto-completed as you type.') . "\n"
|
||||
. " </dd>\n"
|
||||
. ' <dt><strong>' . t('Formatter') . "</strong></dt>\n"
|
||||
. " <dd>\n"
|
||||
. ' ' . t('The actual value of the Formatter, style depending on the chosen Format:') . "<br /><br />\n";
|
||||
|
||||
$items = array();
|
||||
$engines = module_invoke_all('custom_formatters_engine_info');
|
||||
foreach ($engines as $engine) {
|
||||
if (isset($engine['file']) && file_exists($engine['file'])) {
|
||||
require_once $engine['file'];
|
||||
}
|
||||
if (isset($engine['callbacks']['help']) && function_exists($engine['callbacks']['help'])) {
|
||||
$items[] = ' <strong>' . $engine['label'] . "</strong><br />\n"
|
||||
. ' ' . $engine['callbacks']['help']()
|
||||
. "<br /><br />\n";
|
||||
}
|
||||
}
|
||||
if (count($items) > 0) {
|
||||
$output .= theme('item_list', array('items' => $items));
|
||||
}
|
||||
|
||||
$output .= " </dd>\n"
|
||||
. ' <dt><strong>' . t('Formatter Settings') . "</strong></dt>\n"
|
||||
. " <dd>\n"
|
||||
. " <p>\n"
|
||||
. ' ' . t('As of Custom Formatters 7.x-2.1, the PHP format now supports Formatter Settings, which allow you PHP formatters to be configured on each instance of use (Display settings per content type, etc).') . "\n"
|
||||
. " </p>\n"
|
||||
. " <p>\n"
|
||||
. ' ' . t('To enable the Formatter Settings functionality uou need to download and enable the <a href="http://drupal.org/project/form_builder">Form Builder</a> module, once enabled, you will be able to drag and drop fields to create your settings form, and then access the settings inside of your Formatter.') . "\n"
|
||||
. " </p>\n"
|
||||
. " <p>\n"
|
||||
. ' ' . t('The <a href="!url">Example: Image (PHP)</a> Formatter demonstrates how Formatter Settings can be used.', array('!url' => url('admin/structure/formatters/list/example_php_image/edit'))) . "\n"
|
||||
. " </p>\n"
|
||||
. " </dd>\n"
|
||||
. "</dl>\n"
|
||||
. "<p> </p>\n"
|
||||
. '<h3><a name="test"></a>' . t('Testing a Formatter') . "</h3>\n"
|
||||
. "<p>\n"
|
||||
. ' ' . t('The Formatter add/edit form includes a Preview tool allowing quick testing of the Formatter on live content.') . "\n"
|
||||
. "</p>\n"
|
||||
. "<p>\n"
|
||||
. ' ' . t('To do so all you need to do is expand the Preview fieldset and select a populated Entity type (Node, Comment, etc), Bundle (Article, Basic page, etc) and Field (Image, Tags, etc) combination, select the desired Entity for testing and hit the <strong>Preview</strong> button.') . "\n"
|
||||
. "</p>\n"
|
||||
. "<p>\n"
|
||||
. ' ' . t('Enabling the <a href="http://drupal.org/project/devel">Devel</a> and Devel Generate module (packaged with the Devel module) adds additional debugging information into your Formatter preview.') . "\n"
|
||||
. "</p>\n"
|
||||
. "<p> </p>\n"
|
||||
. '<h3><a name="use"></a>' . t('Using a Formatter') . "</h3>\n"
|
||||
. "<p>\n"
|
||||
. ' ' . t('Formatters can be used on a variety of different modules, including, but not limited to, Drupal Core Field UI, Views, Display Suite and Insert modules.') . "\n"
|
||||
. "</p>\n"
|
||||
. "<p>\n"
|
||||
. ' ' . t('Instructions on how to apply Formatters to Fields varies from module to module, but in general there will be a Format or Formatter field with the Field configuton within said module.') . "\n"
|
||||
. "</p>\n"
|
||||
. "<p> </p>\n"
|
||||
. '<h3><a name="cfcom"></a>' . t('<a href="http://customformatters.com">CustomFormatters.com</a>') . "</h3>\n"
|
||||
. "<p>\n"
|
||||
. ' ' . t('<a href="http://customformatters.com">CustomFormatters.com</a> is a Custom Formatters repository, containing a every growing list of reusable Custom Formatters available as raw code snippets, exportables and as Drupal API field formatters, it\'s a useful resouce to see examples of how to create Formatters.') . "\n"
|
||||
. "</p>\n"
|
||||
. "<p> </p>\n"
|
||||
. "<p> </p>\n";
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
63
sites/all/modules/custom_formatters/includes/image.inc
Normal file
63
sites/all/modules/custom_formatters/includes/image.inc
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Image module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_theme_alter() on behalf of image.module.
|
||||
*/
|
||||
function image_custom_formatters_theme_alter(&$theme) {
|
||||
$theme['custom_formatters_image_styles'] = array(
|
||||
'render element' => 'element',
|
||||
'file' => 'includes/image.inc',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_element_info_alter() on behalf of
|
||||
* image.module.
|
||||
*/
|
||||
function image_custom_formatters_element_info_alter(&$types) {
|
||||
$types['custom_formatters_image_styles'] = array(
|
||||
'#input' => TRUE,
|
||||
'#multiple' => FALSE,
|
||||
'#process' => array('form_process_select', 'ajax_process_form'),
|
||||
'#theme' => 'custom_formatters_image_styles',
|
||||
'#theme_wrappers' => array('form_element'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_form_builder_types_alter() on behalf of
|
||||
* image.module.
|
||||
*/
|
||||
function image_custom_formatters_form_builder_types_alter(&$fields) {
|
||||
$fields['image_styles'] = array(
|
||||
'title' => t('Image styles'),
|
||||
'properties' => array(
|
||||
'title',
|
||||
'description',
|
||||
'default_value',
|
||||
'required',
|
||||
'key',
|
||||
),
|
||||
'default' => array(
|
||||
'#title' => t('New styles selector'),
|
||||
'#type' => 'custom_formatters_image_styles',
|
||||
'#multiple_toggle' => TRUE,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme callback for Custom Formatters Image Styles element.
|
||||
*/
|
||||
function theme_custom_formatters_image_styles($variables) {
|
||||
$element = $variables['element'];
|
||||
$element['#options'] = image_style_options();
|
||||
element_set_attributes($element, array('id', 'name', 'size'));
|
||||
_form_set_class($element, array('form-select'));
|
||||
|
||||
return '<select' . drupal_attributes($element['#attributes']) . '>' . form_select_options($element) . '</select>';
|
||||
}
|
53
sites/all/modules/custom_formatters/includes/insert.inc
Normal file
53
sites/all/modules/custom_formatters/includes/insert.inc
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Insert module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_insert_styles().
|
||||
*/
|
||||
function custom_formatters_insert_styles() {
|
||||
$insert_styles = array();
|
||||
$supported = array('image', 'file');
|
||||
$settings = variable_get('custom_formatters_settings', array('label_prefix' => TRUE, 'label_prefix_value' => t('Custom')));
|
||||
|
||||
foreach (custom_formatters_crud_load_all() as $formatter) {
|
||||
if (array_intersect($supported, drupal_explode_tags($formatter->field_types))) {
|
||||
$label = $settings['label_prefix'] ? "{$settings['label_prefix_value']}: {$formatter->label}" : $formatter->label;
|
||||
$insert_styles["custom_formatters_{$formatter->name}"] = array(
|
||||
'label' => $label,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $insert_styles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_insert_content().
|
||||
*/
|
||||
function custom_formatters_insert_content($item, $style, $widget) {
|
||||
$menu_item = menu_get_item();
|
||||
$form_build_id = end($menu_item['page_arguments']);
|
||||
|
||||
if (is_string($form_build_id)) {
|
||||
$form = form_get_cache($form_build_id, $form_state = array());
|
||||
|
||||
$obj_type = $form['#entity_type'];
|
||||
$object = $form["#{$obj_type}"];
|
||||
$field = field_info_field($menu_item['page_arguments'][0]);
|
||||
$instance = field_info_instance($obj_type, $field['field_name'], $form['#bundle']);
|
||||
$langcode = field_language($obj_type, $object, $field['field_name']);
|
||||
$items = array((array) file_load($item['fid']));
|
||||
$display = $instance['display']['default'];
|
||||
$formatter = custom_formatters_crud_load(drupal_substr($style['name'], 18));
|
||||
|
||||
$display['cf_options'] = array(
|
||||
'#contextual_links' => FALSE,
|
||||
);
|
||||
|
||||
return render(custom_formatters_field_formatter_view($obj_type, $object, $field, $instance, $langcode, $items, $display, $formatter));
|
||||
}
|
||||
return FALSE;
|
||||
}
|
20
sites/all/modules/custom_formatters/includes/libraries.inc
Normal file
20
sites/all/modules/custom_formatters/includes/libraries.inc
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Libraries API integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_form_alter_alter() on behalf of
|
||||
* libraries.module.
|
||||
*/
|
||||
function libraries_custom_formatters_form_alter_alter(&$form, $form_state, $form_id) {
|
||||
if (in_array($form_id, array('ctools_export_ui_edit_item_form', 'ctools_export_ui_edit_item_wizard_form')) && isset($form['#formatters'])) {
|
||||
// EditArea library support.
|
||||
if (in_array('editarea', array_keys(libraries_get_libraries()))) {
|
||||
$form['#attached']['js'][] = libraries_get_path('editarea') . '/edit_area/edit_area_full.js';
|
||||
|
||||
$form['engine']['code']['#resizable'] = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
43
sites/all/modules/custom_formatters/includes/node.inc
Normal file
43
sites/all/modules/custom_formatters/includes/node.inc
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Node module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_devel_generate_info() on behalf of
|
||||
* node.module.
|
||||
*/
|
||||
function node_custom_formatters_devel_generate_info() {
|
||||
return array(
|
||||
'node' => array(
|
||||
'process callback' => 'custom_formatters_node_devel_generate_process',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process callback for Node Devel Generate integration.
|
||||
*/
|
||||
function custom_formatters_node_devel_generate_process($form_state) {
|
||||
module_load_include('inc', 'devel_generate', 'devel_generate');
|
||||
|
||||
$object = new stdClass();
|
||||
$object->nid = mt_rand(1, 100);
|
||||
$object->type = $form_state['values']['preview']['bundle'];
|
||||
$object->uid = $GLOBALS['user']->uid;
|
||||
$type = node_type_get_type($object);
|
||||
$object->title = $type->has_title ? devel_create_greeking(mt_rand(2, rand(4, 10)), TRUE) : '';
|
||||
$object->revision = mt_rand(0, 1);
|
||||
$object->promote = mt_rand(0, 1);
|
||||
|
||||
devel_generate_set_language(array(), $object);
|
||||
|
||||
$object->created = REQUEST_TIME;
|
||||
|
||||
// Populate all core fields on behalf of field.module
|
||||
module_load_include('inc', 'devel_generate', 'devel_generate.fields');
|
||||
devel_generate_fields($object, $form_state['values']['preview']['entity_type'], $object->type);
|
||||
|
||||
return $object;
|
||||
}
|
38
sites/all/modules/custom_formatters/includes/system.inc
Normal file
38
sites/all/modules/custom_formatters/includes/system.inc
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* System module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_init().
|
||||
*/
|
||||
function custom_formatters_init() {
|
||||
module_invoke_all('custom_formatters_init');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_element_info().
|
||||
*/
|
||||
function custom_formatters_element_info() {
|
||||
$types = array();
|
||||
drupal_alter('custom_formatters_element_info', $types);
|
||||
return $types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
function custom_formatters_theme() {
|
||||
$theme = array();
|
||||
drupal_alter('custom_formatters_theme', $theme);
|
||||
return $theme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_alter().
|
||||
*/
|
||||
function custom_formatters_form_alter(&$form, &$form_state, $form_id) {
|
||||
drupal_alter('custom_formatters_form_alter', $form, $form_state, $form_id);
|
||||
drupal_alter("custom_formatters_form_{$form_id}_alter", $form, $form_state);
|
||||
}
|
42
sites/all/modules/custom_formatters/includes/taxonomy.inc
Normal file
42
sites/all/modules/custom_formatters/includes/taxonomy.inc
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Taxonomy module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_devel_generate_info() on behalf of
|
||||
* taxonomy.module.
|
||||
*/
|
||||
function taxonomy_custom_formatters_devel_generate_info() {
|
||||
return array(
|
||||
'taxonomy_term' => array(
|
||||
'process callback' => 'custom_formatters_taxonomy_term_devel_generate_process',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process callback for Taxonomy term Devel Generate integration.
|
||||
*/
|
||||
function custom_formatters_taxonomy_term_devel_generate_process($form_state) {
|
||||
module_load_include('inc', 'devel_generate', 'devel_generate');
|
||||
|
||||
$vocab = taxonomy_vocabulary_machine_name_load($form_state['values']['preview']['bundle']);
|
||||
|
||||
$object = new stdClass();
|
||||
$object->tid = mt_rand(1, 100);
|
||||
$object->vid = $vocab->vid;
|
||||
$object->name = devel_generate_word(mt_rand(2, 12));
|
||||
$object->description = "description of {$object->name}";
|
||||
$object->format = filter_fallback_format();
|
||||
$object->weight = mt_rand(0, 10);
|
||||
$object->vocabulary_machine_name = $form_state['values']['preview']['bundle'];
|
||||
$object->language = LANGUAGE_NONE;
|
||||
|
||||
// Populate all core fields on behalf of field.module
|
||||
module_load_include('inc', 'devel_generate', 'devel_generate.fields');
|
||||
devel_generate_fields($object, 'taxonomy_term', $object->vocabulary_machine_name);
|
||||
|
||||
return $object;
|
||||
}
|
55
sites/all/modules/custom_formatters/includes/token.inc
Normal file
55
sites/all/modules/custom_formatters/includes/token.inc
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Token module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_form_ctools_export_ui_edit_item_form_alter_alter()
|
||||
* on behalf of token.module.
|
||||
*/
|
||||
function token_custom_formatters_form_ctools_export_ui_edit_item_form_alter_alter(&$form, $form_state) {
|
||||
if (isset($form['#formatters']) && $form['#formatters'] && 'token' == $form['info']['mode']['#default_value']) {
|
||||
// Add token tree.
|
||||
$fieldable = array();
|
||||
$entity_types = entity_get_info();
|
||||
foreach ($entity_types as $entity_type => $entity) {
|
||||
if ($entity['fieldable']) {
|
||||
$fieldable[] = $entity['token type'];
|
||||
}
|
||||
}
|
||||
$token_types = $fieldable;
|
||||
$field_type = $form['engine']['field_types']['#default_value'];
|
||||
drupal_alter('custom_formatters_token_tree_types', $token_types, $field_type);
|
||||
$form['engine']['tokens'] = array(
|
||||
'#title' => t('Tokens'),
|
||||
'#type' => 'fieldset',
|
||||
'#description' => theme('token_tree', array('token_types' => $token_types)),
|
||||
'#weight' => 50,
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_form_builder_types_alter() on behalf of
|
||||
* token.module.
|
||||
*/
|
||||
function token_custom_formatters_form_builder_types_alter(&$fields) {
|
||||
$fields['token_tree'] = array(
|
||||
'title' => t('Token tree'),
|
||||
'properties' => array(
|
||||
'title',
|
||||
'key'
|
||||
),
|
||||
'default' => array(
|
||||
'#title' => t('Tokens'),
|
||||
'#type' => 'fieldset',
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#theme' => 'token_tree',
|
||||
'#token_types' => 'all',
|
||||
),
|
||||
);
|
||||
}
|
42
sites/all/modules/custom_formatters/includes/user.inc
Normal file
42
sites/all/modules/custom_formatters/includes/user.inc
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* User module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_custom_formatters_devel_generate_info() on behalf of
|
||||
* user.module.
|
||||
*/
|
||||
function user_custom_formatters_devel_generate_info() {
|
||||
return array(
|
||||
'user' => array(
|
||||
'process callback' => 'custom_formatters_user_devel_generate_process',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process callback for User Devel Generate integration.
|
||||
*/
|
||||
function custom_formatters_user_devel_generate_process($form_state) {
|
||||
module_load_include('inc', 'devel_generate', 'devel_generate');
|
||||
|
||||
$url = parse_url($GLOBALS['base_url']);
|
||||
|
||||
$object = new stdClass();
|
||||
$object->uid = mt_rand(3, 100);
|
||||
$object->name = devel_generate_word(mt_rand(6, 12));
|
||||
$object->pass = user_password();
|
||||
$object->mail = "{$object->name}@{$url['host']}";
|
||||
$object->status = 1;
|
||||
$object->created = 1;
|
||||
$object->roles = drupal_map_assoc(array(DRUPAL_AUTHENTICATED_RID));
|
||||
$object->language = LANGUAGE_NONE;
|
||||
|
||||
// Populate all core fields on behalf of field.module
|
||||
module_load_include('inc', 'devel_generate', 'devel_generate.fields');
|
||||
devel_generate_fields($object, 'user', 'user');
|
||||
|
||||
return $object;
|
||||
}
|
@@ -0,0 +1,478 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* CTools Export UI plugin for SexyBookmarks profiles.
|
||||
*/
|
||||
|
||||
/**
|
||||
* CTools Export UI required function for plugin definition
|
||||
*/
|
||||
function custom_formatters_custom_formatters_ctools_export_ui() {
|
||||
return array(
|
||||
'schema' => 'formatters',
|
||||
'access' => 'administer custom formatters',
|
||||
|
||||
'menu' => array(
|
||||
'menu prefix' => 'admin/structure',
|
||||
'menu item' => 'formatters',
|
||||
'menu title' => 'Formatters',
|
||||
'menu description' => 'Administer Formatters.',
|
||||
),
|
||||
|
||||
'title singular' => t('formatter'),
|
||||
'title singular proper' => t('Formatter'),
|
||||
'title plural' => t('formatters'),
|
||||
'title plural proper' => t('Formatters'),
|
||||
|
||||
'handler' => 'custom_formatters_ui',
|
||||
|
||||
'form' => array(
|
||||
'settings' => 'custom_formatters_export_ui_form',
|
||||
'submit' => 'custom_formatters_export_ui_form_submit',
|
||||
),
|
||||
|
||||
'export' => array(
|
||||
'admin_title' => 'label',
|
||||
'admin_description' => 'description',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom Formatters settings form.
|
||||
*/
|
||||
function custom_formatters_export_ui_form(&$form, &$form_state) {
|
||||
$form['#attached'] = array(
|
||||
'css' => array(
|
||||
drupal_get_path('module', 'custom_formatters') . '/styles/custom_formatters.css',
|
||||
),
|
||||
'js' => array(
|
||||
drupal_get_path('module', 'custom_formatters') . '/scripts/custom_formatters.admin.js',
|
||||
),
|
||||
);
|
||||
|
||||
$item = $form_state['item'];
|
||||
$form['#item'] = $item;
|
||||
$form['#formatters'] = TRUE;
|
||||
|
||||
$engines = module_invoke_all('custom_formatters_engine_info');
|
||||
$engine = !empty($form_state['values']['mode']) ? $form_state['values']['mode'] : (
|
||||
!empty($item->mode) ? $item->mode : key($engines)
|
||||
);
|
||||
if (isset($engines[$engine]['file']) && file_exists($engines[$engine]['file'])) {
|
||||
require_once $engines[$engine]['file'];
|
||||
}
|
||||
|
||||
$disable = FALSE;
|
||||
if ($form_state['op'] != 'add') {
|
||||
$disable = custom_formatters_formatter_is_active($item);
|
||||
if ($disable) {
|
||||
drupal_set_message(t('As the Formatter is currently in use, certain features have been disabled.'), 'warning');
|
||||
}
|
||||
}
|
||||
|
||||
$form['info']['#title'] = t('Basic information');
|
||||
$form['info']['#type'] = 'fieldset';
|
||||
$form['info']['#collapsible'] = TRUE;
|
||||
$form['info']['#collapsed'] = $form_state['op'] != 'add';
|
||||
|
||||
$form['info']['label']['#title'] = t('Formatter name');
|
||||
|
||||
$form['info']['description'] = array(
|
||||
'#title' => t('Description'),
|
||||
'#type' => 'textarea',
|
||||
'#default_value' => $item->description,
|
||||
);
|
||||
|
||||
$options = array();
|
||||
foreach ($engines as $key => $option) {
|
||||
$options[$key] = $option['label'];
|
||||
}
|
||||
$form['info']['mode'] = array(
|
||||
'#title' => t('Format'),
|
||||
'#type' => 'select',
|
||||
'#options' => $options,
|
||||
'#default_value' => $engine,
|
||||
'#ajax' => array(
|
||||
'callback' => 'custom_formatters_export_ui_form_js',
|
||||
'wrapper' => 'engine-wrapper',
|
||||
),
|
||||
);
|
||||
|
||||
$form['engine'] = array(
|
||||
'#type' => 'container',
|
||||
'#prefix' => '<div id="engine-wrapper">',
|
||||
'#suffix' => '</div>'
|
||||
);
|
||||
$form['engine']['field_types'] = array(
|
||||
'#title' => t('Field type(s)'),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $item->field_types,
|
||||
'#required' => TRUE,
|
||||
'#description' => t('Enter a comma-separated list of field types (file, image, text, text_long, etc).'),
|
||||
'#autocomplete_path' => 'js/formatters/autocomplete',
|
||||
'#ajax' => array(
|
||||
'callback' => 'custom_formatters_export_ui_form_js',
|
||||
'wrapper' => 'engine-wrapper',
|
||||
),
|
||||
'#disabled' => $disable,
|
||||
);
|
||||
$form['engine']['code'] = array(
|
||||
'#title' => t('Formatter'),
|
||||
'#type' => 'textarea',
|
||||
'#default_value' => !empty($item->code) ? $item->code : '',
|
||||
'#required' => TRUE,
|
||||
'#rows' => 10,
|
||||
);
|
||||
|
||||
$options = _custom_formatters_preview_variables($form, $form_state);
|
||||
$form['engine']['preview'] = array(
|
||||
'#title' => t('Preview'),
|
||||
'#type' => 'fieldset',
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#weight' => 100,
|
||||
'#theme' => 'custom_formatters_export_ui_form_preview',
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
$form['engine']['preview']['entity_type'] = array(
|
||||
'#title' => t('Entity type'),
|
||||
'#type' => 'select',
|
||||
'#options' => $options['entity_types'],
|
||||
'#default_value' => 'node',
|
||||
'#disabled' => empty($options['entity_types']),
|
||||
'#ajax' => array(
|
||||
'callback' => 'custom_formatters_export_ui_form_js',
|
||||
'wrapper' => 'engine-wrapper',
|
||||
),
|
||||
);
|
||||
$form['engine']['preview']['bundle'] = array(
|
||||
'#title' => t('Bundle'),
|
||||
'#type' => 'select',
|
||||
'#options' => $options['bundles'],
|
||||
'#disabled' => empty($options['bundles']),
|
||||
'#ajax' => array(
|
||||
'callback' => 'custom_formatters_export_ui_form_js',
|
||||
'wrapper' => 'engine-wrapper',
|
||||
),
|
||||
);
|
||||
$form['engine']['preview']['field'] = array(
|
||||
'#title' => t('Field'),
|
||||
'#type' => 'select',
|
||||
'#options' => $options['fields'],
|
||||
'#disabled' => empty($options['fields']),
|
||||
'#ajax' => array(
|
||||
'callback' => 'custom_formatters_export_ui_form_js',
|
||||
'wrapper' => 'engine-wrapper',
|
||||
),
|
||||
);
|
||||
$form['engine']['preview']['entity'] = array(
|
||||
'#title' => t('Entity'),
|
||||
'#type' => 'select',
|
||||
'#options' => $options['entities'],
|
||||
'#disabled' => empty($options['entities']),
|
||||
);
|
||||
$form['engine']['preview']['options'] = array(
|
||||
'#type' => 'container',
|
||||
);
|
||||
$form['engine']['preview']['button'] = array(
|
||||
'#type' => 'button',
|
||||
'#value' => t('Preview'),
|
||||
'#ajax' => array(
|
||||
'callback' => 'custom_formatters_export_ui_form_js_preview',
|
||||
'wrapper' => 'preview-wrapper',
|
||||
),
|
||||
'#disabled' => empty($options['entities']),
|
||||
);
|
||||
$form['engine']['preview']['preview'] = array(
|
||||
'#type' => 'container',
|
||||
'#prefix' => '<div id="preview-wrapper">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
|
||||
$engines[$engine]['callbacks']['settings form']($form['engine'], $form_state, $item);
|
||||
|
||||
$form['buttons']['edit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save & Edit'),
|
||||
);
|
||||
}
|
||||
|
||||
function _custom_formatters_preview_variables($form, $form_state) {
|
||||
$options = array();
|
||||
$item = !empty($form_state['values']) ? $form_state['values'] : (array) $form_state['item'];
|
||||
|
||||
// Entity Types
|
||||
$options['entity_types'] = array();
|
||||
$entity_types = entity_get_info();
|
||||
foreach ($entity_types as $key => $entity) {
|
||||
if ($entity['fieldable']) {
|
||||
$options['entity_types'][$key] = $entity['label'];
|
||||
}
|
||||
}
|
||||
|
||||
// Bundles
|
||||
$options['bundles'] = array();
|
||||
if (!empty($options['entity_types'])) {
|
||||
$entity_type = !empty($item['preview']['entity_type']) ? $item['preview']['entity_type'] : 'node';
|
||||
foreach ($entity_types[$entity_type]['bundles'] as $key => $bundle) {
|
||||
$options['bundles'][$key] = $bundle['label'];
|
||||
}
|
||||
}
|
||||
|
||||
// Fields
|
||||
$options['fields'] = array();
|
||||
if (!empty($options['bundles'])) {
|
||||
$bundle = !empty($item['preview']['bundle']) && isset($options['bundles'][$item['preview']['bundle']])
|
||||
? $item['preview']['bundle'] : key($options['bundles']);
|
||||
$fields = field_info_instances($entity_type, $bundle);
|
||||
foreach ($fields as $key => $field) {
|
||||
$field_info = field_info_field_by_id($field['field_id']);
|
||||
if (in_array($field_info['type'], drupal_explode_tags($item['field_types']))) {
|
||||
$options['fields'][$key] = $field['label'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Entities
|
||||
$options['entities'] = array();
|
||||
if (!empty($options['fields'])) {
|
||||
$field = !empty($item['preview']['field']) ? $item['preview']['field'] : key($options['fields']);
|
||||
if (strstr($field, 'field_')) {
|
||||
$query = new EntityFieldQuery();
|
||||
$query->entityCondition('entity_type', $entity_type)
|
||||
->entityCondition('bundle', $bundle)
|
||||
->addTag('random')
|
||||
->range(0, 50)
|
||||
->fieldCondition($field);
|
||||
$result = $query->execute();
|
||||
if (!empty($result)) {
|
||||
$entities = entity_load($entity_type, array_keys($result[$entity_type]));
|
||||
foreach ($entities as $key => $entity) {
|
||||
$options['entities'][$key] = entity_label($entity_type, $entity) . " [eid:{$key}]";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_query_TAG_alter().
|
||||
*/
|
||||
function custom_formatters_query_random_alter($query) {
|
||||
$query->orderRandom();
|
||||
}
|
||||
|
||||
function custom_formatters_export_ui_form_js($form, $form_state) {
|
||||
// Clear messages.
|
||||
drupal_get_messages(NULL, TRUE);
|
||||
|
||||
$engines = module_invoke_all('custom_formatters_engine_info');
|
||||
$engine = $form_state['values']['mode'];
|
||||
if (isset($engines[$engine]['file']) && file_exists($engines[$engine]['file'])) {
|
||||
require_once $engines[$engine]['file'];
|
||||
}
|
||||
|
||||
return $form['engine'];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function custom_formatters_export_ui_form_js_preview($form, $form_state, $object = NULL) {
|
||||
// Clear messages.
|
||||
drupal_get_messages(NULL, TRUE);
|
||||
|
||||
// Build preview elements.
|
||||
$obj_type = $form_state['values']['preview']['entity_type'];
|
||||
if (is_null($object)) {
|
||||
$objects = entity_load($obj_type, array($form_state['values']['preview']['entity']));
|
||||
$object = $objects[$form_state['values']['preview']['entity']];
|
||||
}
|
||||
$field = field_info_field($form_state['values']['preview']['field']);
|
||||
$instance = field_info_instance($obj_type, $field['field_name'], $form_state['values']['preview']['bundle']);
|
||||
$langcode = field_language($obj_type, $object, $field['field_name']);
|
||||
$items = field_get_items($obj_type, $object, $instance['field_name'], $langcode);
|
||||
|
||||
// Prepare field view.
|
||||
$functions = array("{$field['module']}_field_prepare_view", "{$field['module']}_field_load");
|
||||
foreach ($functions as $function) {
|
||||
if (function_exists($function)) {
|
||||
$items = array($items);
|
||||
$function($entity_type, array($entity), $field, array($instance), $langcode, $items, FIELD_LOAD_CURRENT);
|
||||
$items = $items[0];
|
||||
}
|
||||
}
|
||||
|
||||
$display = $instance['display']['default'];
|
||||
// @TODO - Allow this to be done via form_builder.inc or any other Foramtter
|
||||
// Settings integration modules.
|
||||
$display['settings'] = isset($form_state['input']['settings']['preview']) ? $form_state['input']['settings']['preview'] : $display['settings'];
|
||||
// Disable contextual links in preview.
|
||||
$display['#cf_options'] = array('#contextual_links' => FALSE);
|
||||
$formatter = (object) $form_state['values'];
|
||||
|
||||
// Build the preview html.
|
||||
$element = custom_formatters_field_formatter_view($obj_type, $object, $field, $instance, $langcode, $items, $display, $formatter);
|
||||
$variables = array(
|
||||
'element' => array_merge($element, array(
|
||||
'#label_display' => 'hidden',
|
||||
'#title' => NULL,
|
||||
'#items' => $element,
|
||||
'#field_name' => $field['field_name'],
|
||||
'#field_type' => $field['type']
|
||||
)),
|
||||
);
|
||||
foreach (array_keys($element) as $delta) {
|
||||
$variables['item_attributes'][$delta] = NULL;
|
||||
}
|
||||
|
||||
$js = drupal_add_js();
|
||||
$form['engine']['preview']['preview']['content'] = array(
|
||||
'#markup' => theme('field', $variables),
|
||||
);
|
||||
$js = array_diff_assoc(drupal_add_js(), $js);
|
||||
$form['engine']['preview']['preview']['content']['#markup'] .= drupal_get_js('header', $js);
|
||||
|
||||
// Preview debugging; Show the output HTML.
|
||||
if (module_exists('devel') && isset($formatter->preview) && $formatter->preview['options']['dpm']['html']) {
|
||||
dpm(theme('field', $variables));
|
||||
}
|
||||
|
||||
return $form['engine']['preview']['preview'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit callback for Custom Formatters settings form.
|
||||
*/
|
||||
function custom_formatters_export_ui_form_submit(&$form, &$form_state) {
|
||||
field_cache_clear();
|
||||
if ($form_state['values']['op'] == t('Save & Edit')) {
|
||||
$destination = "admin/structure/formatters/list/{$form_state['values']['name']}/edit";
|
||||
$_GET['destination'] = isset($_GET['destination']) ? $destination . "?destination={$_GET['destination']}" : $destination;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a form for displaying an export.
|
||||
*/
|
||||
function custom_formatters_export_ui_export_form($form, &$form_state, $item, $title = '') {
|
||||
$form['mode'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Mode'),
|
||||
'#options' => array(
|
||||
'default' => t('CTools exportable (default)'),
|
||||
'drupal' => t('Drupal API')
|
||||
),
|
||||
'#default_value' => 'default',
|
||||
'#ajax' => array(
|
||||
'callback' => 'custom_formatters_export_ui_export_form_js',
|
||||
'wrapper' => 'export-wrapper',
|
||||
),
|
||||
);
|
||||
|
||||
$form['export'] = array(
|
||||
'#type' => 'container',
|
||||
'#prefix' => '<div id="export-wrapper">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
|
||||
$mode = isset($form_state['values']['mode']) ? $form_state['values']['mode'] : $form['mode']['#default_value'];
|
||||
switch ($mode) {
|
||||
case 'default':
|
||||
$code = ctools_export_crud_export('formatters', $item);
|
||||
break;
|
||||
|
||||
case 'drupal':
|
||||
$engines = module_invoke_all('custom_formatters_engine_info');
|
||||
$engine = $item->mode;
|
||||
if (isset($engines[$engine]['file']) && file_exists($engines[$engine]['file'])) {
|
||||
require_once $engines[$engine]['file'];
|
||||
}
|
||||
|
||||
$module = isset($form_state['values']['module']) ? $form_state['values']['module'] : t('MYMODULE');
|
||||
$form['export']['module'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Module name'),
|
||||
'#default_value' => $module,
|
||||
'#ajax' => array(
|
||||
'callback' => 'custom_formatters_export_ui_export_form_js',
|
||||
'wrapper' => 'export-wrapper',
|
||||
),
|
||||
);
|
||||
|
||||
$code = $engines[$engine]['callbacks']['export']($item, $module);
|
||||
break;
|
||||
}
|
||||
|
||||
$lines = substr_count($code, "\n");
|
||||
$form['export']['code'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#title' => check_plain($title),
|
||||
'#value' => $code,
|
||||
'#rows' => $lines,
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
function custom_formatters_export_ui_export_form_js($form, $form_state) {
|
||||
return $form['export'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Field Types autocomplete callback.
|
||||
*/
|
||||
function custom_formatters_autocomplete($string = '') {
|
||||
// The user enters a comma-separated list of fields. We only autocomplete the last tag.
|
||||
$array = drupal_explode_tags($string);
|
||||
|
||||
// Fetch last field.
|
||||
$last_string = trim(array_pop($array));
|
||||
$matches = array();
|
||||
if ($last_string != '') {
|
||||
$prefix = count($array) ? implode(', ', $array) . ', ' : '';
|
||||
|
||||
$fields = array_keys(field_info_field_types());
|
||||
// Give modules a chance to alter fields.
|
||||
//drupal_alter('custom_formatters_fields', $fields);
|
||||
|
||||
sort($fields);
|
||||
foreach ($fields as $field) {
|
||||
if (preg_match('/^' . drupal_strtolower($last_string) . '/', $field)) {
|
||||
$matches[$prefix . $field] = check_plain($field);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
drupal_json_output($matches);
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme for Preview form.
|
||||
*/
|
||||
function theme_custom_formatters_export_ui_form_preview($variable) {
|
||||
$form = $variable['form'];
|
||||
$output = '';
|
||||
|
||||
$output .= theme('table', array(
|
||||
'rows' => array(
|
||||
array(
|
||||
render($form['entity_type']),
|
||||
render($form['bundle']),
|
||||
render($form['field']),
|
||||
render($form['entity']),
|
||||
),
|
||||
array(
|
||||
array('data' => render($form['options']), 'colspan' => 3),
|
||||
render($form['button'])
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
$output .= render($form['preview']);
|
||||
|
||||
return $output;
|
||||
}
|
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
class custom_formatters_ui extends ctools_export_ui {
|
||||
/**
|
||||
* Build a row based on the item.
|
||||
*
|
||||
* By default all of the rows are placed into a table by the render
|
||||
* method, so this is building up a row suitable for theme('table').
|
||||
* This doesn't have to be true if you override both.
|
||||
*/
|
||||
function list_build_row($item, &$form_state, $operations) {
|
||||
// Set up sorting
|
||||
$name = $item->{$this->plugin['export']['key']};
|
||||
$schema = ctools_export_get_schema($this->plugin['schema']);
|
||||
|
||||
// Load Custom Formatters engines.
|
||||
$engines = module_invoke_all('custom_formatters_engine_info');
|
||||
|
||||
// Hide Formatters using missing engines.
|
||||
if (!isset($engines[$item->mode])) {
|
||||
unset($this->row);
|
||||
return;
|
||||
}
|
||||
|
||||
// Note: $item->{$schema['export']['export type string']} should have already been set up by export.inc so
|
||||
// we can use it safely.
|
||||
switch ($form_state['values']['order']) {
|
||||
case 'disabled':
|
||||
$this->sorts[$name] = empty($item->disabled) . $name;
|
||||
break;
|
||||
case 'title':
|
||||
$this->sorts[$name] = $item->{$this->plugin['export']['admin_title']};
|
||||
break;
|
||||
case 'name':
|
||||
$this->sorts[$name] = $name;
|
||||
break;
|
||||
case 'storage':
|
||||
$this->sorts[$name] = $item->{$schema['export']['export type string']} . $name;
|
||||
break;
|
||||
}
|
||||
|
||||
$this->rows[$name]['data'] = array();
|
||||
$this->rows[$name]['class'] = !empty($item->disabled) ? array('ctools-export-ui-disabled') : array('ctools-export-ui-enabled');
|
||||
|
||||
// If we have an admin title, make it the first row.
|
||||
if (!empty($this->plugin['export']['admin_title'])) {
|
||||
$this->rows[$name]['data'][] = array('data' => check_plain($item->{$this->plugin['export']['admin_title']}), 'class' => array('ctools-export-ui-title'));
|
||||
}
|
||||
$this->rows[$name]['data'][] = array('data' => check_plain($name), 'class' => array('ctools-export-ui-name'));
|
||||
$this->rows[$name]['data'][] = array('data' => check_plain($engines[$item->mode]['label']), 'class' => array('ctools-export-ui-format'));
|
||||
$this->rows[$name]['data'][] = array('data' => !empty($item->fapi) && drupal_strlen($item->fapi) > 17 ? t('Yes') : t('No'), 'class' => array('ctools-export-ui-fapi'));
|
||||
$this->rows[$name]['data'][] = array('data' => check_plain($item->{$schema['export']['export type string']}), 'class' => array('ctools-export-ui-storage'));
|
||||
|
||||
$ops = theme('links__ctools_dropbutton', array('links' => $operations, 'attributes' => array('class' => array('links', 'inline'))));
|
||||
|
||||
$this->rows[$name]['data'][] = array('data' => $ops, 'class' => array('ctools-export-ui-operations'));
|
||||
|
||||
// Add an automatic mouseover of the description if one exists.
|
||||
if (!empty($this->plugin['export']['admin_description'])) {
|
||||
$this->rows[$name]['title'] = $item->{$this->plugin['export']['admin_description']};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide the table header.
|
||||
*
|
||||
* If you've added columns via list_build_row() but are still using a
|
||||
* table, override this method to set up the table header.
|
||||
*/
|
||||
function list_table_header() {
|
||||
$header = array();
|
||||
if (!empty($this->plugin['export']['admin_title'])) {
|
||||
$header[] = array('data' => t('Title'), 'class' => array('ctools-export-ui-title'));
|
||||
}
|
||||
|
||||
$header[] = array('data' => t('Name'), 'class' => array('ctools-export-ui-name'));
|
||||
$header[] = array('data' => t('Format'), 'class' => array('ctools-export-ui-format'));
|
||||
$header[] = array('data' => t('Formatter settings'), 'class' => array('ctools-export-ui-fapi'));
|
||||
$header[] = array('data' => t('Storage'), 'class' => array('ctools-export-ui-storage'));
|
||||
$header[] = array('data' => t('Operations'), 'class' => array('ctools-export-ui-operations'));
|
||||
|
||||
return $header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to enable a page.
|
||||
*/
|
||||
function enable_page($js, $input, $item) {
|
||||
field_cache_clear();
|
||||
return $this->set_item_state(FALSE, $js, $input, $item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback to disable a page.
|
||||
*/
|
||||
function disable_page($js, $input, $item) {
|
||||
field_cache_clear();
|
||||
return $this->set_item_state(TRUE, $js, $input, $item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Page callback to display export information for an exportable item.
|
||||
*/
|
||||
function export_page($js, $input, $item) {
|
||||
drupal_set_title($this->get_page_title('export', $item));
|
||||
return drupal_get_form('custom_formatters_export_ui_export_form', $item, t('Export'));
|
||||
}
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
(function($) {
|
||||
Drupal.settings.customFormattersAdmin = {};
|
||||
|
||||
Drupal.behaviors.customFormattersAdmin = {
|
||||
attach: function(context) {
|
||||
// Set initial fieldset states.
|
||||
if (typeof Drupal.settings.customFormattersAdmin.fieldsets == 'undefined') {
|
||||
Drupal.settings.customFormattersAdmin.fieldsets = {};
|
||||
this.storeStates();
|
||||
}
|
||||
if (context !== document) {
|
||||
this.restoreStates();
|
||||
}
|
||||
|
||||
// EditArea real-time syntax highlighter.
|
||||
if (typeof editAreaLoader !== 'undefined' && !$('.form-item-code textarea').hasClass('editarea-processed')) {
|
||||
$('.form-item-code textarea').addClass('editarea-processed');
|
||||
syntax = $('.form-item-code textarea').attr('class').match(/syntax-(\w+)\b/m);
|
||||
editAreaLoader.init({
|
||||
id: $('.form-item-code textarea').attr('id'),
|
||||
syntax: syntax[1],
|
||||
start_highlight: true,
|
||||
allow_resize: "y",
|
||||
allow_toggle: false,
|
||||
toolbar: "*",
|
||||
word_wrap: false,
|
||||
language: "en",
|
||||
replace_tab_by_spaces: 2,
|
||||
change_callback: 'Drupal.behaviors.customFormattersAdmin.customFormattersEAUpdate',
|
||||
});
|
||||
|
||||
// Make sure '#edit-code' gets updated before we preview the formatter.
|
||||
$('#engine-wrapper .form-submit').bind('mouseover', function() {
|
||||
Drupal.behaviors.customFormattersAdmin.customFormattersEAUpdate($('.form-item-code textarea').attr('id'))
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
detach: function(context) {
|
||||
this.storeStates();
|
||||
},
|
||||
|
||||
storeStates: function() {
|
||||
$('fieldset').each(function() {
|
||||
id = $(this).attr('id').indexOf('--') > 0 ? $(this).attr('id').substr(0, $(this).attr('id').indexOf('--')) : $(this).attr('id');
|
||||
Drupal.settings.customFormattersAdmin.fieldsets[id] = $(this).hasClass('collapsed');
|
||||
});
|
||||
},
|
||||
|
||||
restoreStates: function() {
|
||||
$('fieldset').each(function() {
|
||||
id = $(this).attr('id').indexOf('--') > 0 ? $(this).attr('id').substr(0, $(this).attr('id').indexOf('--')) : $(this).attr('id');
|
||||
if (Drupal.settings.customFormattersAdmin.fieldsets[id] == false) {
|
||||
$(this).removeClass('collapsed');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Update '#edit-code' with the EditArea code.
|
||||
customFormattersEAUpdate: function(editor_id) {
|
||||
$('#' + editor_id).val(editAreaLoader.getValue(editor_id));
|
||||
}
|
||||
}
|
||||
})(jQuery);
|
@@ -0,0 +1,10 @@
|
||||
#preview-wrapper .messages pre {
|
||||
white-space: pre;
|
||||
white-space: pre-wrap;
|
||||
white-space: pre-line;
|
||||
white-space: -pre-wrap;
|
||||
white-space: -o-pre-wrap;
|
||||
white-space: -moz-pre-wrap;
|
||||
white-space: -hp-pre-wrap;
|
||||
word-wrap: break-word;
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
#form-builder-fields .block {
|
||||
position: static !important;
|
||||
}
|
||||
|
||||
#form-builder .form-builder-empty-form {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#form-builder .form-builder-title + .form-builder-empty-form {
|
||||
display: inherit;
|
||||
}
|
||||
|
||||
#form-builder-field-palette ul li.field-image_styles {
|
||||
background-image: url('../images/icon-image_styles.png');
|
||||
}
|
||||
|
||||
#form-builder-field-palette ul li.field-token_tree {
|
||||
background-image: url('../images/icon-token_tree.png');
|
||||
}
|
Reference in New Issue
Block a user