class ViewsRulesLoopUI in Views Rules 7
Views loop administrative UI.
Hierarchy
- class \RulesPluginUI extends \FacesExtender implements RulesPluginUIInterface
- class \RulesContainerPluginUI
- class \RulesActionContainerUI
- class \ViewsRulesLoopUI
- class \RulesActionContainerUI
- class \RulesContainerPluginUI
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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RulesContainerPluginUI:: |
public | function | Gets the Add-* operations for the given element. | |
RulesPluginUI:: |
public static | property | The base path determines where a Rules overview UI lives. | |
RulesPluginUI:: |
public static | function | Determines the default redirect target for an edited/deleted element. | |
RulesPluginUI:: |
public static | function | ||
RulesPluginUI:: |
public | function |
Implements RulesPluginUIInterface. Overrides RulesPluginUIInterface:: |
|
RulesPluginUI:: |
public | function | Returns the name of class for the given data type. | |
RulesPluginUI:: |
public static | function | Returns the state values for $form, possibly only a part of the whole form. | |
RulesPluginUI:: |
public static | function | ||
RulesPluginUI:: |
protected | function | Actually generates the parameter form for the given data type. | |
RulesPluginUI:: |
public static | function | ||
RulesPluginUI:: |
public | function | Returns the form for configuring the info of a single variable. | |
RulesPluginUI:: |
public static | function | Deprecated by the controllers overviewTable() method. | |
RulesPluginUI:: |
public static | function | Generates an operation path. | |
RulesPluginUI:: |
public | function | Adds the configuration settings form (label, tags, description, ...). | 1 |
RulesPluginUI:: |
public | function | 1 | |
RulesPluginUI:: |
protected | function | Provides a matrix permission for the component based in the existing roles. | |
RulesPluginUI:: |
public | function | ||
RulesPluginUI:: |
public | function | ||
RulesPluginUI:: |
public | function | Provide $this->element to make the code more meaningful. | 1 |
ViewsRulesLoopUI:: |
protected | property |
Overrides RulesPluginUI:: |
|
ViewsRulesLoopUI:: |
public | function |
Implements RulesPluginUIInterface. Overrides RulesContainerPluginUI:: |
|
ViewsRulesLoopUI:: |
public | function |
Implements RulesPluginUIInterface::form(). Overrides RulesActionContainerUI:: |
|
ViewsRulesLoopUI:: |
public | function |
Applies the values of the form to the given rule configuration. Overrides RulesContainerPluginUI:: |
|
ViewsRulesLoopUI:: |
public | function |
Implements RulesPluginUIInterface. Overrides RulesPluginUI:: |
|
ViewsRulesLoopUI:: |
public | function |
Implements RulesPluginUIInterface. Overrides RulesPluginUI:: |
|
ViewsRulesLoopUI:: |
public | function |
Implements RulesPluginUIInterface. Overrides RulesContainerPluginUI:: |