You are here

class RulesConditionalPredicateUI in Conditional Rules 8

Same name and namespace in other branches
  1. 7 includes/rules_conditional.ui.inc \RulesConditionalPredicateUI

UI for configuring the predicate in a conditional branch.

Hierarchy

Expanded class hierarchy of RulesConditionalPredicateUI

2 string references to 'RulesConditionalPredicateUI'
rules_conditional_rules_plugin_info in ./rules_conditional.rules.inc
Implements hook_rules_plugin_info().
rules_conditional_test_rules_plugin_info in tests/rules_conditional_test.module
Implements hook_rules_plugin_info().

File

includes/rules_conditional.ui.inc, line 61
Plugin UI implementation.

View source
class RulesConditionalPredicateUI extends RulesContainerPluginUI {

  /**
   * @var RulesPlugin
   */
  protected $predicate;
  public function __construct(FacesExtendable $object) {
    parent::__construct($object);
    if (!$this->element instanceof RulesConditionalPredicateElement) {
      return;
    }
    $this->predicate = $this
      ->property('predicate');
  }

  /**
   * Delegates the form to the predicate.
   */
  public function form(&$form, &$form_state, $options = array(), $iterator = NULL) {
    $baseCount = count(explode('/', RulesPluginUI::$basePath));
    $op = arg($baseCount + 2);
    if ($op == 'add') {

      // Redirect to extended path.
      $pathAddPredicate = RulesPluginUI::path($this->element
        ->root()->name, 'add-predicate', $this->element
        ->parentElement(), $this->element
        ->plugin());
      drupal_goto($pathAddPredicate);
    }
    if (isset($this->predicate)) {

      // Build form for predicate.
      $form_state['rules_element'] = $this->predicate;
      $this->predicate
        ->form($form, $form_state, $options);
      $heading = '<h4 class="rules-form-heading">';
      $heading .= t('Condition');
      $heading .= '</h4>';
      $form['parameter']['#prefix'] = $heading;
    }
  }

  /**
   * Delegates the form validator to the predicate.
   */
  public function form_validate($form, &$form_state) {
    if (isset($this->predicate)) {

      // Validate form for predicate.
      $form_state['rules_element'] = $this->predicate;
      $this->predicate
        ->form_validate($form, $form_state);
    }
  }

  /**
   * Delegates the form submit handler to the predicate.
   */
  public function form_submit($form, &$form_state) {
    if (isset($this->predicate)) {

      // Handle form submission for predicate.
      $form_state['rules_element'] = $this->predicate;
      $this->predicate
        ->form_submit($form, $form_state);
    }
  }
  public function buildContent() {
    $content = NULL;
    if (isset($this->predicate)) {

      // Build default content.
      $content = parent::buildContent();

      // Build parameter description from predicate.
      $predicateContent = $this->predicate
        ->buildContent();
      if (isset($predicateContent['description']['parameter'])) {
        $content['description']['parameter'] = $predicateContent['description']['parameter'];
      }
    }
    return $content;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RulesConditionalPredicateUI::$predicate protected property
RulesConditionalPredicateUI::buildContent public function
RulesConditionalPredicateUI::form public function Delegates the form to the predicate. 1
RulesConditionalPredicateUI::form_submit public function Delegates the form submit handler to the predicate.
RulesConditionalPredicateUI::form_validate public function Delegates the form validator to the predicate.
RulesConditionalPredicateUI::__construct public function