FINAL suepr merge step : added all modules to this super repos

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-19 16:46:59 +02:00
7585 changed files with 1723356 additions and 18 deletions

View 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.

View File

@@ -0,0 +1,37 @@
--------------------------------------------------------------------------------
Rules Links
--------------------------------------------------------------------------------
This module allows you to create links, which trigger rules.
Dependencies
------------
Rules Links dependes on following modules:
* Rules - http://drupal.org/project/rules
* Entity API - http://drupal.org/project/entity
* (Optionally) Views 3 - http://drupal.org/project/views
Usage
-----
To create a new link go to admin/config/workflow/rules_links and click on
"Add rules link". Enter the title of your link and set all the settings. After
clicking on the "Save Rules Link" button, the module will generate a new And-
and Rules-Set and their forms will be embedded into the rules link editing form.
The And-Sets are called Visibility Conditions and will define when to render
the links. The Rules set is the rule, that will be triggered on clicking the
rule. Additionally Rules Links also generates access permission for each link,
which you'll have to set in admin/people/permissions.
The best way to display the links is currently using views. Rules Links link
will create a Views field for each link, using the title of the link as title
for the field. So if you have link for nodes with the delete 'Delete node',
you'll find the Views field under name 'Content: Delete node'.
Alternatively you can use render the links directly in the entities that can be
displayed, using the option 'Show link in entity' in the Rules Links settings.
Note that this will not work for links were the parameters have multiple.
paramaters.
If you would like to render a link yourself in a theme or in a module, than use
the function rules_link_render_link().

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@@ -0,0 +1,3 @@
<div class="rules-link-wrapper rules-link-<?php print $rules_link->name ?>">
<a href="<?php print $href ?>" <?php print $attr ?>><?php print $title ?></a>
</div>

View File

