class RulesContainerPluginUI in Rules 7.2
UI for Rules Container.
Hierarchy
- class \RulesPluginUI extends \FacesExtender implements RulesPluginUIInterface
- class \RulesContainerPluginUI
Expanded class hierarchy of RulesContainerPluginUI
File
- ui/
ui.core.inc, line 1007 - Contains core Rules UI functions.
View source
class RulesContainerPluginUI extends RulesPluginUI {
/**
* Generates a table for editing the contained elements.
*/
public function form(&$form, &$form_state, $options = array(), $iterator = NULL) {
parent::form($form, $form_state, $options);
$form['elements'] = array(
// Hide during creation or for embedded elements.
'#access' => empty($options['init']) && $this->element
->isRoot(),
'#tree' => TRUE,
'#theme' => 'rules_elements',
'#empty' => t('None'),
'#caption' => t('Elements'),
);
$form['elements']['#attributes']['class'][] = 'rules-container-plugin';
// Recurse over all element children or use the provided iterator.
$iterator = isset($iterator) ? $iterator : $this->element
->elements();
$root_depth = $this->element
->depth();
foreach ($iterator as $key => $child) {
$id = $child
->elementId();
// Do not render rules as container element when displayed in a rule set.
$is_container = $child instanceof RulesContainerPlugin && !$child instanceof Rule;
$form['elements'][$id] = array(
'#depth' => $child
->depth() - $root_depth - 1,
'#container' => $is_container,
);
$form['elements'][$id]['label'] = $child
->buildContent();
$form['elements'][$id]['weight'] = array(
'#type' => 'weight',
'#default_value' => $child->weight,
'#delta' => 50,
);
$form['elements'][$id]['parent_id'] = array(
'#type' => 'hidden',
// If another iterator is passed in, the child parent may not equal
// the current element. Thus ask the child for its parent.
'#default_value' => $child
->parentElement()
->elementId(),
);
$form['elements'][$id]['element_id'] = array(
'#type' => 'hidden',
'#default_value' => $id,
);
$form['elements'][$id]['operations'] = $child
->operations();
}
// Alter the submit button label.
if (!empty($options['button']) && !empty($options['init'])) {
$form['submit']['#value'] = t('Continue');
}
elseif (!empty($options['button']) && $this->element
->isRoot()) {
$form['submit']['#value'] = t('Save changes');
}
}
/**
* Applies the values of the form to the given rule configuration.
*/
public function form_extract_values($form, &$form_state) {
parent::form_extract_values($form, $form_state);
$values = RulesPluginUI::getFormStateValues($form, $form_state);
// Now apply the new hierarchy.
if (isset($values['elements'])) {
foreach ($values['elements'] as $id => $data) {
$child = $this->element
->elementMap()
->lookup($id);
$child->weight = $data['weight'];
$parent = $this->element
->elementMap()
->lookup($data['parent_id']);
$child
->setParent($parent ? $parent : $this->element);
}
$this->element
->sortChildren(TRUE);
}
}
public function operations() {
$ops = parent::operations();
$add_ops = self::addOperations();
$ops['#links'] += $add_ops['#links'];
return $ops;
}
/**
* Gets the Add-* operations for the given element.
*/
public function addOperations() {
$name = $this->element
->root()->name;
$render = array(
'#theme' => 'links__rules',
);
$render['#attributes']['class'][] = 'rules-operations-add';
$render['#attributes']['class'][] = 'action-links';
foreach (rules_fetch_data('plugin_info') as $plugin => $info) {
if (!empty($info['embeddable']) && $this->element instanceof $info['embeddable']) {
$render['#links']['add_' . $plugin] = array(
'title' => t('Add !name', array(
'!name' => $plugin,
)),
'href' => RulesPluginUI::path($name, 'add', $this->element, $plugin),
);
}
}
return $render;
}
public function buildContent() {
$content = parent::buildContent();
// Don't link the title for embedded container plugins, except for rules.
if (!$this->element
->isRoot() && !$this->element instanceof Rule) {
// $content['label']['#type'] is currently set to 'link', but in this
// case we don't want a link, we just want 'markup' text.
$content['label']['#type'] = 'markup';
$content['label']['#markup'] = check_plain($content['label']['#title']);
unset($content['label']['#title']);
}
elseif ($this->element
->isRoot()) {
$content['description']['settings'] = array(
'#theme' => 'rules_content_group',
'#weight' => -4,
'machine_name' => array(
'#markup' => t('Machine name') . ': ' . $this->element->name,
),
'weight' => array(
'#access' => $this->element instanceof RulesTriggerableInterface,
'#markup' => t('Weight') . ': ' . $this->element->weight,
),
);
if (!empty($this->element->tags)) {
$content['description']['tags'] = array(
'#theme' => 'rules_content_group',
'#caption' => t('Tags'),
'tags' => array(
'#markup' => implode(', ', array_map(function ($entry) {
return l($entry, '/admin/config/workflow/rules', array(
'query' => array(
'event' => '0',
'tag' => $entry,
),
));
}, $this->element->tags)),
),
);
}
if ($vars = $this->element
->componentVariables()) {
$content['description']['variables'] = array(
'#caption' => t('Parameter'),
'#theme' => 'rules_content_group',
);
foreach ($vars as $name => $info) {
if (!isset($info['parameter']) || $info['parameter']) {
$content['description']['variables'][$name] = array(
'#theme' => 'rules_variable_view',
'#info' => $info,
'#name' => $name,
);
}
}
}
}
return $content;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RulesContainerPluginUI:: |
public | function | Gets the Add-* operations for the given element. | |
RulesContainerPluginUI:: |
public | function |
Implements RulesPluginUIInterface. Overrides RulesPluginUI:: |
1 |
RulesContainerPluginUI:: |
public | function |
Generates a table for editing the contained elements. Overrides RulesPluginUI:: |
2 |
RulesContainerPluginUI:: |
public | function |
Applies the values of the form to the given rule configuration. Overrides RulesPluginUI:: |
3 |
RulesContainerPluginUI:: |
public | function |
Implements RulesPluginUIInterface. Overrides RulesPluginUI:: |
1 |
RulesPluginUI:: |
public static | property | The base path determines where a Rules overview UI lives. | |
RulesPluginUI:: |
protected | property | ||
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 |
Implements RulesPluginUIInterface. Overrides RulesPluginUIInterface:: |
2 |
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 | function |
Implements RulesPluginUIInterface. Overrides RulesPluginUIInterface:: |
|
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 |