updated webform, webform_localization, profile2, term_merge, search_api_saved_pages, rules, redirect, overide_node_options

This commit is contained in:
2019-05-13 18:47:27 +02:00
parent 58cd990c8c
commit 9adc940a67
281 changed files with 28658 additions and 7138 deletions

View File

@@ -1,15 +1,18 @@
<?php
/**
* @file Contains plugin info and implementations not needed for rule evaluation.
* @file
* Contains plugin info and implementations not needed for rule evaluation.
*/
/**
* Implements a rules action.
*/
class RulesAction extends RulesAbstractPlugin implements RulesActionInterface {
/**
* @var string
*/
protected $itemName = 'action';
/**
@@ -69,6 +72,7 @@ class RulesAction extends RulesAbstractPlugin implements RulesActionInterface {
}
}
}
}
/**
@@ -76,7 +80,14 @@ class RulesAction extends RulesAbstractPlugin implements RulesActionInterface {
*/
class RulesCondition extends RulesAbstractPlugin implements RulesConditionInterface {
/**
* @var string
*/
protected $itemName = 'condition';
/**
* @var bool
*/
protected $negate = FALSE;
public function providesVariables() {
@@ -132,19 +143,28 @@ class RulesCondition extends RulesAbstractPlugin implements RulesConditionInterf
public function label() {
$label = parent::label();
return $this->negate ? t('NOT @condition', array('@condition' => $label)) : $label;
return $this->negate ? t('NOT !condition', array('!condition' => $label)) : $label;
}
}
/**
* An actual rule.
*
* Note: A rule also implements the RulesActionInterface (inherited).
*/
class Rule extends RulesActionContainer {
protected $conditions = NULL;
/**
* @var string
*/
protected $itemName = 'rule';
/**
* @var string
*/
public $label = 'unlabeled';
public function __construct($variables = array(), $providesVars = array()) {
@@ -159,8 +179,9 @@ class Rule extends RulesActionContainer {
}
/**
* Get an iterator over all contained conditions. Note that this iterator also
* implements the ArrayAcces interface.
* Gets an iterator over all contained conditions.
*
* Note that this iterator also implements the ArrayAccess interface.
*
* @return RulesRecursiveElementIterator
*/
@@ -183,8 +204,9 @@ class Rule extends RulesActionContainer {
}
/**
* Get an iterator over all contained actions. Note that this iterator also
* implements the ArrayAcces interface.
* Gets an iterator over all contained actions.
*
* Note that this iterator also implements the ArrayAccess interface.
*
* @return RulesRecursiveElementIterator
*/
@@ -193,11 +215,12 @@ class Rule extends RulesActionContainer {
}
/**
* Add a condition. Pass either an instance of the RulesConditionInterface
* or the arguments as needed by rules_condition().
* Adds a condition.
*
* @return Rule
* Returns $this to support chained usage.
* Pass either an instance of the RulesConditionInterface or the arguments as
* needed by rules_condition().
*
* @return $this
*/
public function condition($name, $settings = array()) {
$this->conditions->condition($name, $settings);
@@ -309,7 +332,9 @@ class Rule extends RulesActionContainer {
}
/**
* Rules may not provided any variable info assertions, as Rules are only
* Overrides RulesPlugin::variableInfoAssertions().
*
* Rules may not provide any variable info assertions, as Rules are only
* conditionally executed.
*/
protected function variableInfoAssertions() {
@@ -324,7 +349,7 @@ class Rule extends RulesActionContainer {
}
/**
* Overriden to expose the variables of all actions for embedded rules.
* Overridden to expose the variables of all actions for embedded rules.
*/
public function providesVariables() {
$provides = parent::providesVariables();
@@ -340,6 +365,7 @@ class Rule extends RulesActionContainer {
parent::resetInternalCache();
$this->conditions->resetInternalCache();
}
}
/**
@@ -347,22 +373,30 @@ class Rule extends RulesActionContainer {
*/
class RulesReactionRule extends Rule implements RulesTriggerableInterface {
/**
* @var string
*/
protected $itemName = 'reaction rule';
/**
* @var array
*/
protected $events = array();
/**
* Returns the array of events associated with that Rule.
* @var array
*/
public function &events() {
protected $eventSettings = array();
/**
* Implements RulesTriggerableInterface::events().
*/
public function events() {
return $this->events;
}
/**
* Removes an event from the rule configuration.
*
* @param $event
* The name of the event to remove.
* @return RulesReactionRule
* Implements RulesTriggerableInterface::removeEvent().
*/
public function removeEvent($event) {
if (($id = array_search($event, $this->events)) !== FALSE) {
@@ -372,10 +406,43 @@ class RulesReactionRule extends Rule implements RulesTriggerableInterface {
}
/**
* @return RulesReactionRule
* Implements RulesTriggerableInterface::event().
*/
public function event($event) {
$this->events[] = $event;
public function event($event_name, array $settings = NULL) {
// Process any settings and determine the configured event's name.
if ($settings) {
$handler = rules_get_event_handler($event_name, $settings);
if ($suffix = $handler->getEventNameSuffix()) {
$event_name .= '--' . $suffix;
$this->eventSettings[$event_name] = $settings;
}
else {
// Do not store settings if there is no suffix.
unset($this->eventSettings[$event_name]);
}
}
if (array_search($event_name, $this->events) === FALSE) {
$this->events[] = $event_name;
}
return $this;
}
/**
* Implements RulesTriggerableInterface::getEventSettings().
*/
public function getEventSettings($event_name) {
if (isset($this->eventSettings[$event_name])) {
return $this->eventSettings[$event_name];
}
}
public function integrityCheck() {
parent::integrityCheck();
// Check integrity of the configured events.
foreach ($this->events as $event_name) {
$handler = rules_get_event_handler($event_name, $this->getEventSettings($event_name));
$handler->validate();
}
return $this;
}
@@ -394,9 +461,9 @@ class RulesReactionRule extends Rule implements RulesTriggerableInterface {
}
public function access() {
$event_info = rules_fetch_data('event_info');
foreach ($this->events as $event) {
if (!empty($event_info[$event]['access callback']) && !call_user_func($event_info[$event]['access callback'], 'event', $event)) {
foreach ($this->events as $event_name) {
$event_info = rules_get_event_info($event_name);
if (!empty($event_info['access callback']) && !call_user_func($event_info['access callback'], 'event', $event_info['name'])) {
return FALSE;
}
}
@@ -405,10 +472,10 @@ class RulesReactionRule extends Rule implements RulesTriggerableInterface {
public function dependencies() {
$modules = array_flip(parent::dependencies());
$event_info = rules_fetch_data('event_info');
foreach ($this->events as $event) {
if (isset($event_info[$event]['module'])) {
$modules[$event_info[$event]['module']] = TRUE;
foreach ($this->events as $event_name) {
$event_info = rules_get_event_info($event_name);
if (isset($event_info['module'])) {
$modules[$event_info['module']] = TRUE;
}
}
return array_keys($modules);
@@ -433,15 +500,20 @@ class RulesReactionRule extends Rule implements RulesTriggerableInterface {
else {
// The intersection of the variables provided by the events are
// available.
$event_info = rules_fetch_data('event_info');
$events = array_intersect($this->events, array_keys($event_info));
foreach ($events as $event) {
$event_info[$event] += array('variables' => array());
foreach ($this->events as $event_name) {
$handler = rules_get_event_handler($event_name, $this->getEventSettings($event_name));
if (isset($this->availableVariables)) {
$this->availableVariables = array_intersect_key($this->availableVariables, $event_info[$event]['variables']);
$event_vars = $handler->availableVariables();
// Merge variable info by intersecting the variable-info keys also,
// so we have only metadata available that is valid for all of the
// provided variables.
foreach (array_intersect_key($this->availableVariables, $event_vars) as $name => $variable_info) {
$this->availableVariables[$name] = array_intersect_key($variable_info, $event_vars[$name]);
}
}
else {
$this->availableVariables = $event_info[$event]['variables'];
$this->availableVariables = $handler->availableVariables();
}
}
$this->availableVariables = isset($this->availableVariables) ? RulesState::defaultVariables() + $this->availableVariables : RulesState::defaultVariables();
@@ -451,18 +523,38 @@ class RulesReactionRule extends Rule implements RulesTriggerableInterface {
}
public function __sleep() {
return parent::__sleep() + drupal_map_assoc(array('events'));
return parent::__sleep() + drupal_map_assoc(array('events', 'eventSettings'));
}
protected function exportChildren($key = 'ON') {
$export[$key] = array_values($this->events);
foreach ($this->events as $event_name) {
$export[$key][$event_name] = (array) $this->getEventSettings($event_name);
}
return $export + parent::exportChildren();
}
protected function importChildren($export, $key = 'ON') {
$this->events = $export[$key];
// Detect and support old-style exports: a numerically indexed array of
// event names.
if (is_string(reset($export[$key])) && is_numeric(key($export[$key]))) {
$this->events = $export[$key];
}
else {
$this->events = array_keys($export[$key]);
$this->eventSettings = array_filter($export[$key]);
}
parent::importChildren($export);
}
/**
* Overrides optimize().
*/
public function optimize() {
parent::optimize();
// No need to keep event settings for evaluation.
$this->eventSettings = array();
}
}
/**
@@ -470,6 +562,9 @@ class RulesReactionRule extends Rule implements RulesTriggerableInterface {
*/
class RulesAnd extends RulesConditionContainer {
/**
* @var string
*/
protected $itemName = 'and';
public function evaluate(RulesState $state) {
@@ -486,6 +581,7 @@ class RulesAnd extends RulesConditionContainer {
public function label() {
return !empty($this->label) ? $this->label : ($this->negate ? t('NOT AND') : t('AND'));
}
}
/**
@@ -493,6 +589,9 @@ class RulesAnd extends RulesConditionContainer {
*/
class RulesOr extends RulesConditionContainer {
/**
* @var string
*/
protected $itemName = 'or';
public function evaluate(RulesState $state) {
@@ -511,6 +610,8 @@ class RulesOr extends RulesConditionContainer {
}
/**
* Overrides RulesContainerPlugin::stateVariables().
*
* Overridden to exclude all variable assertions as in an OR we cannot assert
* the children are successfully evaluated.
*/
@@ -527,6 +628,7 @@ class RulesOr extends RulesConditionContainer {
}
return $vars;
}
}
/**
@@ -534,6 +636,9 @@ class RulesOr extends RulesConditionContainer {
*/
class RulesLoop extends RulesActionContainer {
/**
* @var string
*/
protected $itemName = 'loop';
protected $listItemInfo;
@@ -640,6 +745,7 @@ class RulesLoop extends RulesActionContainer {
$this->settings['item:label'] = reset($export['ITEM']);
}
}
}
/**
@@ -647,6 +753,9 @@ class RulesLoop extends RulesActionContainer {
*/
class RulesActionSet extends RulesActionContainer {
/**
* @var string
*/
protected $itemName = 'action set';
}
@@ -656,6 +765,9 @@ class RulesActionSet extends RulesActionContainer {
*/
class RulesRuleSet extends RulesActionContainer {
/**
* @var string
*/
protected $itemName = 'rule set';
/**
@@ -672,6 +784,7 @@ class RulesRuleSet extends RulesActionContainer {
protected function importChildren($export, $key = 'RULES') {
parent::importChildren($export, $key);
}
}
/**
@@ -679,8 +792,16 @@ class RulesRuleSet extends RulesActionContainer {
*/
class RulesEventSet extends RulesRuleSet {
/**
* @var string
*/
protected $itemName = 'event set';
// Event sets may recurse as we block recursions on rule-level.
/**
* Event sets may recurse as we block recursions on rule-level.
*
* @var bool
*/
public $recursion = TRUE;
public function __construct($info = array()) {
@@ -698,7 +819,10 @@ class RulesEventSet extends RulesRuleSet {
}
/**
* Cache event-sets per event to allow efficient usage via rules_invoke_event().
* Rebuilds the event cache.
*
* We cache event-sets per event in order to allow efficient usage via
* rules_invoke_event().
*
* @see rules_get_cache()
* @see rules_invoke_event()
@@ -711,18 +835,27 @@ class RulesEventSet extends RulesRuleSet {
$rules = rules_config_load_multiple(FALSE, array('plugin' => 'reaction rule', 'active' => TRUE));
foreach ($rules as $name => $rule) {
foreach ($rule->events() as $event) {
foreach ($rule->events() as $event_name) {
$event_base_name = rules_get_event_base_name($event_name);
// Skip not defined events.
if (empty($events[$event])) {
if (empty($events[$event_base_name])) {
continue;
}
// Create an event set if not yet done.
if (!isset($sets[$event])) {
$event_info = $events[$event] + array(
'variables' => isset($events[$event]['arguments']) ? $events[$event]['arguments'] : array(),
);
$sets[$event] = new RulesEventSet($event_info);
$sets[$event]->name = $event;
if (!isset($sets[$event_name])) {
$handler = rules_get_event_handler($event_name, $rule->getEventSettings($event_name));
// Start the event dispatcher for this event, if any.
if ($handler instanceof RulesEventDispatcherInterface && !$handler->isWatching()) {
$handler->startWatching();
}
// Update the event info with the variables available based on the
// event settings.
$event_info = $events[$event_base_name];
$event_info['variables'] = $handler->availableVariables();
$sets[$event_name] = new RulesEventSet($event_info);
$sets[$event_name]->name = $event_name;
}
// If a rule is marked as dirty, check if this still applies.
@@ -732,23 +865,22 @@ class RulesEventSet extends RulesRuleSet {
if (!$rule->dirty) {
// Clone the rule to avoid modules getting the changed version from
// the static cache.
$sets[$event]->rule(clone $rule);
$sets[$event_name]->rule(clone $rule);
}
}
}
// Create cache items for all created sets.
foreach ($sets as $event => $set) {
foreach ($sets as $event_name => $set) {
$set->sortChildren();
$set->optimize();
// Allow modules to alter the cached event set.
drupal_alter('rules_event_set', $event, $set);
rules_set_cache('event_' . $event, $set);
drupal_alter('rules_event_set', $event_name, $set);
rules_set_cache('event_' . $event_name, $set);
}
// Cache a list of empty sets so we can use it to speed up later calls.
// See rules_get_event_set().
$empty_events = array_keys(array_diff_key($events, $sets));
variable_set('rules_empty_sets', array_flip($empty_events));
// Cache a whitelist of configured events so we can use it to speed up later
// calls. See rules_invoke_event().
rules_set_cache('rules_event_whitelist', array_flip(array_keys($sets)));
}
protected function stateVariables($element = NULL) {
@@ -763,4 +895,5 @@ class RulesEventSet extends RulesRuleSet {
public function save($name = NULL, $module = 'rules') {
return FALSE;
}
}