@@ -0,0 +1,502 @@
<?php
/**
* @file
* Generate a admin UI.
*/
/**
* UI controller.
*/
class RulesLinkUIController extends EntityDefaultUIController {
/**
* Overrides EntityDefaultUIController::hook_menu() defaults.
*/
public function hook_menu() {
$items = parent::hook_menu();
$id_count = count(explode('/', $this->path));
$wildcard = isset($this->entityInfo['admin ui']['menu wildcard']) ? $this->entityInfo['admin ui']['menu wildcard'] : '%entity_object';
$items[$this->path]['description'] = 'Manage links that trigger rules.';
$items[$this->path . '/manage/' . $wildcard . '/components'] = array(
'title' => t('Configure rules'),
'page callback' => 'drupal_get_form',
'page arguments' => array('rules_link_component_form', $this->entityType, $id_count + 1),
'load arguments' => array($this->entityType),
'access callback' => 'entity_access',
'access arguments' => array('update', $this->entityType, $id_count + 1),
'file' => 'rules_link.admin.inc',
'file path' => drupal_get_path('module', 'rules_link'),
'type' => MENU_LOCAL_TASK,
'weight' => 2,
);
return $items;
}
/**
* Overrides EntityDefaultUIController::overviewTableHeaders().
*/
protected function overviewTableHeaders($conditions, $rows, $additional_header = array()) {
$additional_header[] = t('Entity');
return parent::overviewTableHeaders($conditions, $rows, $additional_header);
}
/**
* Overrides EntityDefaultUIController::overviewTableRow().
*/
protected function overviewTableRow($conditions, $id, $entity, $additional_cols = array()) {
// Add a column showing the entity type.
$entity_info = entity_get_info($entity->entity_type);
$additional_cols[] = $entity_info['label'];
return parent::overviewTableRow($conditions, $id, $entity, $additional_cols);
}
/**
* Overrides EntityDefaultUIController::entityFormSubmitBuildEntity().
*/
public function entityFormSubmitBuildEntity($form, &$form_state) {
$rules_link = $form_state[$this->entityType];
$values = $form_state['values'];
$rules_link->name = $values['name'];
$rules_link->label = $values['label'];
$rules_link->entity_type = $values['entity_type'];
$rules_link->path = $values['path'];
$rules_link->settings['text'] = $values['text'];
$rules_link->settings['link_type'] = $values['link_type'];
$rules_link->settings['bundles'] = $values['bundles'];
$rules_link->settings['entity_link'] = isset($values['entity_link']) ? $values['entity_link'] : '';
if ($rules_link->settings['link_type'] == 'confirm') {
$rules_link->settings['confirm_question'] = $values['question'];
$rules_link->settings['confirm_description'] = $values['description'];
}
return $rules_link;
}
}
/**
* Generates the rules link editing form.
*/
function rules_link_form($form, &$form_state, $rules_link, $op = 'edit') {
drupal_add_css(drupal_get_path('module', 'rules_link') . '/rules_link.css', 'file');
if ($op == 'clone') {
$rules_link->label .= ' (cloned)';
$rules_link->name .= '_cloned';
}
$form['label'] = array(
'#title' => t('Label'),
'#type' => 'textfield',
'#default_value' => isset($rules_link->label) ? $rules_link->label : '',
'#description' => t('The human-readable name of this rules link'),
'#required' => TRUE,
'#size' => 30,
);
$form['name'] = array(
'#type' => 'machine_name',
'#description' => t('A unique machine-readable name for this rules link. It must only contain lowercase letters, numbers, and underscores and must not begin with a number.'),
'#default_value' => isset($rules_link->name) ? $rules_link->name : '',
'#disabled' => $rules_link->hasStatus(ENTITY_IN_CODE) && $op != 'clone',
'#required' => TRUE,
'#maxlength' => 32,
'#machine_name' => array(
'exists' => 'rules_link_get_links',
'source' => array('label'),
),
);
$entity_options = array();
$entities = entity_get_info();
foreach ($entities as $key => $entity) {
$entity_options[$key] = t($entity['label']);
}
$default_entity = isset($form_state['values']['entity_type']) ? $form_state['values']['entity_type'] : (isset($rules_link->entity_type) ? $rules_link->entity_type : 'node');
$form['entity_type'] = array(
'#title' => t('Entity Type'),
'#description' => t('Enity type to which the link should be attached to.'),
'#default_value' => $default_entity,
'#options' => $entity_options,
'#required' => TRUE,
'#type' => 'select',
'#maxlength' => 32,
'#ajax' => array(
'callback' => 'rules_link_bundle_js_callback',
'wrapper' => 'rules-link-bundle',
'speed' => 'fast',
),
);
$bundle_options = array();
if (isset($form_state['clicked_button']) && $form_state['clicked_button']['#parents'][0] == 'show_all') {
foreach ($entities as $key => $entity) {
foreach ($entity['bundles'] as $key => $bundle) {
$bundle_options[$key] = $bundle['label'];
}
}
}
else {
foreach ($entities[$default_entity]['bundles'] as $key => $bundle) {
$bundle_options[$key] = isset($bundle['label']) ? $bundle['label'] : $key;
}
}
$form['bundle_wrapper'] = array(
'#prefix' => '<div id="rules-link-bundle">',
'#suffix' => '</div>',
);
$form['bundle_wrapper']['bundles'] = array(
'#title' => t('Bundles'),
'#description' => t('Bundles to which the link should be attached to. If left empty, the link is not restricted for any bundles.'),
'#type' => 'select',
'#options' => $bundle_options,
'#default_value' => isset($rules_link->settings['bundles']) ? $rules_link->settings['bundles'] : array(),
'#multiple' => TRUE,
);
// If the entity type does not make use of bundles, make sure we are not
// restricting by bundle.
$entity_info = entity_get_info($default_entity);
if (empty($entity_info['entity keys']['bundle'])) {
$form['bundle_wrapper']['bundles']['#access'] = FALSE;
$form['bundle_wrapper']['bundles']['#value'] = array();
}
$html_id_show_all= drupal_html_id('rules-link-show-all-wrapper');
// Button for users without js.
$form['show_all'] = array(
'#type' => 'button',
'#value' => t('Show All'),
'#prefix' => "<div id='$html_id_show_all'>",
'#suffix' => '</div>'
);
// Hide the button for users with javascript.
drupal_add_js('(function ($) { $("#' . $html_id_show_all . '").hide() }(jQuery));',
array('type' => 'inline', 'scope' => 'footer')
);
$form['text'] = array(
'#title' => t('Link text'),
'#type' => 'textfield',
'#default_value' => isset($rules_link->settings['text']) ? $rules_link->settings['text'] : '',
'#description' => t('The text of the link.'),
'#required' => TRUE,
'#size' => 30,
);
$form['link_type'] = array(
'#type' => 'radios',
'#title' => t('Link type'),
'#default_value' => isset($rules_link->settings['link_type']) ? $rules_link->settings['link_type'] : 'token',
'#options' => array('javascript' => t('Javascript'), 'token' => t('Normal'), 'confirm' => t('Confirmation')),
);
$form['confirm']['confirm_question'] = array(
'#type' => 'textfield',
'#title' => t('Confirm question'),
'#default_value' => isset($rules_link->settings['confirm_text']) ? $rules_link->settings['confirm_text'] : '',
'#required' => TRUE,
'#weight' => 50,
'#states' => array(
// Show the form only when the link type is confirm.
'visible' => array(
'input[name="link_type"]' => array('value' => 'confirm'),
),
),
);
$form['confirm'] = array(
'#type' => 'fieldset',
'#title' => 'Confirmation form settings.',
'#states' => array(
// Show the form only when the link type is confirm.
'visible' => array(
'input[name="link_type"]' => array('value' => 'confirm'),
),
),
);
$form['confirm']['question'] = array(
'#type' => 'textfield',
'#title' => t('Confirm question'),
'#description' => t('The question that should appear, when confirmation form is shown.'),
'#default_value' => isset($rules_link->settings['confirm_question']) ? $rules_link->settings['confirm_question'] : '',
);
$form['confirm']['description'] = array(
'#type' => 'textfield',
'#title' => t('Confirm description'),
'#description' => t('The description that should appear, when confirmation form is shown.'),
'#default_value' => isset($rules_link->settings['confirm_description']) ? $rules_link->settings['confirm_description'] : '',
);
global $base_url;
$form['path'] = array(
'#title' => t('Path'),
'#description' => t('(Optional) Path for the link. It not set a default link will be generated.'),
'#default_value' => isset($rules_link->path) ? $rules_link->path : '',
'#type' => 'textfield',
'#field_prefix' => $base_url . '/',
);
$form['entity_link'] = array(
'#type' => 'checkbox',
'#title' => t('Show link when entity is rendered'),
'#description' => t('If checked, the link is shown when viewing an entity to which the bundle and the visibility conditions apply. Only applies to displayed entity types and if no addition variables were added.'),
'#default_value' => isset($rules_link->settings['entity_link']) ? $rules_link->settings['entity_link'] : FALSE,
);
if ($op == 'add') {
RulesPluginUI::formDefaults($form, $form_state);
$rules_link_temp_component = rules_plugin_factory('and');
$rules_link_temp_component->form($form['variables'], $form_state, array('show settings' => TRUE, 'button' => TRUE, 'init' => TRUE));
unset($form['variables']['settings']['label']);
unset($form['variables']['settings']['name']);
unset($form['variables']['settings']['tags']);
$form['variables']['settings']['vars']['#title'] = t('Additional Variables');
$form['variables']['settings']['vars']['#description'] = t('Here you can add additional variable, which should be used apart from the entity type by the access conditions and the rule sets.') . ' ' . $form['variables']['settings']['vars']['#description'];
$form['variables']['settings']['#collapsible'] = FALSE;
$form['variables']['settings']['#type'] = 'container';
$form['variables']['settings']['label']['#default_value'] = '';
$form['variables']['settings']['#weight'] = -1;
// Add JS file that sets the correct type, label and machine name for the
// selected entity type.
drupal_add_js(drupal_get_path('module', 'rules_link') . '/rules_link.admin.js', 'file');
$form['variables']['settings']['vars']['items'][0]['type']['#default_value'] = 'node';
$form['variables']['settings']['vars']['items'][0]['type']['#disabled'] = TRUE;
//$form['variables']['settings']['vars']['items'][0]['type']
$form['variables']['settings']['vars']['items'][0]['label']['#default_value'] = 'node';
$form['variables']['settings']['vars']['items'][0]['label']['#disabled'] = TRUE;
$form['variables']['settings']['vars']['items'][0]['name']['#default_value'] = 'node';
$form['variables']['settings']['vars']['items'][0]['name']['#disabled'] = TRUE;
// Hide the rule elements stuff for now.
foreach (array('elements', 'negate') as $key) {
$form[$key]['#access'] = FALSE;
}
foreach (array('active', 'weight') as $key) {
$form['settings'][$key]['#access'] = FALSE;
}
unset($form['variables']['negate']);
$form_state['rules_link_temp_component'] = &$rules_link_temp_component;
$form['entity_link']['#states'] = array(
// Disable this form if additional variables were added.
'disabled' => array(
'input[name="settings[vars][items][1][name]"]' => array('filled' => TRUE),
),
'unchecked' => array(
'input[name="settings[vars][items][1][name]"]' => array('filled' => TRUE),
),
);
}
else {
$condition_set = rules_link_load_condition_set($rules_link);
$condition_vars = $condition_set->componentVariables();
$form['entity_link']['#disabled'] = count($condition_vars) > 1 ? TRUE : FALSE;
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save Rules Link'),
'#weight' => 40,
);
}
return $form;
}
/**
* Callback for the select box for bundles.
*/
function rules_link_bundle_js_callback($form, $form_state) {
return $form['bundle_wrapper'];
}
/**
* Validation form for editing form.
*/
function rules_link_form_validate(&$form, &$form_state) {
$rules_link = entity_ui_form_submit_build_entity($form, $form_state);
if (!entity_property_verify_data_type($rules_link->name, 'token')) {
form_error($form['name'], t('The name "%name" is not a valid name. Please select a different name.', array('%name' => $rules_link->name)));
}
$path = empty($rules_link->path) ? $rules_link->name : $rules_link->path;
$menu_item = menu_get_item($path);
$lookup_path = drupal_lookup_path('source', $path);
if (!empty($menu_item) || !empty($lookup_path)) {
form_error($form['path'], t('The path "%path" is already in use. This system cannot override existing paths. Please select a different name or enter a different path.', array('%path' => $path)));
}
foreach (rules_link_get_links() as $link) {
if ($link->path == $path && $link->name != $rules_link->name) {
form_error($form['path'], t('The path "%path" is taken by the rules link "%link". This system cannot override existing paths.',
array(
'%path' => $path,
'%link' => $link->name,
)
));
}
}
}
/**
* Form API submit callback for the type form.
*/
function rules_link_form_submit(&$form, &$form_state) {
$rules_link = entity_ui_form_submit_build_entity($form, $form_state);
$form_state['redirect'] = 'admin/config/workflow/rules_links';
if (empty($rules_link->path)) {
$rules_link->path = $rules_link->name;
}
if ($form_state['op'] == 'add') {
$form_state['redirect'] = 'admin/config/workflow/rules_links/manage/' . $rules_link->name;
$rule_set = rules_link_load_rules_set($rules_link);
$condition_set = rules_link_load_condition_set($rules_link);
$rules_set_vars = &$rule_set->componentVariables();
$condition_vars = &$condition_set->componentVariables();
// Remove the first element, since it is decoration only and it might be
// wrong in case Javascript is disabled.
array_shift($form_state['values']['settings']['vars']['items']);
foreach ($form_state['values']['settings']['vars']['items'] as $var) {
if ($var['type'] !== '0') {
$val = array(
'label' => $var['label'],
'type' => $var['type'],
);
$rules_set_vars[$var['name']] = $val;
$condition_vars[$var['name']] = $val;
}
}
$condition_set->label = 'Rules link: ' . $rules_link->label . ' condition';
$condition_set->save(rules_link_get_condition_set_name($rules_link), 'rules_link');
$rule_set->label = 'Rules link: ' . $rules_link->label . ' rules set';
$rule_set->save(rules_link_get_rules_set_name($rules_link), 'rules_link');
drupal_set_message(t('Your Rules Link has been created along with the required components. Please remember to set <a href="!url">%link</a> for your link and to add actions to your reactions rule.', array('%link' => t('the permissions'), '!url' => url('admin/people/permissions', array('fragment' => 'module-rules_link')))));
}
else {
drupal_set_message(t('Your Rules Link has been saved.'));
}
// Save and go back.
$rules_link->save();
}
/**
* Form function for the rules link components.
*/
function rules_link_component_form($form, $form_state, $entity_type, $rules_link) {
$form = array();
$form_state['rules_link'] = $rules_link;
$condition = rules_link_load_condition_set($rules_link);
$condition->form($form['condition_set'], $form_state);
$form['condition_set']['elements']['#caption'] = '';
$form['condition_set']['help']['#title'] = t('Access conditions');
$form['condition_set']['help']['#type'] = 'item';
$form['condition_set']['help']['#markup'] = t('The access conditions can additionally to <a href="!url">%link</a> specify, when to show the rules links.', array('%link' => t('the permissions'), '!url' => url('admin/people/permissions', array('fragment' => 'module-rules_link'))));
// Since we never want to negate the result, we can hide the form.
unset($form['condition_set']['negate']);
$form['condition_set']['#tree'] = TRUE;
$rule_set = rules_link_load_rules_set($rules_link);
$rule_set->form($form['rule_set'], $form_state, array('show settings' => TRUE));
$form['rule_set']['elements']['#caption'] = '';
$form['rule_set']['#tree'] = TRUE;
$form['rule_set']['help']['#title'] = t('Reactions');
$form['rule_set']['help']['#type'] = 'item';
$form['rule_set']['help']['#markup'] = t('To output a system message, simply use the "Show a message on the site" action in one of your rules. Javascript links will replace the link with the text from the system message.');
$form['rule_set']['settings']['vars']['#description'] .= '<br/>' . t('Please also note that Rules Link only checks if there are enough variables available, but not if the entities could be loaded. You will have to check that your self in your components.');
$form['rule_set']['settings']['label']['#access'] = FALSE;
$form['rule_set']['settings']['name']['#type'] = 'value';
$form['rule_set']['settings']['tags']['#access'] = FALSE;
$form['rule_set']['settings']['vars']['items'][$rules_link->entity_type]['#disabled'] = TRUE;
$form_state['rules_link_condition_set'] = $condition;
$form_state['rules_link_rules_set'] = $rule_set;
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save Rules Link'),
'#weight' => 40,
);
return $form;
}
function rules_link_component_form_validate(&$form, &$form_state) {
$form_state['rules_link_condition_set']->form_validate($form['condition_set'], $form_state);
$form_state['rules_link_rules_set']->form_validate($form['rule_set'], $form_state);
}
/**
* Form API submit callback for the type form.
*/
function rules_link_component_form_submit(&$form, &$form_state) {
$rules_set_vars = $form_state['rules_link_rules_set']->componentVariables();
$form_state['rules_link_rules_set']->form_submit($form['rule_set'], $form_state);
$condition_vars = &$form_state['rules_link_condition_set']->componentVariables();
foreach ($condition_vars as $key => $value) {
unset($condition_vars[$key]);
}
foreach ($rules_set_vars as $key => $value) {
$condition_vars[$key] = $value;
}
$form_state['rules_link_condition_set']->form_submit($form['condition_set'], $form_state);
// If the rule is renamed, rename also the rules set.
if ($form_state['rules_link_condition_set']->name != rules_link_get_condition_set_name($form_state['rules_link'])) {
$form_state['rules_link_condition_set']->label = 'Rules link: ' . $form_state['rules_link']->label . ' condition';
$form_state['rules_link_condition_set']->save(rules_link_get_condition_set_name($form_state['rules_link']), 'rules_link');
}
// If the rule is renamed, rename also the rules set.
if ($form_state['rules_link_rules_set']->name != rules_link_get_rules_set_name($form_state['rules_link'])) {
$form_state['rules_link_rules_set']->label = 'Rules link: ' . $form_state['rules_link']->label . ' rules set';
$form_state['rules_link_rules_set']->save(rules_link_get_rules_set_name($form_state['rules_link']), 'rules_link');
}
// If an additional variable was added, then disable 'show link in entity'.
if (count($rules_set_vars) > 1) {
$form_state['rules_link']->settings['entity_link'] = FALSE;
$form_state['rules_link']->save();
}
drupal_set_message(t('Your Rules Link components has been saved.'));
}

