You are here

class ViewsRulesLoopUI in Views Rules 7

Views loop administrative UI.

Hierarchy

Expanded class hierarchy of ViewsRulesLoopUI

1 string reference to 'ViewsRulesLoopUI'
views_rules_rules_plugin_info in ./views_rules.rules.inc
Implements hook_rules_plugin_info().

File

rules/views_rules.ui.inc, line 10
Rules UI implementation for Views Rules plugins.

View source
class ViewsRulesLoopUI extends RulesActionContainerUI {

  /**
   * @var ViewsRulesLoop
   */
  protected $element;
  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.
      $pathAddView = RulesPluginUI::path($this->element
        ->root()->name, 'add-view-loop', $this->element
        ->parentElement());
      drupal_goto($pathAddView);
    }

    // Build form with "Save" button.
    $options['init'] = FALSE;
    parent::form($form, $form_state, $options, $iterator);

    // Add row variable form.
    if ($display = $this->element
      ->getViewIterator()) {
      $settings = $this->element->settings;
      foreach ($display
        ->get_rules_variable_info() as $var_name => $var_info) {
        $form['views_row'][$var_name] = array(
          '#type' => 'fieldset',
          '#title' => check_plain($var_info['label']),
          '#description' => filter_xss(isset($var_info['description']) ? $var_info['description'] : ''),
        );
        $form['views_row'][$var_name]['label'] = array(
          '#type' => 'textfield',
          '#title' => t('Variable label'),
          '#default_value' => isset($settings[$var_name . ':label']) ? $settings[$var_name . ':label'] : $var_info['label'],
          '#required' => TRUE,
        );
        $form['views_row'][$var_name]['var'] = array(
          '#type' => 'textfield',
          '#title' => t('Variable name'),
          '#default_value' => isset($settings[$var_name . ':var']) ? $settings[$var_name . ':var'] : $var_name,
          '#description' => t('The variable name must contain only lowercase letters, numbers, and underscores and must be unique in the current scope.'),
          '#element_validate' => array(
            'rules_ui_element_machine_name_validate',
          ),
          '#required' => TRUE,
        );
      }
      if (element_children($form['views_row'])) {
        $help = '<div class="description">' . t('Adjust the names and labels of row variables (from the view) available in each iteration of the view loop, but note that renaming of already utilizied variables invalidates the existing uses.') . '</div>';
        $form['views_row'] += array(
          '#tree' => TRUE,
          '#prefix' => '<h4 class="rules-form-heading">' . t('Row variables') . '</h4>' . $help,
        );
      }
    }
  }
  public function help() {
    return t('Configure parameters for input into the view and row variables available in loop iterations.');
  }
  public function form_extract_values($form, &$form_state) {
    parent::form_extract_values($form, $form_state);
    $form_values = RulesPluginUI::getFormStateValues($form, $form_state);

    // Extract row variable settings.

    /** @var $display views_rules_iterator */
    $display = $this->element
      ->getViewIterator();
    foreach ($display
      ->get_rules_variable_info() as $var_name => $var_info) {
      $this->element->settings[$var_name . ':var'] = $form_values['views_row'][$var_name]['var'];
      $this->element->settings[$var_name . ':label'] = $form_values['views_row'][$var_name]['label'];
    }
  }
  public function form_validate($form, &$form_state) {
    parent::form_validate($form, $form_state);

    // Validate row variable names.
    $vars = $this->element
      ->availableVariables();

    /** @var $display views_rules_iterator */
    $display = $this->element
      ->getViewIterator();
    foreach ($display
      ->get_rules_variable_info() as $var_name => $var_info) {
      $name = $this->element->settings[$var_name . ':var'];
      if (isset($vars[$name])) {
        form_error($form['views_row'][$var_name]['var'], t('The variable name %name is already taken.', array(
          '%name' => $name,
        )));
      }
    }
  }
  public function operations() {
    $ops = parent::operations();
    if (module_exists('views_ui') && user_access('administer views')) {

      /** @var $view view */
      $view = $this->element
        ->getView();
      $link = array(
        'title' => t('edit view display'),
        'href' => 'admin/structure/views/view/' . $view->name . '/edit/' . $view->current_display,
      );
      array_unshift($ops['#links'], $link);
    }
    return $ops;
  }
  public function buildContent() {
    $content = parent::buildContent();

    // Build row variables.

    /** @var $display views_rules_iterator */
    $display = $this->element
      ->getViewIterator();
    $content['description']['views_row'] = array(
      '#caption' => t('Row variables'),
      '#theme' => 'rules_content_group',
    );
    foreach ($display
      ->get_rules_variable_info() as $var_name => $var_info) {
      if (isset($this->element->settings[$var_name . ':var'])) {
        $content['description']['views_row'][$var_name] = array(
          '#theme' => 'rules_variable_view',
          '#info' => array(
            'type' => $var_info['type'],
            'label' => $this->element->settings[$var_name . ':label'],
          ),
          '#name' => $this->element->settings[$var_name . ':var'],
        );
      }
    }
    return $content;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RulesContainerPluginUI::addOperations public function Gets the Add-* operations for the given element.
RulesPluginUI::$basePath public static property The base path determines where a Rules overview UI lives.
RulesPluginUI::defaultRedirect public static function Determines the default redirect target for an edited/deleted element.
RulesPluginUI::formDefaults public static function
RulesPluginUI::form_submit public function Implements RulesPluginUIInterface. Overrides RulesPluginUIInterface::form_submit
RulesPluginUI::getDataTypeClass public function Returns the name of class for the given data type.
RulesPluginUI::getFormStateValues public static function Returns the state values for $form, possibly only a part of the whole form.
RulesPluginUI::getOptions public static function
RulesPluginUI::getParameterForm protected function Actually generates the parameter form for the given data type.
RulesPluginUI::getTags public static function
RulesPluginUI::getVariableForm public function Returns the form for configuring the info of a single variable.
RulesPluginUI::overviewTable public static function Deprecated by the controllers overviewTable() method.
RulesPluginUI::path public static function Generates an operation path.
RulesPluginUI::settingsForm public function Adds the configuration settings form (label, tags, description, ...). 1
RulesPluginUI::settingsFormExtractValues public function 1
RulesPluginUI::settingsFormPermissionMatrix protected function Provides a matrix permission for the component based in the existing roles.
RulesPluginUI::settingsFormSubmit public function
RulesPluginUI::settingsFormValidate public function
RulesPluginUI::__construct public function Provide $this->element to make the code more meaningful. 1
ViewsRulesLoopUI::$element protected property Overrides RulesPluginUI::$element
ViewsRulesLoopUI::buildContent public function Implements RulesPluginUIInterface. Overrides RulesContainerPluginUI::buildContent
ViewsRulesLoopUI::form public function Implements RulesPluginUIInterface::form(). Overrides RulesActionContainerUI::form
ViewsRulesLoopUI::form_extract_values public function Applies the values of the form to the given rule configuration. Overrides RulesContainerPluginUI::form_extract_values
ViewsRulesLoopUI::form_validate public function Implements RulesPluginUIInterface. Overrides RulesPluginUI::form_validate
ViewsRulesLoopUI::help public function Implements RulesPluginUIInterface. Overrides RulesPluginUI::help
ViewsRulesLoopUI::operations public function Implements RulesPluginUIInterface. Overrides RulesContainerPluginUI::operations