You are here

class RulesConditionalSwitch in Conditional Rules 8

Same name and namespace in other branches
  1. 7 includes/rules_conditional.plugin.inc \RulesConditionalSwitch

Switch conditional container.

@method RulesConditionalSwitch case() case($value, $fallThrough = FALSE, $valueIsSelector = FALSE) Adds a "case" statement. @method RulesConditionalSwitch defaultCase() defaultCase() Adds a "default case" statement. @method RulesConditionalSwitch action() action($name, array $settings = array()) Adds an action to the currently active statement. Pass arguments as rules_action() would need.

Hierarchy

Expanded class hierarchy of RulesConditionalSwitch

1 string reference to 'RulesConditionalSwitch'
rules_conditional_rules_plugin_info in ./rules_conditional.rules.inc
Implements hook_rules_plugin_info().

File

includes/rules_conditional.plugin.inc, line 160
Rules plugin implementation.

View source
class RulesConditionalSwitch extends RulesConditionalContainer {
  protected $itemName = 'switch';

  /**
   * Intercepts calls to "case" and "defaultCase".
   * @var array
   */
  protected $interceptMethods = array(
    'case',
    'defaultCase',
  );
  public function __construct($dataSelector = NULL) {
    parent::__construct();
    if (isset($dataSelector)) {
      $this->settings['data:select'] = $dataSelector;
    }
  }

  /**
   * Adds a "case" statement, for use with magic call.
   */
  protected function call_case($settings = array(), $fallThrough = FALSE) {
    $this->fluentElement = $element = rules_conditional_case($settings, $fallThrough);
    $element
      ->setParent($this);
    return $this;
  }

  /**
   * Adds a "defaultCase" statement, for use with magic call.
   */
  protected function call_defaultCase() {
    $this->fluentElement = $element = rules_conditional_default_case();
    $element
      ->setParent($this);
    return $this;
  }
  public function pluginParameterInfo() {
    $parameterInfo = array(
      'data' => array(
        'type' => '*',
        'label' => t('Data to match cases against'),
        'description' => t('The data to be compared, specified by using a data selector, e.g. "node:author:name".'),
        'restriction' => 'selector',
        'allow null' => TRUE,
      ),
    );
    return $parameterInfo;
  }

  /**
   * Selects the branches to evaluate for this conditional.
   *
   * @param RulesState $state
   *   Rules state to use.
   * @return RulesConditionalElement[]
   *   An array of branches to evaluate.
   */
  protected function selectBranches(RulesState $state) {
    $branches = array();

    // Collect all cases to be evaluated.
    $fallThrough = FALSE;
    foreach ($this->children as $case) {

      /** @var $case RulesConditionalCase */
      if ($case
        ->canEvaluate($state)) {
        $branches[] = $case;
      }
    }
    return $branches;
  }
  protected function importChildren($export, $key = NULL) {
    parent::importChildren($export, 'DO');
  }
  protected function exportChildren($key = NULL) {
    return parent::exportChildren('DO');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RulesConditionalContainer::$fluentElement protected property
RulesConditionalContainer::$providesVariables protected property
RulesConditionalContainer::action public function Adds an action to the active fluent statement.
RulesConditionalContainer::delete public function Deletes the container and its children.
RulesConditionalContainer::dependencies public function
RulesConditionalContainer::destroy public function
RulesConditionalContainer::evaluate public function Evaluates the conditional statement.
RulesConditionalContainer::exportSettings protected function
RulesConditionalContainer::label public function
RulesConditionalContainer::providesVariables public function Provides intersections of variables in all branches, at least one default.
RulesConditionalContainer::resetInternalCache public function
RulesConditionalContainer::stateVariables protected function Declares only parent state variables for individual branches.
RulesConditionalContainer::variableInfoAssertions protected function Asserts no variables (since a conditional is *conditionally* evaluated).
RulesConditionalContainer::__call public function Intercepts calls to magic methods, possibly using reserved keywords.
RulesConditionalSwitch::$interceptMethods protected property Intercepts calls to "case" and "defaultCase". Overrides RulesConditionalContainer::$interceptMethods
RulesConditionalSwitch::$itemName protected property
RulesConditionalSwitch::call_case protected function Adds a "case" statement, for use with magic call.
RulesConditionalSwitch::call_defaultCase protected function Adds a "defaultCase" statement, for use with magic call.
RulesConditionalSwitch::exportChildren protected function
RulesConditionalSwitch::importChildren protected function
RulesConditionalSwitch::pluginParameterInfo public function
RulesConditionalSwitch::selectBranches protected function Selects the branches to evaluate for this conditional. Overrides RulesConditionalContainer::selectBranches
RulesConditionalSwitch::__construct public function