View File

@@ -0,0 +1,17 @@
/**
* @file
* Ui Tweaks for rules link admin ui.
*/
(function($) {
Drupal.behaviors.rules_link = {
attach: function(context) {
$('#edit-entity-type').change(function() {
$('#edit-settings-vars-items-0-type').val($(this).val());
$('#edit-settings-vars-items-0-label').val($('#edit-entity-type option:selected').text());
$('#edit-settings-vars-items-0-name').val($(this).val());
});
}
};
})(jQuery);

View File

@@ -0,0 +1,98 @@
<?php
/**
* @file
* Hooks provided by this module.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Acts on rules links being loaded from the database.
*
* This hook is invoked during rules link loading, which is handled by
* entity_load(), via the EntityCRUDController.
*
* @param array $rules_links
* An array of rules link entities being loaded, keyed by id.
*
* @see hook_entity_load()
*/
function hook_rules_link_load(array $rules_links) {
$result = db_query('SELECT pid, foo FROM {mytable} WHERE pid IN(:ids)', array(':ids' => array_keys($entities)));
foreach ($result as $record) {
$entities[$record->pid]->foo = $record->foo;
}
}
/**
* Responds when a rules link is inserted.
*
* This hook is invoked after the rules link is inserted into the database.
*
* @param RulesLink $rules_link
* The rules link that is being inserted.
*
* @see hook_entity_insert()
*/
function hook_rules_link_insert(RulesLink $rules_link) {
db_insert('mytable')
->fields(array(
'id' => entity_id('rules_link', $rules_link),
'extra' => print_r($rules_link, TRUE),
))
->execute();
}
/**
* Acts on a rules link being inserted or updated.
*
* This hook is invoked before the rules link is saved to the database.
*
* @param RulesLink $rules_link
* The rules link that is being inserted or updated.
*
* @see hook_entity_presave()
*/
function hook_rules_link_presave(RulesLink $rules_link) {
$rules_link->name = 'foo';
}
/**
* Responds to a rules link being updated.
*
* This hook is invoked after the rules link has been updated in the database.
*
* @param RulesLink $rules_link
* The rules link that is being updated.
*
* @see hook_entity_update()
*/
function hook_rules_link_update(RulesLink $rules_link) {
db_update('mytable')
->fields(array('extra' => print_r($rules_link, TRUE)))
->condition('id', entity_id('rules_link', $rules_link))
->execute();
}
/**
* Responds to rules link deletion.
*
* This hook is invoked after the rules link has been removed from the database.
*
* @param RulesLink $rules_link
* The rules link that is being deleted.
*
* @see hook_entity_delete()
*/
function hook_rules_link_delete(RulesLink $rules_link) {
db_delete('mytable')
->condition('pid', entity_id('rules_link', $rules_link))
->execute();
}
/**
* @}
*/

View File

@@ -0,0 +1,21 @@
.rules-link-wrapper {
position: relative;
}
a.rules-link {
position: relative;
}
.rules-link-waiting {
background: url(rules-link-throbber.gif) no-repeat right center;
padding-right: 16px;
}
.rules-link-waiting a {
opacity: 0.5;
filter: alpha(opacity=50); /* IE */
}
.rules-link-rules-margin {
margin-bottom: 3em;
}

View File

@@ -0,0 +1,16 @@
name = Rules Link
description = Attach link to entities for triggering Rules components.
package = Rules
core = 7.x
configure = admin/config/workflow/rules_links
dependencies[] = rules
files[] = rules_link.views.inc
files[] = rules_link.admin.inc
files[] = rules_link.test
; Information added by drupal.org packaging script on 2013-10-01
version = "7.x-1.0-beta5+0-dev"
core = "7.x"
project = "rules_link"
datestamp = "1380626278"

View File

@@ -0,0 +1,72 @@
<?php
/**
* @file
* Install, update and uninstall functions for the rules_link module.
*/
/**
* Implements hook_schema().
*/
function rules_link_schema() {
$schema['rules_link'] = array(
'description' => 'Stores rules links.',
'fields' => array(
'id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique id for the links.',
),
'name' => array(
'description' => 'The (machine readable) name of the link.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
),
'label' => array(
'description' => 'The label of the link.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'path' => array(
'type' => 'text',
'description' => 'The path for the link.',
),
'entity_type' => array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
'description' => 'The entity type to which the link should be attached.',
),
'settings' => array(
'type' => 'blob',
'size' => 'big',
'serialize' => TRUE,
'description' => 'Everything else, serialized.',
),
'status' => array(
'type' => 'int',
'not null' => TRUE,
// Set the default to ENTITY_CUSTOM without using the constant as it is
// not safe to use it at this point.
'default' => 0x01,
'size' => 'tiny',
'description' => 'The exportable status of the entity.',
),
'module' => array(
'description' => 'The name of the providing module if the entity has been defined in code.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
),
'primary key' => array('id'),
'unique keys' => array(
'name' => array('name'),
),
);
return $schema;
}

View File

@@ -0,0 +1,52 @@
/**
* @file
* Converts a normal link into javascript rules link.
*/
(function($) {
Drupal.behaviors.rules_link = {
attach: function(context) {
$('a.rules-link-js').once( function() {
var message = $('<span class="rules-link-message">Link executed</span>').hide();
var wrapper = $(this).parents('.rules-link-wrapper').append(message);
});
$('a.rules-link-js').click(rules_link);
}
};
function rules_link(context) {
var element = this;
var wrapper = $(element).parents('.rules-link-wrapper');
var message = wrapper.children('.rules-link-message');
if (wrapper.is('.rules-link-waiting')) {
return false;
}
wrapper.addClass('rules-link-waiting');
$.ajax({
type: 'GET',
url: element.href,
dataType: 'json',
success: function (data) {
wrapper.removeClass('rules-link-waiting');
if (data.message.status !== undefined) {
$(element).replaceWith("<span>" + data.message.status +"</span>");
}
else {
$(element).remove();
}
},
error: function (xmlhttp) {
alert(Drupal.t('An HTTP error '+ xmlhttp.status +' occurred.\n'+ element.href));
wrapper.removeClass('rules-link-waiting');
message.text("Error while executing the rules link.");
message.show();
setTimeout(function(){
message.fadeOut();
}, 3000);
}
});
return false;
};
})(jQuery);

View File

@@ -0,0 +1,570 @@
<?php
/**
* @file
* Rules Link - module file.
*/
/**
* Implements hook_entity_info().
*/
function rules_link_entity_info() {
return array(
'rules_link' => array(
'label' => t('Rules Link'),
'entity class' => 'RulesLink',
'controller class' => 'EntityAPIControllerExportable',
'base table' => 'rules_link',
'fieldable' => TRUE,
'entity keys' => array(
'id' => 'id',
'name' => 'name',
'label' => 'label',
),
'exportable' => TRUE,
'module' => 'rules_link',
'access callback' => 'rules_link_access',
// Enable the entity API's admin UI.
'admin ui' => array(
'path' => 'admin/config/workflow/rules_links',
'file' => 'rules_link.admin.inc',
'controller class' => 'RulesLinkUIController',
),
),
);
}
/**
* Access callback for the entity API.
*/
function rules_link_access($op, $type = NULL, $account = NULL) {
return user_access('administer rules links', $account);
}
/**
* Menu argument loader; Load a rules link by string.
*
* @param $name
* The machine-readable name of a rules link to load.
* @return
* A rules link array or FALSE if $name does not exist.
*/
function rules_link_load($name) {
return rules_link_get_links($name);
}
/**
* Implements hook_permission().
*/
function rules_link_permission() {
$permissions = array(
'administer rules links' => array(
'title' => t('Administer rules links'),
'description' => t('Create and delete rules links and set their permissions.'),
),
);
foreach (rules_link_get_links() as $link) {
$name = check_plain($link->name);
$permissions += array(
"access rules link $name" => array(
'title' => t('%link_label: Execute rules link', array('%link_label' => $link->label)),
),
);
}
return $permissions;
}
/**
* Gets an array of all rules links, keyed by the type name.
*
* @param $link_names
* If set, the function will return the link with the given name.
* @return RuleLinks[]
* Depending on isset $link_names, a name single or an array of rules links.
*/
function rules_link_get_links($link_names = NULL) {
$links = entity_load_multiple_by_name('rules_link', isset($link_names) ? array($link_names) : FALSE);
return isset($link_names) ? reset($links) : $links;
}
/**
* Returns the name condition set to a rules link.
*/
function rules_link_get_condition_set_name($rules_link) {
return 'rules_link_condition_' . $rules_link->name;
}
/**
* Returns the name condition set to a rules link.
*/
function rules_link_get_rules_set_name($rules_link) {
return 'rules_link_set_' . $rules_link->name;
}
/**
* Loads and returns the condition to a link. If it
* doesn't exist, a new one will be created.
*
* @param $rules_link
* The rules link to which the condition should be loaded.
*/
function rules_link_load_condition_set($rules_link) {
$condition_set = rules_config_load(rules_link_get_condition_set_name($rules_link));
if ($condition_set != FALSE) {
return $condition_set;
}
else {
$conditions = rules_and(array(
$rules_link->entity_type => array('type' => $rules_link->entity_type, 'label' => $rules_link->entity_type),
));
$conditions->label = 'Rules link: ' . $rules_link->label . ' condition';
$conditions->save(rules_link_get_condition_set_name($rules_link), 'rules_link');
return $conditions;
}
}
/**
* Loads and returns the rules set to a link. If it
* doesn't exist, a new one will be created.
*
* @param $rules_link
* The rules link to which the condition or rules set should be loaded.
*/
function rules_link_load_rules_set($rules_link) {
$rule_set = rules_config_load(rules_link_get_rules_set_name($rules_link));
if ($rule_set != FALSE) {
return $rule_set;
}
else {
$rule_set = rules_rule_set(array(
$rules_link->entity_type => array('type' => $rules_link->entity_type, 'label' => $rules_link->entity_type),
));
$rule_set->label = 'Rules link: ' . $rules_link->label . ' rules set';
$rule_set->save(rules_link_get_rules_set_name($rules_link), 'rules_link');
return $rule_set;
}
}
/**
* Renders a link using the name of the rules_link and the entity id.
*
* @param $rules_link_name
* The name the link which should be rendered.
* @param $entity_id
* The entity id of entity on which the rule should be triggered.
* @param $destination
* The destination to which the Rules Module should redirect the user after
* triggering the link.
* @param $parameters
* Additional parameters for the Rules components of the link.
*
* @return
* A renderable array.
*/
function rules_link_render($rules_link_name, $entity_id, $destination = NULL, $parameters = array()) {
$rules_link = rules_link_load($rules_link_name);
return rules_link_render_link($rules_link, $entity_id, $destination, $parameters);
}
/**
* Renders a link.
*
* @param $rules_link
* The link which should be rendered.
* @param $entity_id
* The entity id of entity on which the rule should be triggered.
* @param $destination
* The destination to which the Rules Module should redirect the user after
* triggering the link.
* @param $parameters
* Additional parameters for the Rules components of the link.
*
* @return
* A renderable array.
*/
function rules_link_render_link($rules_link, $entity_id, $destination = NULL, $parameters = array()) {
if (rules_link_check_visibility($rules_link, array_merge(array($entity_id), $parameters))) {
$path = $rules_link->path . '/' . $entity_id;
if (count($parameters) > 0) {
$path .= '/' . implode('/', $parameters);
}
$path .= $rules_link->settings['link_type'] == 'confirm' ? '' : '/' . rules_link_get_token($entity_id);
$link = array(
'#title' => $rules_link->getSettingTranslation('text'),
'#href' => $path,
'#attr' => array('class' => array('rules-link'), 'rel' => 'nofollow'),
'#rules_link' => $rules_link,
'#theme' => 'rules_link',
);
if ($rules_link->settings['link_type'] == 'javascript') {
$link['#attr']['class'][] = 'rules-link-js';
drupal_add_js(drupal_get_path('module', 'rules_link') . '/rules_link.js', 'file');
drupal_add_css(drupal_get_path('module', 'rules_link') . '/rules_link.css', 'file');
}
else {
$link['#options'] = array('query' => $destination);
}
return $link;
}
return array();
}
/**
* Trims a whitespaces from a parameter.
*/
function rules_link_trim_parameters(&$value) {
$value = trim($value);
}
/**
* Custom Entity class.
*/
class RulesLink extends Entity {
public $settings = array();
public function __construct($values = array()) {
parent::__construct($values, 'rules_link');
}
/**
* Gets the i18n translation of a setting.
*
* @param $name
* The setting name.
* @param $langcode
* The optional language code. Defaults to the current display language.
*
* @see Entity::getTranslation()
*/
public function getSettingTranslation($name, $langcode = NULL) {
$value = isset($this->settings[$name]) ? $this->settings[$name] : NULL;
$i18n_name = 'rules_link:rules_link:' . $this->identifier() . ':' . $name;
return entity_i18n_string($i18n_name, $value, $langcode);
}
}
/**
* Implements hook_rules_link_insert().
*/
function rules_link_rules_link_insert($link) {
// Do not directly issue menu rebuilds here to avoid potentially multiple
// rebuilds. Instead, let menu_get_item() issue the rebuild on the next page.
variable_set('menu_rebuild_needed', TRUE);
}
/**
* Implements hook_rules_link_update().
*/
function rules_link_rules_link_update($link) {
// Make sure to only issue menu rebuilds if necessary.
// @see rules_link_rules_link_insert()
if (!empty($link->original) && ($link->path != $link->original->path || $link->settings['link_type'] != $link->original->settings['link_type'])) {
variable_set('menu_rebuild_needed', TRUE);
}
}
/**
* Implements hook_rules_link_delete().
*/
function rules_link_rules_link_delete($link) {
// @see rules_link_rules_link_insert()
variable_set('menu_rebuild_needed', TRUE);
// Delete associate rule configs.
rules_link_load_condition_set($link)->delete();
rules_link_load_rules_set($link)->delete();
}
/**
* Generates a token used to protect links from spoofing.
*/
function rules_link_get_token($content_id) {
// Anonymous users get a less secure token, since it must be the same for all
// anonymous users on the entire site to work with page caching.
return ($GLOBALS['user']->uid) ? drupal_get_token($content_id) : md5(drupal_get_private_key() . $content_id);
}
/**
* Checks if the given token is correct.
*/
function rules_link_check_token($token, $content_id) {
return rules_link_get_token($content_id) == $token;
}
function rules_link_get_paramters($rules_link) {
$args = arg();
// Remove the first arguments, that represent the url of the link.
$path_args = explode('/', $rules_link->path);
$args = array_slice($args, count($path_args));
return $args;
}
function rules_link_invoke_component($name, $args) {
if ($component = rules_get_cache('comp_' . $name)) {
return $component->executeByArgs($args);
}
}
function rules_link_check_visibility($rules_link, $args) {
$rule_set = rules_link_load_rules_set($rules_link);
$paramInfo = $rule_set->parameterInfo();
return count($args) >= count($paramInfo) && user_access("access rules link " . $rules_link->name) && rules_link_invoke_component(rules_link_get_condition_set_name($rules_link), $args);
}
/**
* Triggers a rule set from a rules link.
*/
function rules_link_trigger($rules_link, $entity_id) {
rules_link_invoke_component(rules_link_get_rules_set_name($rules_link), rules_link_get_paramters($rules_link));
}
/**
* Menu callback for javascript links.
*/
function rules_link_trigger_js($rules_link, $entity_id) {
rules_link_trigger($rules_link, $entity_id);
$json = array(
'message' => drupal_get_messages(),
);
drupal_json_output($json);
}
/**
* Menu callback for token links.
*/
function rules_link_trigger_token($rules_link, $entity_id) {
rules_link_trigger($rules_link, $entity_id);
drupal_goto();
}
/**
* Form generator for the menu callback for the confirm form links.
*/
function rules_link_trigger_form($form, &$form_state, $rules_link, $entity_id) {
$form['link'] = array(
'#type' => 'hidden',
'#value' => $rules_link->name,
);
$form['entity_id'] = array(
'#type' => 'hidden',
'#value' => $entity_id,
);
return confirm_form($form, $rules_link->getSettingTranslation('confirm_question'), '', $rules_link->getSettingTranslation('confirm_description'));
}
/**
* Submit function for the confirm form links.
*/
function rules_link_trigger_form_submit($form, &$form_state) {
$rules_link = rules_link_load($form_state['values']['link']);
rules_link_trigger($rules_link, $form_state['values']['entity_id']);
}
/**
* Access callback function for confirm type links.
*/
function rules_link_access_link_confirm($rules_link, $entity_id) {
if (rules_link_check_visibility($rules_link, rules_link_get_paramters($rules_link))) {
return TRUE;
}
return FALSE;
}
/**
* Access callback function for the token and javascript links.
*/
function rules_link_access_link($rules_link, $entity_id) {
// The token is always the last element of the argument array.
$params = rules_link_get_paramters($rules_link);
$token = array_pop($params);
return rules_link_check_token($token, $entity_id) && rules_link_access_link_confirm($rules_link, $entity_id);
}
/**
* Implements hook_menu().
*/
function rules_link_menu() {
$item = array();
foreach (rules_link_get_links() as $name => $link) {
$first_arg = (count(explode('/', $link->path)));
switch ($link->settings['link_type']) {
case 'javascript':
$item[$link->path . '/%/%'] = array(
'page callback' => 'rules_link_trigger_js',
'page arguments' => array($link, $first_arg),
'access arguments' => array($link, $first_arg, $first_arg + 1),
'access callback' => 'rules_link_access_link',
'type' => MENU_CALLBACK,
);
break;
case 'token':
$item[$link->path . '/%/%'] = array(
'page callback' => 'rules_link_trigger_token',
'page arguments' => array($link, $first_arg),
'access arguments' => array($link, $first_arg, $first_arg + 1),
'access callback' => 'rules_link_access_link',
'type' => MENU_CALLBACK,
);
break;
case 'confirm':
$item[$link->path . '/%'] = array(
'page callback' => 'drupal_get_form',
'page arguments' => array('rules_link_trigger_form', $link, $first_arg),
'access arguments' => array($link, $first_arg),
'access callback' => 'rules_link_access_link_confirm',
'type' => MENU_CALLBACK,
);
break;
}
}
return $item;
}
/**
* Implements hook_theme().
*/
function rules_link_theme() {
return array(
'rules_link' => array(
'template' => 'rules-link',
'variables' => array('title' => NULL, 'href' => NULL, 'attr' => NULL, 'options' => NULL, 'rules_link' => NULL),
'pattern' => 'rules-link__',
),
);
}
/**
* Implements hook_theme_registry_alter().
*/
function rules_link_theme_registry_alter(&$theme_registry) {
// Override the base hook so that we do not overlay with the default entity
// theme hook defined in entity_theme().
// Directly changing this setting in rules_link_theme() did not work.
$theme_registry['rules_link']['base hook'] = 'rules_link';
}
/**
* Implements hook_views_api().
*/
function rules_link_views_api() {
return array(
'api' => '3.0',
);
}
function template_preprocess_rules_link(&$variables) {
if (!isset($variables['options'])) {
$variables['options'] = array();
}
$variables['options'] += array('html' => FALSE);
$variables['title'] = ($variables['options']['html'] ? $variables['title'] : check_plain($variables['title']));
if (isset($options['attr']['title']) && strpos($options['attr']['title'], '<') !== FALSE) {
$variables['attr']['title'] = strip_tags($options['attr']['title']);
} else if (!isset($options['attr']['title'])) {
$variables['attr']['title'] = $variables['title'];
}
$variables['href'] = check_plain(url($variables['href'], $variables['options']));
$variables['title'] = check_plain($variables['title']);
$variables['attr'] = drupal_attributes($variables['attr']);
}
/**
* Implement hook_entity_view().
*/
function rules_link_entity_view($entity, $type, $view_mode, $langcode) {
$links = array();
$rules_links = rules_link_get_links();
foreach ($rules_links as $name => $rules_link) {
if ($rules_link->entity_type == $type && $rules_link->settings['entity_link']) {
list($id, $rev, $bundle) = entity_extract_ids($type, $entity);
// If the link is restricted to some bundles, verify the bundle.
if ($id && (empty($rules_link->settings['bundles']) || in_array($bundle, $rules_link->settings['bundles']))) {
$renderd_link = rules_link_render_link($rules_link, $id, drupal_get_destination());
if (!empty($renderd_link)) {
$links[$name] = drupal_render($renderd_link);
}
}
}
}
foreach ($links as $name => $link) {
$entity->content['rules_links_' . $name] = array(
'#markup' => $link,
);
}
}
/**
* Implements hook_features_pipe_component_alter() for fields.
*/
function rules_link_features_pipe_rules_link_alter(&$pipe, $data, $export) {
foreach ($data as $id) {
$rules_link = entity_load_single('rules_link', $id);
$pipe['rules_config'][] = rules_link_get_condition_set_name($rules_link);
$pipe['rules_config'][] = rules_link_get_rules_set_name($rules_link);
}
}
/**
* Alter the breadcrumb trail of the rules components.
*/
function rules_link_menu_breadcrumb_alter(&$active_trail, $item) {
if (substr($item['href'], 22, 34) == 'rules/components/manage/rules_link') {
// Parse the name out of the link.
if (substr($item['href'], 57, 3) == 'set') {
$start = 61;
}
elseif (substr($item['href'], 57, 3) == 'con') {
$start = 67;
}
$link_name = substr($item['href'], $start, strlen($item['href']));
$pos = strpos($link_name, '/') ;
if ($pos !== FALSE) {
$link_name = substr($link_name, 0, $pos);
}
$rules_link = rules_link_load($link_name);
if ($rules_link) {
// Replace the link to Rules with a link to Rules Link.
$active_trail[4]['title'] = 'Rules Links';
$active_trail[4]['href'] = 'admin/config/workflow/rules_links';
$active_trail[4]['options']['attributes']['title'] = 'Manage links that triggers rules.';
$active_trail[4]['localized_options'] = array();
// Replace component link with link to the current rules link.
$active_trail[5]['title'] = $rules_link->label;
$active_trail[5]['href'] = "admin/config/workflow/rules_links/manage/$link_name/components";
$active_trail[5]['options']['attributes']['title'] = 'Edit the current link.';
$active_trail[5]['localized_options'] = array();
}
}
}
/**
* Implements hook_field_extra_fields().
*/
function rules_link_field_extra_fields() {
$return = array();
$rules_links = rules_link_get_links();
foreach ($rules_links as $rules_link) {
if ($rules_link->settings['entity_link']) {
$entity_info = entity_get_info($rules_link->entity_type);
$bundles = empty($rules_link->settings['bundles']) ? array_keys($entity_info['bundles']) : $rules_link->settings['bundles'];
foreach ($bundles as $bundle) {
$return[$rules_link->entity_type][$bundle]['display']['rules_links_' . $rules_link->name]['label'] = $rules_link->label;
$return[$rules_link->entity_type][$bundle]['display']['rules_links_' . $rules_link->name]['description'] = '';
$return[$rules_link->entity_type][$bundle]['display']['rules_links_' . $rules_link->name]['weight'] = 0;
}
}
}
return $return;
}

View File

@@ -0,0 +1,104 @@
<?php
/**
* @file
* Views integration.
*/
/**
* Test class for Rules link.
*/
class RulesLinkTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Rules link tests',
'description' => 'Test basic editing and execution of rules links',
'group' => 'Rules',
);
}
protected $admin;
function setUp() {
parent::setUp('rules_link', 'rules');
$this->admin = $this->drupalCreateUser(array('administer rules links', 'administer permissions', 'administer rules'));
}
/**
* Create a link with the given name and the type.
*/
function createLink($name, $type) {
$this->drupalLogin($this->admin);
$this->drupalGet('admin/config/workflow/rules_links/add');
$this->assertText('Add rules link');
$data = array(
'label' => $name,
'name' => $name,
'entity_type' => 'node',
'bundles[]' => array('article'),
'text' => $name,
'link_type' => $type,
'question' => 'foo?',
'description' => 'bar!',
'entity_link' => TRUE,
);
$this->drupalPost('admin/config/workflow/rules_links/add', $data, t('Continue'));
$this->assertText('Your Rules Link has been created along with the required components.');
$this->drupalGet('admin/people/permissions');
$this->assertText("$name: Execute rules link", 'Permission was created.');
//$this->drupalLogout();
// The Simpletest function checkPermissions() saves all permissions into a
// static array, but rules links generates new permissions, when creating
// a link. So we have to reset the static cache, so that the
// checkPermissions function recognizes the new permissions.
drupal_static_reset('checkPermissions');
}
/**
* Test creating a new token link.
*/
function testTokenLink() {
$name = 'token_link';
$this->createLink($name, 'token');
$rules_link = rules_link_load($name);
$set = rules_config_load(rules_link_get_rules_set_name($rules_link));
$set->rule(rule()->action('drupal_message', array('message' => 'Rules link executed.')));
$set->save();
$tokenUser = $this->drupalCreateUser(array("access rules link $name", 'administer rules'));
$this->drupalLogin($tokenUser);
$node = $this->drupalCreateNode(array('title' => 'foo', 'type' => 'article'));
$this->drupalGet('node/' . $node->vid);
$this->clickLink($name);
$this->assertText('Rules link executed');//*/
}
/**
* Test creating a new confirmation link.
*/
function testConfirmLink() {
$name = 'test_rules_link';
$this->createLink($name, 'confirm');
$rules_link = rules_link_load($name);
$set = rules_config_load(rules_link_get_rules_set_name($rules_link));
$set->rule(rule()->action('drupal_message', array('message' => 'Rules link executed.')));
$set->save();
$user2 = $this->drupalCreateUser(array("access rules link $name"));
$this->drupalLogin($user2);
$node = $this->drupalCreateNode(array('title' => 'foo', 'type' => 'article'));
$this->drupalGet('node/' . $node->vid);
$this->clickLink($name);
$this->drupalPost('test_rules_link/1', array(), t('Confirm'));
$this->assertText('Rules link executed.', 'Confirm form was generated and rules link was executed.');
$this->drupalLogout();
}
}

