Skip to content
Snippets Groups Projects
Commit b5ea5cea authored by Chris Gross's avatar Chris Gross
Browse files

daily build

parent c3f695e4
No related branches found
No related tags found
No related merge requests found
Showing
with 5496 additions and 11 deletions
WCM Base 7.x-1.x, 2015-08-12
----------------------------
- WCM Base Profile: Added Conditional Fields module.
- OCIO News: Added field to select if article should be displayed in view panes.
- OCIO Landing Page: Added fields to display text atop of banner photo.
- OCIO Omega Base:
- Added ocio-omega-dps panels layout for DPS front page use.
- Added JavaScript to resize all tile panes in a row to the same height
- OCIO Panels Settings: Display only one icon when Media Magnet widget requests
a single channel or channel type.
- OCIO Site Information: Allow <strong> tags in site name field.
- Media Magnet: Fixed request query string when using multiple values of a type.
WCM Base 7.x-1.x, 2015-08-05
----------------------------
- OCIO Omega Base:
......
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.
Conditional Fields:
--------------------
A Drupal module
Author:
--------------------
Gregorio Magini (peterpoe) <gmagini@gmail.com> - http://www.twitter.com/peterpoe
Short Description:
--------------------
Define dependencies between fields based on their states and values. Conditional Fields for Drupal 7 is basically an user interface for the States API, plus the ability to hide fields on certain conditions when viewing content.
Description:
--------------------
The Conditional Fields module allows you to manage sets of dependencies between fields. When a field is "dependent", it will only be available for editing and displayed if the state of the "dependee" field matches the right condition.
When editing a node (or any other entity type that supports fields, like users and categories), the dependent fields are dynamically modified with the States API.
You can, for example, define a custom “Article teaser" field that is shown only if a "Has teaser" checkbox is checked.
Dependencies:
--------------------
- Drupal core: 7.x (Version 7.14 or higher recommended).
Installation:
--------------------
- Install as usual, see http://drupal.org/documentation/install/modules-themes/modules-7 for further information.
Usage:
--------------------
Users with the "administer dependencies" permission can administer dependencies at admin/structure/dependencies.
For more information, read the Conditional Fields documentation:
http://drupal.org/node/1704126
Upgrading from Drupal 6 to Drupal 7
--------------------
Read carefully these instructions since taking the wrong steps could lead to loss of dependencies data!
- Before upgrading, ensure that you have the latest stable version of Conditional Fields for Drupal 6 installed and working.
- Follow the instructions on the D6 to D7 upgrade process here: http://drupal.org/node/570162.
- Most importantly, you have to migrate your old CCK fields to the new format BEFORE updating Conditional Fields, so do not omit step 14: "Upgrade fields"! Failing to do so will give an error when trying to run the subsequent update on step 15: "Update contrib modules and themes" and could lead to loss of dependencies data.
- After step 14, leave the Content Migrate module activated. You can safely disable it after step 15.
- Note that Content Migrate in certain cases changes the allowed values of fields: you will have to manually edit the dependencies to match the new allowed values if this happens.
Limitations:
--------------------
- Conditional Fields, for now, supports only core fields and widgets as dependee fields. Fields from other modules might work, but probably won't. Dependent fields, though, can be of any type.
Any help is welcome!
--------------------
Check the issue queue of this module for more information:
http://drupal.org/project/issues/conditional_fields
<?php
/**
* @file
* Hooks provided by Conditional Fields.
*/
/**
* Alter the list of states available for dependent fields.
*
* These are the jQuery events that are executed when a dependent field changes
* state (that is, when the dependency changes from untriggered to triggered or
* vice-versa).
*
* To implement a new state, it is necessary to create a jQuery event with the
* same name, prepended by the "state:" namespace. E.g.:
*
* $(document).bind('state:STATE_NAME', function(e) {
* if (e.trigger) {
* // e.value is true if the conditions are satisfied, false otherwise...
* }
* });
*
* @param $states
* An associative array of states.
*/
function hook_conditional_fields_states_alter(&$states) {
// Add a new Form state to the list. The corresponding jQuery event might
// look like this:
// $(document).bind('state:addmyclass', function(e) {
// if (e.trigger) {
// $(e.target).toggleClass('myclass', e.value);
// }
// });
$states['addmyclass'] = t('With CSS class myclass');
// Converse states are obtained by prepending an exclamation mark to the name.
// They are automatically implemented by the States API, but you need to add
// them explicitly to the list to make them available in the UI.
$states['!addmyclass'] = t('Without CSS class myclass');
// A configurable state. The class can be configured implementing an effect
// (see example in hook_conditional_fields_effects_alter).
$states['addclass'] = t('With CSS class');
$states['!addclass'] = t('Without CSS class');
}
/**
* Alter the list of visual effects available to states.
*
* Visual effects may provide settings that are passed to the js object
* Drupal.settings.conditionalFields.effects and that are automatically
* made available to the corresponding state change event under event.effect.
*
* Dependent field events associated with effects have the effect name appended
* to the name, separated by a hypen; effect options are passed into the event
* argument. E.g.:
*
* $(document).bind('state:STATE_NAME-EFFECT_NAME', function(e) {
* if (e.trigger) {
* // Effect options are stored in e.effect...
* }
* });
*
* @param $effects
* An associative array of effects. Each key is the unique name of the
* effect. The value is an associative array:
* - label: The human readable name of the effect.
* - states: The states that can be associated with this effect.
* - options: An associative array of effect options names, field types,
* descriptions and default values.
*/
function hook_conditional_fields_effects_alter(&$effects) {
// Implement an effect for the addclass state.
// The addclass event would be something like:
// $(document).bind('state:addclass-toggleclass', function(e) {
// if (e.trigger) {
// $(e.target).toggleClass(e.effect.class, e.value);
// }
// });
$effects['toggleclass'] = array(
'label' => t('CSS Class'),
// This effect is associated with the following states.
'states' => array('addclass', '!addclass'),
// The values under options are form elements that will be inserted in
// the dependency edit form. The key of this form element is also found in
// the jQuery event argument under event.effect.class.
'options' => array(
'class' => array(
'#type' => 'textfield',
'#description' => t('One or more space separated classes that are toggled on the dependent.'),
'#default_value' => '',
),
),
);
}
/**
* Alter the list of conditions available as dependee states.
*
* These are callbacks that are executed by the States API to check if a
* dependee field matches the required condition.
* Modules adding conditions using this hook should also add the corresponding
* callback to the Drupal.states.Trigger.states object.
*
* @param $conditions
* An associative array of conditions, with names as keys and labels as
* values.
*/
function hook_conditional_fields_conditions_alter(&$conditions) {
// Add a special condition that checks if a field value is an integer greater
// than 0. The javascript callback could be something like:
// Drupal.states.Trigger.states.positiveInteger = {
// 'keyup': function () {
// var val = this.val(),
// int = parseInt(val);
// return val == int && int > 0;
// }
// };
$conditions['positiveInteger'] = t('An integer greater than 0.');
// Like states, conditions get a converse automatically.
$conditions['!positiveInteger'] = t('An integer less than or equal to 0.');
}
/**
* Alter the list of available behaviors.
*
* @param $behaviors
* An associative array with two keys representing contexts: 'edit' and
* 'view'. Each key contains an associative array of behaviors that are
* executed during the corresponding phase. The keys of the array are
* function names and the values are a human readable label of the behavior.
*/
function hook_conditional_fields_behaviors_alter(&$behaviors) {
// Edit behavior.
$behaviors['edit']['conditional_fields_example_fancy_edit_behavior'] = t('A fancy edit behavior for my module');
// View behavior.
$behaviors['view']['conditional_fields_example_fancy_view_behavior'] = t('A fancy view behavior for my module');
}
/**
* Example edit behavior callback.
*
* @param $form
* The form that contains fields with dependencies.
* @param $form_state
* The form state of the form.
* @param $dependent
* The name of the dependent field.
* @param $dependencis
* The dependencies relevant to this dependent.
*/
function conditional_fields_example_fancy_edit_behavior(&$form, &$form_state, $dependent, $dependencies) {
// Do some fancy stuff...
}
/**
* Example view behavior callback.
*
* @param $dependent
* The name of the dependee field.
* @param $dependee
* The name of the dependent field.
* @param $is_triggered
* A boolean indicating whether the dependency was triggered.
* @param $dependencies
* An array of dependencies relevant to this context.
* @param $build
* The entity that is being viewed.
* @param $entity_type
* The entity type that is being viewed.
*/
function conditional_fields_example_fancy_view_behavior($dependee, $dependent, $is_triggered, $dependencies, &$build, $entity_type) {
// Add some foo before all entities that have triggered dependencies.
if ($is_triggered) {
$build['#prefix'] .= 'foo';
}
}
/* Dependencies overview */
table.conditional-fields-overview .add-new-placeholder {
font-weight: bold;
padding-bottom: .5em;
}
table.conditional-fields-overview .form-submit {
margin-top: 1em;
}
table.conditional-fields-overview .description-select .form-type-select {
display: inline;
}
/* Dependency edit */
#conditional-fields-dependency-edit-form .form-item-state .description {
clear: both;
}
#conditional-fields-dependency-edit-form .form-item-state .ajax-progress {
width: 120px;
}
\ No newline at end of file
name = Conditional Fields
description = Define dependencies between fields based on their states and values.
core = 7.x
package = Fields
dependencies[] = field
configure = admin/structure/dependencies
; Information added by packaging script on 2013-11-18
version = "7.x-3.0-alpha1"
core = "7.x"
project = "conditional_fields"
datestamp = "1384798705"
<?php
/**
* @file
* Install, update and uninstall functions for the Conditional Fields module.
*/
/**
* Implements hook_schema().
*/
function conditional_fields_schema() {
$schema['conditional_fields'] = array(
'description' => 'Stores dependencies between fields.',
'fields' => array(
'id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'The primary identifier for a dependency.',
),
'dependee' => array(
'type' => 'int',
'not null' => TRUE,
'description' => 'The id of the dependee field instance.',
),
'dependent' => array(
'type' => 'int',
'not null' => TRUE,
'description' => 'The id of the dependent field instance.',
),
'options' => array(
'type' => 'blob',
'size' => 'big',
'not null' => TRUE,
'serialize' => TRUE,
'description' => 'Serialized data containing the options for the dependency.',
),
),
'primary key' => array('id'),
);
return $schema;
}
/**
* Table schema used for initial upgrade to Drupal 7. Do not edit this function.
*/
function conditional_fields_schema_7000() {
return array(
'fields' => array(
'id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'The primary identifier for a dependency.',
),
'dependee' => array(
'type' => 'int',
'not null' => TRUE,
'description' => 'The id of the dependee field instance.',
),
'dependent' => array(
'type' => 'int',
'not null' => TRUE,
'description' => 'The id of the dependent field instance.',
),
'options' => array(
'type' => 'blob',
'size' => 'big',
'not null' => TRUE,
'serialize' => TRUE,
'description' => 'Serialized data containing the options for the dependency.',
),
),
'primary key' => array('id'),
);
}
/**
* Implements hook_last_removed().
*/
function conditional_fields_last_removed() {
return 6002;
}
/**
* Upgrade from Drupal 6 to Drupal 7.
*/
function conditional_fields_update_7000() {
// Parachute for users who installed version 7.x-3.x-dev before 2011-Aug-10.
try {
$old_dependencies = db_select('conditional_fields', 'cf')->fields('cf', array('control_field_name', 'field_name', 'type', 'trigger_values'))->execute();
}
catch (Exception $e) {
// If the columns are not found, table doesn't need updating.
if ($e->errorInfo[0] == '42S22') {
return 'Conditional Fields schema was already up to date.';
}
else {
throw $e;
}
}
// We can only migrate dependencies after fields definitions have been
// migrated to Drupal 7 using the Content Migrate module.
if (!module_exists('content_migrate')) {
throw new DrupalUpdateException('Before upgrading Conditional Fields from Drupal 6 you must upgrade your fields definitions using the Content Migrate module. Follow the CCK migration to Drupal 7 documentation at http://drupal.org/node/1144136 and then run update.php again, leaving the Content Migrate module activated. After the update, you can safely disable the Content Migrate module. Warning: if you don\'t migrate your fields before rerunning this update you might lose all your defined dependencies!');
}
// Update permission to new name.
db_update('role_permission')
->fields(array('permission' => 'administer dependencies'))
->condition('permission', 'administer conditional fields')
->execute();
$dependencies = array();
$node_types = node_type_get_names();
$administrator_roles = user_roles(FALSE, 'administer dependencies');
$default_options = array(
'selector' => '',
'selector_custom' => 0,
'state' => 'visible',
'condition' => 'value',
'values_set' => 1, // CONDITIONAL_FIELDS_DEPENDENCY_VALUES_SET_SINGLE
'value' => array(),
'value_form' => array(),
'values' => array(),
'effect' => 'show',
'effect_options' => NULL,
'element_view' => array(
1 => 1, // CONDITIONAL_FIELDS_ELEMENT_VIEW_EVALUATE
2 => 2, // CONDITIONAL_FIELDS_ELEMENT_VIEW_HIDE_ORPHAN
5 => 0, // CONDITIONAL_FIELDS_ELEMENT_VIEW_HIDE_ORPHAN_IF_UNTRIGGERED
3 => 0, // CONDITIONAL_FIELDS_ELEMENT_VIEW_HIGHLIGHT
4 => 0, // CONDITIONAL_FIELDS_ELEMENT_VIEW_DESCRIBE
),
'element_view_per_role' => 0,
'element_view_roles' => array(),
'element_edit' => array(
1 => 1, // CONDITIONAL_FIELDS_ELEMENT_EDIT_HIDE_ORPHAN
2 => 0, // CONDITIONAL_FIELDS_ELEMENT_EDIT_HIDE_ORPHAN_IF_UNTRIGGERED
3 => 0, // CONDITIONAL_FIELDS_ELEMENT_EDIT_RESET_DEFAULTS_IF_UNTRIGGERED
),
'element_edit_per_role' => 0,
'element_edit_roles' => array(),
);
// Convert old dependencies to new format.
foreach ($old_dependencies as $old_dependency) {
$options = array();
if (!isset($node_types[$old_dependency->type])) {
continue;
}
$type = $old_dependency->type;
$dependee = field_read_instance('node', $old_dependency->control_field_name, $type, array('include_inactive' => TRUE));
$dependent = field_read_instance('node', $old_dependency->field_name, $type, array('include_inactive' => TRUE));
if (!$dependee || !$dependent) {
continue;
}
$options['values_set'] = 2; // CONDITIONAL_FIELDS_DEPENDENCY_VALUES_SET_AND
$options['values'] = array_keys(unserialize($old_dependency->trigger_values));
// Use Javascript.
switch (variable_get('c_fields_js_' . $type, 1)) {
case 0: // C_FIELDS_JS_NO
$options['state'] = 'unchanged';
break;
case 2: // C_FIELDS_JS_DISABLE
$options['state'] = '!disabled';
break;
}
// JS Animation.
$js_animation = variable_get('c_fields_animation_' . $type, 0);
switch ($js_animation) {
case 1: // C_FIELDS_ANIMATION_FADE
$options['effect'] = 'fade';
break;
case 2: // C_FIELDS_ANIMATION_SLIDE
$options['effect'] = 'slide';
break;
}
// JS Animation speed.
if ($js_animation != 0) {
switch (variable_get('c_fields_anim_speed_' . $type, 'normal')) {
case 'slow':
$speed = 600;
break;
case 'normal':
$speed = 400;
break;
case 'fast':
$speed = 200;
break;
}
$options['effect_options'] = array('speed' => $speed);
}
// Orphaned on view.
switch (variable_get('c_fields_view_' . $type, 1)) {
case 1: // C_FIELDS_ORPHANED_SHOW_TRIGGERED
$options['element_view'][2] = 0; // CONDITIONAL_FIELDS_ELEMENT_VIEW_HIDE_ORPHAN
$options['element_view'][5] = 5; // CONDITIONAL_FIELDS_ELEMENT_VIEW_HIDE_ORPHAN_IF_UNTRIGGERED
break;
case 2: // C_FIELDS_ORPHANED_SHOW_ALL
$options['element_view'][2] = 0;
break;
}
// Orphaned on edit.
switch (variable_get('c_fields_edit_' . $type, 1)) {
case 1: // C_FIELDS_ORPHANED_SHOW_TRIGGERED
$options['element_edit'][1] = 0; // CONDITIONAL_FIELDS_ELEMENT_EDIT_HIDE_ORPHAN
$options['element_edit'][2] = 2; // CONDITIONAL_FIELDS_ELEMENT_EDIT_HIDE_ORPHAN_IF_UNTRIGGERED
break;
case 2: // C_FIELDS_ORPHANED_SHOW_ALL
$options['element_edit'][2] = 0;
break;
}
// Reset if untriggered.
if (variable_get('c_fields_reset_default_' . $type, 1)) {
$options['element_edit'][3] = 3; // CONDITIONAL_FIELDS_ELEMENT_EDIT_RESET_DEFAULTS_IF_UNTRIGGERED
}
// Show all values to administrators.
if (variable_get('c_fields_show_all_' . $type, 0) && !empty($administrator_roles)) {
$options['element_view_per_role'] = 1;
foreach ($administrator_roles as $rid => $role) {
$options['element_view_roles'][$rid] = array();
}
}
$options += $default_options;
$dependencies[] = array(
'dependee' => $dependee['id'],
'dependent' => $dependent['id'],
'options' => serialize($options),
);
}
// Delete the old table.
db_drop_table('conditional_fields');
// Create new table.
$schema = conditional_fields_schema_7000();
db_create_table('conditional_fields', $schema);
// Insert the new settings.
if (!empty($dependencies)) {
$query = db_insert('conditional_fields')->fields(array('dependee', 'dependent', 'options'));
foreach ($dependencies as $record) {
$query->values($record);
}
$query->execute();
}
// Delete obsolete variables, then clear the variables cache.
db_delete('variable')
->condition('name', 'c_fields_%', 'LIKE')
->execute();
cache_clear_all('variables', 'cache_bootstrap');
return 'Conditional Fields successfully upated dependencies to Drupal 7.';
}
/**
* Set 'selector' option to empty string if 'selector_custom' was unchecked and
* remove 'selector_custom' option.
*/
function conditional_fields_update_7001() {
$dependencies = db_select('conditional_fields', 'cf')->fields('cf', array('id', 'options'))->execute();
foreach ($dependencies as $dependency) {
$options = unserialize($dependency->options);
if ($options['selector_custom'] == 0) {
$options['selector'] = '';
}
unset($options['selector_custom']);
db_update('conditional_fields')
->fields(array(
'options' => serialize($options),
))
->condition('id', $dependency->id)
->execute();
}
}
/**
* Updated dependency id menu arguments to argument loader function.
*/
function conditional_fields_update_7002() {
// Do nothing; it's here just to let Drupal rebuild the menu cache.
}
<?php
/**
* @file
* Features integration hooks.
*/
/**
* Implements hook_features_export_options().
*/
function conditional_fields_features_export_options() {
$dependencies = conditional_fields_load_dependencies();
$entity_info = entity_get_info();
$options = array();
foreach ($dependencies as $type => $data) {
foreach ($data as $dependency => $info) {
$option = $type . ':' . $dependency;
if (!isset($options[$dependency])) {
$options[$option] = $entity_info[$type]['bundles'][$dependency]['label'] . ' (' . $type . ')';
}
}
}
return $options;
}
/**
* Implements hook_features_export().
*/
function conditional_fields_features_export($data, &$export, $module_name = '') {
$export['dependencies']['conditional_fields'] = 'conditional_fields';
foreach ($data as $entity) {
$export['features']['conditional_fields'][$entity] = $entity;
}
}
/**
* Implements hook_features_export_render().
*/
function conditional_fields_features_export_render($module_name, $data, $export = NULL) {
$dependencies = conditional_fields_load_dependencies();
if (empty($dependencies)) {
return array();
}
$code = array();
foreach ($data as $option) {
$tokens = explode(':', $option);
$entity = $tokens[0];
$bundle = $tokens[1];
if (isset($dependencies[$entity]) && isset($dependencies[$entity][$bundle])) {
$info = $dependencies[$entity][$bundle];
foreach ($info['dependents'] as $dependent_field_name => $dependees) {
foreach ($dependees as $dependee) {
$code[] = '';
$code[] = ' $items[] = array(';
$code[] = " 'entity' => '" . $entity . "',";
$code[] = " 'bundle' => '" . $bundle . "',";
$code[] = " 'dependent' => '" . $dependent_field_name . "',";
$code[] = " 'dependee' => '" . $dependee['dependee'] . "',";
$code[] = " 'options' => " . features_var_export($dependee['options'], ' ') . ',';
$code[] = ' );';
}
}
}
}
if (empty($code)) {
return array();
}
array_unshift($code, ' $items = array();');
$code[] = '';
$code[] = ' return $items;';
$output = implode("\n", $code);
return array('conditional_fields_default_fields' => $output);
}
/**
* Implements hook_features_rebuild().
*/
function conditional_fields_features_rebuild($module) {
$defaults = module_invoke($module, 'conditional_fields_default_fields');
$dependencies = conditional_fields_load_dependencies();
$instances = field_info_instances();
if (!empty($defaults)) {
$node_types = array();
foreach ($defaults as $field) {
if (isset($dependencies[$field['entity']][$field['bundle']])) {
foreach ($dependencies[$field['entity']][$field['bundle']] as $dependancy_type => $field_dep_settings) {
if ($dependancy_type == 'dependees' && !empty($field_dep_settings)) {
foreach ($field_dep_settings as $dep_setting) {
foreach ($dep_setting as $id => $dep_settings) {
$deps_to_remove[$id] = $id;
}
}
}
}
if (!empty($deps_to_remove)) {
conditional_fields_dependency_delete($deps_to_remove);
}
}
$entity_instances = $instances[$field['entity']][$field['bundle']];
$dependee_id = $entity_instances[$field['dependee']]['id'];
$dependent_id = $entity_instances[$field['dependent']]['id'];
$options = $field['options'];
conditional_fields_dependency_insert($dependee_id, $dependent_id, $options);
}
}
}
/**
* Implements hook_features_revert().
*/
function conditional_fields_features_revert($module) {
return conditional_fields_features_rebuild($module);
}
(function ($) {
/**
* Enhancements to states.js.
*/
/**
* Handle array values.
* @see http://drupal.org/node/1149078
*/
Drupal.states.Dependent.comparisons['Array'] = function (reference, value) {
// Make sure value is an array.
if (!(typeof(value) === 'object' && (value instanceof Array))) {
return false;
}
// We iterate through each value provided in the reference. If all of them
// exist in value array, we return true. Otherwise return false.
for (var key in reference) {
if (reference.hasOwnProperty(key) && $.inArray(reference[key], value) < 0) {
return false;
}
}
return true;
};
/**
* Handle Object values.
*/
Drupal.states.Dependent.comparisons['Object'] = function (reference, value) {
/* Regular expressions are objects with a RegExp property. */
if (reference.hasOwnProperty('RegExp')) {
reference = new RegExp(reference.RegExp);
return this.RegExp(reference, value);
}
else {
return compare(reference, value);
}
};
/**
* Focused condition.
*/
Drupal.states.Trigger.states.focused = function(element) {
element.bind('focus', function () {
element.trigger({ type: 'state:focused', value: true });
})
.bind('blur', function () {
element.trigger({ type: 'state:focused', value: false });
});
Drupal.states.postponed.push($.proxy(function () {
element.trigger({ type: 'state:focused', value: element.is(':focus') });
}, window));
};
/**
* Touched condition.
*/
Drupal.states.Trigger.states.touched = {
'focus': function(e) {
return (typeof e === 'undefined' && !this.is(':focus')) ? false : true;
}
};
/**
* New and existing states enhanced with configurable options.
* Event names of states with effects have the following structure:
* state:stateName-effectName.
*/
// Visible/Invisible.
$(document).bind('state:visible-fade', function(e) {
if (e.trigger) {
$(e.target).closest('.form-item, .form-submit, .form-wrapper')[e.value ? 'fadeIn' : 'fadeOut'](e.effect.speed);
}
})
.bind('state:visible-slide', function(e) {
if (e.trigger) {
$(e.target).closest('.form-item, .form-submit, .form-wrapper')[e.value ? 'slideDown' : 'slideUp'](e.effect.speed);
}
})
// Empty/Filled.
.bind('state:empty-empty', function(e) {
if (e.trigger) {
var field = $(e.target).find('input, select, textarea');
if (e.effect.reset) {
if (typeof oldValue == 'undefined' || field.val() !== e.effect.value) {
oldValue = field.val();
}
field.val(e.value ? e.effect.value : oldValue);
}
else if (e.value) {
field.val(e.effect.value);
}
}
})
.bind('state:empty-fill', function(e) {
if (e.trigger) {
var field = $(e.target).find('input, select, textarea');
if (e.effect.reset) {
if (typeof oldValue === 'undefined' || field.val() !== e.effect.value) {
oldValue = field.val();
}
field.val(!e.value ? e.effect.value : oldValue);
}
else if (!e.value) {
field.val(e.effect.value);
}
}
})
// Unchanged state. Do nothing.
.bind('state:unchanged', function() {});
Drupal.behaviors.conditionalFields = {
attach: function (context, settings) {
// AJAX is not updating settings.conditionalFields correctly.
var conditionalFields = settings.conditionalFields || Drupal.settings.conditionalFields;
if (typeof conditionalFields === 'undefined' || typeof conditionalFields.effects === 'undefined') {
return;
}
// Override state change handlers for dependents with special effects.
$.each($(document).data('events'), function(i, events) {
if (i.substring(0, 6) === 'state:') {
var originalHandler = events[0].handler;
events[0].handler = function(e) {
var effect = conditionalFields.effects['#' + e.target.id];
if (typeof effect !== 'undefined') {
var effectEvent = i + '-' + effect.effect;
if (typeof $(document).data('events')[effectEvent] !== 'undefined') {
$(e.target).trigger({ type : effectEvent, trigger : e.trigger, value : e.value, effect : effect.options });
return;
}
}
originalHandler(e);
}
}
});
}
};
})(jQuery);
(function ($) {
/**
* The base States namespace.
*
* Having the local states variable allows us to use the States namespace
* without having to always declare "Drupal.states".
*/
var states = Drupal.states = {
// An array of functions that should be postponed.
postponed: []
};
/**
* Attaches the states.
*/
Drupal.behaviors.states = {
attach: function (context, settings) {
for (var selector in settings.states) {
for (var state in settings.states[selector]) {
new states.Dependent({
element: $(selector),
state: states.State.sanitize(state),
constraints: settings.states[selector][state]
});
}
}
// Execute all postponed functions now.
while (states.postponed.length) {
(states.postponed.shift())();
}
}
};
/**
* Object representing an element that depends on other elements.
*
* @param args
* Object with the following keys (all of which are required):
* - element: A jQuery object of the dependent element
* - state: A State object describing the state that is dependent
* - constraints: An object with dependency specifications. Lists all elements
* that this element depends on. It can be nested and can contain arbitrary
* AND and OR clauses.
*/
states.Dependent = function (args) {
$.extend(this, { values: {}, oldValue: null }, args);
this.dependees = this.getDependees();
for (var selector in this.dependees) {
this.initializeDependee(selector, this.dependees[selector]);
}
};
/**
* Comparison functions for comparing the value of an element with the
* specification from the dependency settings. If the object type can't be
* found in this list, the === operator is used by default.
*/
states.Dependent.comparisons = {
'RegExp': function (reference, value) {
return reference.test(value);
},
'Function': function (reference, value) {
// The "reference" variable is a comparison function.
return reference(value);
},
'Number': function (reference, value) {
// If "reference" is a number and "value" is a string, then cast reference
// as a string before applying the strict comparison in compare(). Otherwise
// numeric keys in the form's #states array fail to match string values
// returned from jQuery's val().
return (typeof value === 'string') ? compare(reference.toString(), value) : compare(reference, value);
}
};
states.Dependent.prototype = {
/**
* Initializes one of the elements this dependent depends on.
*
* @param selector
* The CSS selector describing the dependee.
* @param dependeeStates
* The list of states that have to be monitored for tracking the
* dependee's compliance status.
*/
initializeDependee: function (selector, dependeeStates) {
var state;
// Cache for the states of this dependee.
this.values[selector] = {};
for (var i in dependeeStates) {
if (dependeeStates.hasOwnProperty(i)) {
state = dependeeStates[i];
// Make sure we're not initializing this selector/state combination twice.
if ($.inArray(state, dependeeStates) === -1) {
continue;
}
state = states.State.sanitize(state);
// Initialize the value of this state.
this.values[selector][state.name] = null;
// Monitor state changes of the specified state for this dependee.
$(selector).bind('state:' + state, $.proxy(function (e) {
this.update(selector, state, e.value);
}, this));
// Make sure the event we just bound ourselves to is actually fired.
new states.Trigger({ selector: selector, state: state });
}
}
},
/**
* Compares a value with a reference value.
*
* @param reference
* The value used for reference.
* @param selector
* CSS selector describing the dependee.
* @param state
* A State object describing the dependee's updated state.
*
* @return
* true or false.
*/
compare: function (reference, selector, state) {
var value = this.values[selector][state.name];
if (reference.constructor.name in states.Dependent.comparisons) {
// Use a custom compare function for certain reference value types.
return states.Dependent.comparisons[reference.constructor.name](reference, value);
}
else {
// Do a plain comparison otherwise.
return compare(reference, value);
}
},
/**
* Update the value of a dependee's state.
*
* @param selector
* CSS selector describing the dependee.
* @param state
* A State object describing the dependee's updated state.
* @param value
* The new value for the dependee's updated state.
*/
update: function (selector, state, value) {
// Only act when the 'new' value is actually new.
if (value !== this.values[selector][state.name]) {
this.values[selector][state.name] = value;
this.reevaluate();
}
},
/**
* Triggers change events in case a state changed.
*/
reevaluate: function () {
// Check whether any constraint for this dependent state is satisifed.
var value = this.verifyConstraints(this.constraints);
// Only invoke a state change event when the value actually changed.
if (value !== this.oldValue) {
// Store the new value so that we can compare later whether the value
// actually changed.
this.oldValue = value;
// Normalize the value to match the normalized state name.
value = invert(value, this.state.invert);
// By adding "trigger: true", we ensure that state changes don't go into
// infinite loops.
this.element.trigger({ type: 'state:' + this.state, value: value, trigger: true });
}
},
/**
* Evaluates child constraints to determine if a constraint is satisfied.
*
* @param constraints
* A constraint object or an array of constraints.
* @param selector
* The selector for these constraints. If undefined, there isn't yet a
* selector that these constraints apply to. In that case, the keys of the
* object are interpreted as the selector if encountered.
*
* @return
* true or false, depending on whether these constraints are satisfied.
*/
verifyConstraints: function(constraints, selector) {
var result;
if ($.isArray(constraints)) {
// This constraint is an array (OR or XOR).
var hasXor = $.inArray('xor', constraints) === -1;
for (var i = 0, len = constraints.length; i < len; i++) {
if (constraints[i] != 'xor') {
var constraint = this.checkConstraints(constraints[i], selector, i);
// Return if this is OR and we have a satisfied constraint or if this
// is XOR and we have a second satisfied constraint.
if (constraint && (hasXor || result)) {
return hasXor;
}
result = result || constraint;
}
}
}
// Make sure we don't try to iterate over things other than objects. This
// shouldn't normally occur, but in case the condition definition is bogus,
// we don't want to end up with an infinite loop.
else if ($.isPlainObject(constraints)) {
// This constraint is an object (AND).
for (var n in constraints) {
if (constraints.hasOwnProperty(n)) {
result = ternary(result, this.checkConstraints(constraints[n], selector, n));
// False and anything else will evaluate to false, so return when any
// false condition is found.
if (result === false) { return false; }
}
}
}
return result;
},
/**
* Checks whether the value matches the requirements for this constraint.
*
* @param value
* Either the value of a state or an array/object of constraints. In the
* latter case, resolving the constraint continues.
* @param selector
* The selector for this constraint. If undefined, there isn't yet a
* selector that this constraint applies to. In that case, the state key is
* propagates to a selector and resolving continues.
* @param state
* The state to check for this constraint. If undefined, resolving
* continues.
* If both selector and state aren't undefined and valid non-numeric
* strings, a lookup for the actual value of that selector's state is
* performed. This parameter is not a State object but a pristine state
* string.
*
* @return
* true or false, depending on whether this constraint is satisfied.
*/
checkConstraints: function(value, selector, state) {
// Normalize the last parameter. If it's non-numeric, we treat it either as
// a selector (in case there isn't one yet) or as a trigger/state.
if (typeof state !== 'string' || (/[0-9]/).test(state[0])) {
state = null;
}
else if (typeof selector === 'undefined') {
// Propagate the state to the selector when there isn't one yet.
selector = state;
state = null;
}
if (state !== null) {
// constraints is the actual constraints of an element to check for.
state = states.State.sanitize(state);
return invert(this.compare(value, selector, state), state.invert);
}
else {
// Resolve this constraint as an AND/OR operator.
return this.verifyConstraints(value, selector);
}
},
/**
* Gathers information about all required triggers.
*/
getDependees: function() {
var cache = {};
// Swivel the lookup function so that we can record all available selector-
// state combinations for initialization.
var _compare = this.compare;
this.compare = function(reference, selector, state) {
(cache[selector] || (cache[selector] = [])).push(state.name);
// Return nothing (=== undefined) so that the constraint loops are not
// broken.
};
// This call doesn't actually verify anything but uses the resolving
// mechanism to go through the constraints array, trying to look up each
// value. Since we swivelled the compare function, this comparison returns
// undefined and lookup continues until the very end. Instead of lookup up
// the value, we record that combination of selector and state so that we
// can initialize all triggers.
this.verifyConstraints(this.constraints);
// Restore the original function.
this.compare = _compare;
return cache;
}
};
states.Trigger = function (args) {
$.extend(this, args);
if (this.state in states.Trigger.states) {
this.element = $(this.selector);
// Only call the trigger initializer when it wasn't yet attached to this
// element. Otherwise we'd end up with duplicate events.
if (!this.element.data('trigger:' + this.state)) {
this.initialize();
}
}
};
states.Trigger.prototype = {
initialize: function () {
var trigger = states.Trigger.states[this.state];
if (typeof trigger == 'function') {
// We have a custom trigger initialization function.
trigger.call(window, this.element);
}
else {
for (var event in trigger) {
if (trigger.hasOwnProperty(event)) {
this.defaultTrigger(event, trigger[event]);
}
}
}
// Mark this trigger as initialized for this element.
this.element.data('trigger:' + this.state, true);
},
defaultTrigger: function (event, valueFn) {
var oldValue = valueFn.call(this.element);
// Attach the event callback.
this.element.bind(event, $.proxy(function (e) {
var value = valueFn.call(this.element, e);
// Only trigger the event if the value has actually changed.
if (oldValue !== value) {
this.element.trigger({ type: 'state:' + this.state, value: value, oldValue: oldValue });
oldValue = value;
}
}, this));
states.postponed.push($.proxy(function () {
// Trigger the event once for initialization purposes.
this.element.trigger({ type: 'state:' + this.state, value: oldValue, oldValue: null });
}, this));
}
};
/**
* This list of states contains functions that are used to monitor the state
* of an element. Whenever an element depends on the state of another element,
* one of these trigger functions is added to the dependee so that the
* dependent element can be updated.
*/
states.Trigger.states = {
// 'empty' describes the state to be monitored
empty: {
// 'keyup' is the (native DOM) event that we watch for.
'keyup': function () {
// The function associated to that trigger returns the new value for the
// state.
return this.val() == '';
}
},
checked: {
'change': function () {
return this.attr('checked');
}
},
// For radio buttons, only return the value if the radio button is selected.
value: {
'keyup': function () {
// Radio buttons share the same :input[name="key"] selector.
if (this.length > 1) {
// Initial checked value of radios is undefined, so we return false.
return this.filter(':checked').val() || false;
}
return this.val();
},
'change': function () {
// Radio buttons share the same :input[name="key"] selector.
if (this.length > 1) {
// Initial checked value of radios is undefined, so we return false.
return this.filter(':checked').val() || false;
}
return this.val();
}
},
collapsed: {
'collapsed': function(e) {
return (typeof e !== 'undefined' && 'value' in e) ? e.value : this.is('.collapsed');
}
}
};
/**
* A state object is used for describing the state and performing aliasing.
*/
states.State = function(state) {
// We may need the original unresolved name later.
this.pristine = this.name = state;
// Normalize the state name.
while (true) {
// Iteratively remove exclamation marks and invert the value.
while (this.name.charAt(0) == '!') {
this.name = this.name.substring(1);
this.invert = !this.invert;
}
// Replace the state with its normalized name.
if (this.name in states.State.aliases) {
this.name = states.State.aliases[this.name];
}
else {
break;
}
}
};
/**
* Creates a new State object by sanitizing the passed value.
*/
states.State.sanitize = function (state) {
if (state instanceof states.State) {
return state;
}
else {
return new states.State(state);
}
};
/**
* This list of aliases is used to normalize states and associates negated names
* with their respective inverse state.
*/
states.State.aliases = {
'enabled': '!disabled',
'invisible': '!visible',
'invalid': '!valid',
'untouched': '!touched',
'optional': '!required',
'filled': '!empty',
'unchecked': '!checked',
'irrelevant': '!relevant',
'expanded': '!collapsed',
'readwrite': '!readonly'
};
states.State.prototype = {
invert: false,
/**
* Ensures that just using the state object returns the name.
*/
toString: function() {
return this.name;
}
};
/**
* Global state change handlers. These are bound to "document" to cover all
* elements whose state changes. Events sent to elements within the page
* bubble up to these handlers. We use this system so that themes and modules
* can override these state change handlers for particular parts of a page.
*/
$(document).bind('state:disabled', function(e) {
// Only act when this change was triggered by a dependency and not by the
// element monitoring itself.
if (e.trigger) {
$(e.target)
.attr('disabled', e.value)
.filter('.form-element')
.closest('.form-item, .form-submit, .form-wrapper').toggleClass('form-disabled', e.value);
// Note: WebKit nightlies don't reflect that change correctly.
// See https://bugs.webkit.org/show_bug.cgi?id=23789
}
});
$(document).bind('state:required', function(e) {
if (e.trigger) {
if (e.value) {
$(e.target).closest('.form-item, .form-wrapper').find('label').append('<span class="form-required">*</span>');
}
else {
$(e.target).closest('.form-item, .form-wrapper').find('label .form-required').remove();
}
}
});
$(document).bind('state:visible', function(e) {
if (e.trigger) {
$(e.target).closest('.form-item, .form-submit, .form-wrapper').toggle(e.value);
}
});
$(document).bind('state:checked', function(e) {
if (e.trigger) {
$(e.target).attr('checked', e.value);
}
});
$(document).bind('state:collapsed', function(e) {
if (e.trigger) {
if ($(e.target).is('.collapsed') !== e.value) {
$('> legend a', e.target).click();
}
}
});
/**
* These are helper functions implementing addition "operators" and don't
* implement any logic that is particular to states.
*/
// Bitwise AND with a third undefined state.
function ternary (a, b) {
return typeof a === 'undefined' ? b : (typeof b === 'undefined' ? a : a && b);
}
// Inverts a (if it's not undefined) when invert is true.
function invert (a, invert) {
return (invert && typeof a !== 'undefined') ? !a : a;
}
// Compares two values while ignoring undefined values.
function compare (a, b) {
return (a === b) ? (typeof a === 'undefined' ? a : true) : (typeof a === 'undefined' || typeof b === 'undefined');
}
})(jQuery);
<?php
/**
* @file
* Test Conditional Fields functionality and UI.
*/
class ConditionalFieldsTestCase extends DrupalWebTestCase {
protected $dependee_on_value;
protected $dependee_off_value;
protected $dependents;
public static function getInfo() {
return array(
'name' => 'Conditional Fields',
'description' => 'Test Conditional Fields functionality.',
'group' => 'Conditional Fields',
);
}
public function setUp() {
// Load all core modules that define field types.
parent::setUp('conditional_fields_test', 'list', 'text', 'number', 'taxonomy', 'image');
// Create and log in user.
$web_user = $this->drupalCreateUser(array('create conditional_fields_test content', 'edit any conditional_fields_test content'));
$this->drupalLogin($web_user);
// Create a vocabulary and two terms to test the term reference field.
$vocabulary = new stdClass();
$vocabulary->name = $this->randomName();
$vocabulary->machine_name = drupal_strtolower($this->randomName());
taxonomy_vocabulary_save($vocabulary);
$term = new stdClass();
$term->name = 'Foo';
$term->vid = $vocabulary->vid;
taxonomy_term_save($term);
$term = new stdClass();
$term->name = 'Bar';
$term->vid = $vocabulary->vid;
taxonomy_term_save($term);
// Create dependee.
$this->dependee_on_value = $this->randomString();
$this->dependee_off_value = $this->randomString();
$dependee = array(
'field_name' => 'dependee',
'type' => 'list_text',
'settings' => array(
'allowed_values' => array($this->dependee_on_value => t('Dependent fields are visible'), $this->dependee_off_value => t('Dependent fields are invisible')),
),
);
field_create_field($dependee);
$dependee_instance = array(
'field_name' => 'dependee',
'entity_type' => 'node',
'bundle' => 'conditional_fields_test',
'label' => 'dependee_label',
);
field_create_instance($dependee_instance);
// Reload the instance because we need the instance id.
$dependee_instance = field_info_instance('node', 'dependee', 'conditional_fields_test');
// Prepare one field for each widget type/field type combination.
foreach (field_info_widget_types() as $widget_type => $widget_info) {
// TODO: test files and images.
if ($widget_type == 'file_generic' || $widget_type == 'image_image') {
continue;
}
foreach ($widget_info['field types'] as $field_type) {
$field_name = 'dependent_' . drupal_strtolower($this->randomName());
$dependent = array(
'field_name' => $field_name,
'type' => $field_type,
'cardinality' => 1,
);
// Some fields need allowed values to function properly.
if ($widget_info['module'] == 'options') {
$dependent['settings']['allowed_values'] = array('Foo', 'Bar');
}
if ($field_type == 'taxonomy_term_reference') {
$dependent['settings']['allowed_values'] = array(
array(
'vocabulary' => $vocabulary->machine_name,
'parent' => '0',
),
);
}
$dependent_instance = array(
'field_name' => $field_name,
'entity_type' => 'node',
'bundle' => 'conditional_fields_test',
'widget' => array(
'type' => $widget_type,
'settings' => array('display_label' => 1), // Used by boolean on/off checkbox.
),
'required' => TRUE,
'label' => $widget_type . '_' . $field_type . '_label',
);
// Radios spit an error if submitted with no value.
if ($widget_type == 'options_buttons' && $widget_info['module'] == 'list') {
// This is the "Bar" option.
$dependent_instance['default_value'] = 1;
}
$this->dependents[] = array(
'field_type' => $field_type,
'widget_type' => $widget_type,
'widget' => $widget_info,
'field' => $dependent,
'instance' => $dependent_instance,
);
// Create a multiple value version of most fields.
if ($widget_type == 'options_onoff') {
continue;
}
$dependent['cardinality'] = -1;
$dependent['field_name'] = $dependent_instance['field_name'] = $field_name . '_multiple';
$dependent_instance['label'] .= '_multiple';
$this->dependents[] = array(
'field_type' => $field_type,
'widget_type' => $widget_type,
'widget' => $widget_info,
'field' => $dependent,
'instance' => $dependent_instance,
);
}
}
// Create fields and dependencies.
$dependency_options = array(
'value_form' => $this->dependee_on_value,
'value' => array(array('value' => $this->dependee_on_value)),
);
foreach ($this->dependents as $dependent) {
field_create_field($dependent['field']);
field_create_instance($dependent['instance']);
$dependent_instance = field_info_instance('node', $dependent['field']['field_name'], 'conditional_fields_test');
conditional_fields_dependency_insert($dependee_instance['id'], $dependent_instance['id'], $dependency_options);
}
}
/**
* Tests field dependencies on a node.
*/
public function testNodeDependencies() {
// Try to submit a node with triggered dependencies.
// The submit should fail because the dependent fields are required.
$langcode = LANGUAGE_NONE;
$edit = array(
"dependee[$langcode]" => $this->dependee_on_value,
);
$this->drupalPost('node/add/conditional-fields-test', $edit, t('Save'));
foreach ($this->dependents as $dependent) {
// Skip fields that always have a default value.
if (($dependent['widget_type'] == 'options_buttons' && $dependent['field']['cardinality'] == 1) || (in_array($dependent['widget_type'], array('options_select', 'options_buttons')) && $dependent['field_type'] == 'taxonomy_term_reference')) {
continue;
}
// Multiple value textfields are dumb and can't find their own name.
if ($dependent['field']['cardinality'] == -1 && in_array($dependent['widget_type'], array('number', 'text_textfield', 'text_textarea', 'text_textarea_with_summary'))) {
$name = '';
}
else {
$name = $dependent['widget_type'] . '_' . $dependent['field_type'] . '_label';
$name .= $dependent['field']['cardinality'] == -1 ? '_multiple' : '';
}
$this->assertRaw(t('!name field is required.', array('!name' => $name)), 'Triggered ' . ($dependent['field']['cardinality'] == -1 ? 'multiple' : 'single') . ' value required ' . $dependent['field_type'] . ' dependent with widget ' . $dependent['widget_type'] . ' and no value fails validation');
}
// Fill the dependents with values and save the node.
$edit = array(
"dependee[$langcode]" => $this->dependee_on_value,
);
foreach ($this->dependents as $dependent) {
// Text fields have structure field_name[langcode][delta][value].
if (in_array($dependent['widget_type'], array('number', 'text_textfield', 'text_textarea', 'text_textarea_with_summary'))) {
$edit[$dependent['field']['field_name'] . "[$langcode][0][value]"] = '1';
}
elseif ($dependent['widget_type'] == 'options_select') {
if ($dependent['field']['cardinality'] == 1) {
// Single value select fields have structure field_name[langcode].
$edit[$dependent['field']['field_name'] . "[$langcode]"] = '1';
}
else {
// Multiple value select fields have structure field_name[langcode][].
$edit[$dependent['field']['field_name'] . "[$langcode][]"] = '1';
}
}
elseif (in_array($dependent['widget_type'], array('options_buttons', 'options_onoff', 'taxonomy_autocomplete'))) {
if ($dependent['field']['cardinality'] == 1 || $dependent['widget_type'] == 'taxonomy_autocomplete') {
// Radios and autocomplete fields have structure field_name[langcode].
$edit[$dependent['field']['field_name'] . "[$langcode]"] = '1';
}
else {
// Checkboxes have structure field_name[langcode][delta].
$edit[$dependent['field']['field_name'] . "[$langcode][1]"] = '1';
}
}
elseif (in_array($dependent['widget_type'], array('file_generic', 'image_image'))) {
// TODO.
// $edit[$dependent['field']['field_name'] . "[$langcode][0][fid]"] = '1';
}
}
$this->drupalPost('node/add/conditional-fields-test', $edit, t('Save'));
$this->assertRaw(t('@type %title has been created.', array('@type' => 'Conditional Fields Test Node Type', '%title' => '')), 'Node was created with triggered dependencies.');
// Verify that the fields are visible on node view.
foreach ($this->dependents as $dependent) {
$this->assertText($dependent['instance']['label'] . ':', 'Triggered ' . ($dependent['field']['cardinality'] == -1 ? 'multiple' : 'single') . ' value ' . $dependent['field_type'] . ' dependent with widget ' . $dependent['widget_type'] . ' is visible on node view');
}
// Untrigger the dependency and verify that node is updated.
$edit = array(
"dependee[$langcode]" => $this->dependee_off_value,
);
$this->drupalPost('node/1/edit', $edit, t('Save'));
$this->assertRaw(t('@type %title has been updated.', array('@type' => 'Conditional Fields Test Node Type', '%title' => '')), 'Node was updated with untriggered dependencies.');
// Verify that fields are invisible on node view.
foreach ($this->dependents as $dependent) {
$this->assertNoText($dependent['instance']['label'] . ':', 'Triggered ' . ($dependent['field']['cardinality'] == -1 ? 'multiple' : 'single') . ' value ' . $dependent['field_type'] . ' dependent with widget ' . $dependent['widget_type'] . ' is invisible on node view');
}
}
}
class ConditionalFieldsUITestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Conditional Fields UI',
'description' => 'Test Conditional Fields UI.',
'group' => 'Conditional Fields',
);
}
public function setUp() {
parent::setUp('conditional_fields_test', 'list', 'text');
// Create and log in user.
$web_user = $this->drupalCreateUser(array('access administration pages', 'administer content types', 'administer dependencies'));
$this->drupalLogin($web_user);
// Create a field that will be used as a dependee.
$dependee = array(
'field_name' => 'dependee',
'type' => 'list_text',
'settings' => array(
'allowed_values' => array('on' => t('Dependent is visible'), 'off' => t('Dependent is invisible')),
),
);
field_create_field($dependee);
$instance = array(
'field_name' => 'dependee',
'entity_type' => 'node',
'bundle' => 'conditional_fields_test',
'label' => t('Label of the dependee field'),
);
field_create_instance($instance);
// Create a field that will be used as a dependent.
$dependent = array(
'field_name' => 'dependent',
'type' => 'text',
);
field_create_field($dependent);
$instance = array(
'field_name' => 'dependent',
'entity_type' => 'node',
'bundle' => 'conditional_fields_test',
'label' => t('Label of the dependent field'),
);
field_create_instance($instance);
}
/**
* Ensures that the administration pages are viewable.
*/
public function testDependenciesOverview() {
$dependee = field_read_instance('node', 'dependee', 'conditional_fields_test');
$this->drupalGet('admin/structure');
$this->clickLink(t('Field dependencies'));
$this->clickLink(t('Node'));
$this->drupalGet('admin/structure/types/manage/conditional-fields-test');
$this->clickLink(t('Manage dependencies'));
$this->assertFieldByName('dependee', $dependee['id'], 'The dependee selection field is in the content type dependencies page.');
$this->assertFieldByName('dependent', $dependee['id'], 'The dependent selection field is in the content type dependencies page.');
}
/**
* Tests adding, editing and deleting a dependency.
*/
public function testDependencyOperations() {
// Add dependency.
$dependee = field_read_instance('node', 'dependee', 'conditional_fields_test');
$dependent = field_read_instance('node', 'dependent', 'conditional_fields_test');
$edit = array(
'dependee' => $dependee['id'],
'dependent' => $dependent['id'],
);
$this->drupalPost('admin/structure/types/manage/conditional-fields-test/dependencies', $edit, t('Add dependency'), array(), array(), 'conditional-fields-dependency-add-form-node-conditional-fields-test');
// Edit dependency.
$edit = array(
'values_set' => CONDITIONAL_FIELDS_DEPENDENCY_VALUES_AND,
'values' => 'on',
);
$this->drupalPost(NULL, $edit, t('Save settings'), array('query' => array('destination' => 'admin/structure/types/manage/conditional-fields-test/dependencies')));
$this->assertRaw(t('%dependent_name is !state when %dependee_name has all the values: @values.', array(
'%dependent_name' => t('Label of the dependent field'),
'!state' => 'visible',
'%dependee_name' => t('Label of the dependee field'),
'@values' => 'on',
)), 'The dependency was updated correctly.');
// Delete dependency.
$this->clickLink(t('delete'));
$this->drupalPost(NULL, array(), t('Delete dependency'), array('query' => array('destination' => 'admin/structure/types/manage/conditional-fields-test/dependencies')));
$this->assertText(t('The dependency has been deleted.'));
}
}
name = Conditional Fields test
description = Provides hooks for testing Conditional Fields.
package = Fields
core = 7.x
dependencies[] = conditional_fields
files[] = conditional_fields.test
hidden = TRUE
; Information added by packaging script on 2013-11-18
version = "7.x-3.0-alpha1"
core = "7.x"
project = "conditional_fields"
datestamp = "1384798705"
<?php
/**
* @file
* Test Conditional Fields functionality.
*/
/**
* Implements hook_node_info().
*/
function conditional_fields_test_node_info() {
return array(
'conditional_fields_test' => array(
'name' => t('Conditional Fields Test Node Type'),
'module' => 'conditional_fields_test',
'base' => 'conditional_fields_test',
),
);
}
\ No newline at end of file
......@@ -78,7 +78,7 @@ function _mm_add_query_params($url, $params=array()) {
$has_query = parse_url($url, PHP_URL_QUERY);
$separator = $has_query ? '&' : '?';
$add_query = http_build_query($params, '', '&');
$add_query = preg_replace('/(%5B|\[)[0-9]+(%5D|\])/s', '[]', http_build_query($params, '', '&'));
return $url . $separator . $add_query;
}
......@@ -21,16 +21,16 @@ function ocio_landing_page_ds_layout_settings_info() {
'regions' => array(
'ds_hero' => array(
0 => 'field_banner_image',
1 => 'field_banner_image_text',
),
'ds_footer' => array(
1 => 'field_pre_footer_banner_image',
2 => 'field_footer_image',
2 => 'field_pre_footer_banner_image',
),
),
'fields' => array(
'field_banner_image' => 'ds_hero',
'field_banner_image_text' => 'ds_hero',
'field_pre_footer_banner_image' => 'ds_footer',
'field_footer_image' => 'ds_footer',
),
'classes' => array(),
'wrappers' => array(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment