class RulesContainerPluginUI

UI for Rules Container.

Hierarchy

Expanded class hierarchy of RulesContainerPluginUI

File

ui/ui.core.inc, line 1007

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

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
RulesContainerPluginUI::addOperations public function Gets the Add-* operations for the given element.
RulesContainerPluginUI::buildContent public function Implements RulesPluginUIInterface. Overrides RulesPluginUI::buildContent 1
RulesContainerPluginUI::form public function Generates a table for editing the contained elements. Overrides RulesPluginUI::form 2
RulesContainerPluginUI::form_extract_values public function Applies the values of the form to the given rule configuration. Overrides RulesPluginUI::form_extract_values 3
RulesContainerPluginUI::operations public function Implements RulesPluginUIInterface. Overrides RulesPluginUI::operations 1
RulesPluginUI::$basePath public static property The base path determines where a Rules overview UI lives.
RulesPluginUI::$element protected property
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::form_validate public function Implements RulesPluginUIInterface. Overrides RulesPluginUIInterface::form_validate 2
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::help public function Implements RulesPluginUIInterface. Overrides RulesPluginUIInterface::help
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