View File

@@ -0,0 +1,96 @@
<?php
/**
* @file
* Provide views data.
*/
/**
* Implements hook_views_data().
*/
function rules_link_views_data() {
$data = array();
foreach (rules_link_get_links() as $name => $rules_link) {
$entity = entity_get_info($rules_link->entity_type);
$data[$entity['base table']][$name]['field']['moved to'] = array('views_entity_' . $rules_link->entity_type, $name, 'field');
$data['views_entity_' . $rules_link->entity_type][$name]['field'] = array(
'title' => $rules_link->label,
'help' => t('Execute the selected rules link.'),
'handler' => 'views_handler_field_rules_link',
'rules link name' => $name,
);
}
return $data;
}
/**
* Renders the links for views.
*/
class views_handler_field_rules_link extends views_handler_field_entity {
function render($value) {
$replacements = filter_xss_admin($this->options['rules_link']['rules_link_parameters']);
$token = $this->get_render_tokens('');
$parameters = array_filter(explode(',', strtr($replacements, $token)));
// Trim the spaces from the
array_walk($parameters, 'rules_link_trim_parameters');
$rules_link = rules_link_load($this->definition['rules link name']);
$entity = $this->get_value($value);
list($id, $rev, $bundle) = entity_extract_ids($rules_link->entity_type, $entity);
// If there are multiple bundle types, we only have to display the links to
// the entities which have the correct bundle.
if (empty($rules_link->settings['bundles']) || in_array($bundle, $rules_link->settings['bundles'])) {
$output = rules_link_render_link($rules_link, $id, drupal_get_destination(), $parameters);
if (isset($this->options['rules_link']['rules_link_rewrite']) && !empty($this->options['rules_link']['rules_link_rewrite'])) {
$output['#options']['html'] = TRUE;
$output['#title'] = strtr($this->options['rules_link']['rules_link_rewrite'], $this->get_render_tokens(''));
}
return $output;
}
}
/**
* Override option_definition.
*/
function option_definition() {
$options = parent::option_definition();
$options['rules_link']['rules_link_parameters'] = array('default' => '');
$options['rules_link']['rules_link_rewrite'] = array('default' => '');
return $options;
}
/**
* Override options_form.
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['rules_link'] = array(
'#type' => 'fieldset',
'#title' => t('Rules Link settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['rules_link']['rules_link_parameters'] = array(
'#type' => 'textfield',
'#title' => t('Additional parameters for the rules link'),
'#description' => t('Enter additional parameter using replacement patterns, use comma to enter multiple items. Whitespaces at the beginning and end of token will be trimmed.'),
'#default_value' => $this->options['rules_link']['rules_link_parameters'],
);
$form['rules_link']['rules_link_rewrite'] = array(
'#type' => 'textarea',
'#title' => t('Rewrite the link text'),
'#description' => t('Enter a custom link title or HTML that you want to place inside of the rules link. You may use the replacement patterns below.'),
'#default_value' => $this->options['rules_link']['rules_link_rewrite'],
);
$form['rules_link']['rules_link_patterns'] = array(
'#type' => 'fieldset',
'#title' => t('Replacement patterns'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#value' => $form['alter']['help']['#value'],
);
}
}

View File

@@ -0,0 +1,13 @@
name = Rules link translation
description = Allows translating Rules links.
dependencies[] = rules_link
dependencies[] = i18n_string
package = Multilingual - Internationalization
core = 7.x
; Information added by drupal.org packaging script on 2013-10-01
version = "7.x-1.0-beta5+0-dev"
core = "7.x"
project = "rules_link"
datestamp = "1380626278"

View File

@@ -0,0 +1,80 @@
<?php
/**
* @file
* Rules link i18n integration module via entity API i18n support.
*
* @see EntityDefaultI18nController
*/
/**
* Implements hook_entity_info_alter().
*/
function rules_link_i18n_entity_info_alter(&$info) {
// Enable i18n support via the entity API.
$info['rules_link']['i18n controller class'] = 'RulesLinkI18nController';
}
/**
* Customized i18n string integration controller.
*/
class RulesLinkI18nController extends EntityDefaultI18nStringController {
/**
* Overriddes EntityDefaultI18nStringController::hook_object_info() to include a custom object wrapper.
*/
public function hook_object_info() {
$info = parent::hook_object_info();
$info['rules_link']['class'] = 'RulesLinkI18nStringObjectWrapper';
return $info;
}
/**
* Overrides EntityDefaultI18nStringController::translatableProperties() to define our custom ones.
*/
protected function translatableProperties() {
$properties = array();
$properties['text'] = t('Link text');
$properties['confirm_question'] = t('Confirm question');
$properties['confirm_description'] = t('Confirm description');
return $properties;
}
}
/**
* Custom i18n object wrapper.
*/
class RulesLinkI18nStringObjectWrapper extends i18n_string_object_wrapper {
/**
* Overrides i18n_string_object_wrapper::get_field() to read properties from the settings array.
*/
public function get_field($field, $default = NULL) {
return isset($this->object->settings[$field]) ? $this->object->settings[$field] : parent::get_field($field, $default);
}
}
/**
* Implements hook_rules_link_insert().
*/
function rules_link_i18n_rules_link_insert($rules_link) {
i18n_string_object_update('rules_link', $rules_link);
}
/**
* Implements hook_rules_link_update().
*/
function rules_link_i18n_rules_link_update($rules_link) {
// Account for name changes.
if ($rules_link->original->name != $rules_link->name) {
i18n_string_update_context("rules_link:rules_link:{$rules_link->original->name}:*", "rules_link:rules_link:{$rules_link->name}:*");
}
i18n_string_object_update('rules_link', $rules_link);
}
/**
* Implements hook_rules_link_delete().
*/
function rules_link_i18n_rules_link_delete($rules_link) {
i18n_string_object_remove('rules_link', $rules_link);
}