function RulesPluginUI::form

Implements RulesPluginUIInterface::form().

Generates the element edit form. Note: Make sure that you set RulesPluginUI::$basePath before using this method, otherwise paths, links, redirects etc. won't be correct.

Overrides RulesPluginUIInterface::form

2 calls to RulesPluginUI::form()
RulesAbstractPluginUI::form in ui/ui.core.inc
Overrides RulesPluginUI::form().
RulesContainerPluginUI::form in ui/ui.core.inc
Generates a table for editing the contained elements.
2 methods override RulesPluginUI::form()
RulesAbstractPluginUI::form in ui/ui.core.inc
Overrides RulesPluginUI::form().
RulesContainerPluginUI::form in ui/ui.core.inc
Generates a table for editing the contained elements.

File

ui/ui.core.inc, line 216

Class

RulesPluginUI
Faces UI extender for all kind of Rules plugins.

Code

public function form(&$form, &$form_state, $options = array()) {
    self::formDefaults($form, $form_state);
    $form_state += array(
        'rules_element' => $this->element,
    );
    // Add the help to the top of the form.
    $help = $this->element
        ->help();
    $form['help'] = is_array($help) ? $help : array(
        '#markup' => $help,
    );
    // We use $form_state['element_settings'] to store the settings of both
    // parameter modes. That way one can switch between the parameter modes
    // without losing the settings of those.
    $form_state += array(
        'element_settings' => $this->element->settings,
    );
    $settings = $this->element->settings + $form_state['element_settings'];
    $form['parameter'] = array(
        '#tree' => TRUE,
    );
    foreach ($this->element
        ->pluginParameterInfo() as $name => $parameter) {
        if ($parameter['type'] == 'hidden') {
            continue;
        }
        $form['parameter'][$name] = array(
            '#type' => 'fieldset',
            '#title' => check_plain($parameter['label']),
            '#description' => filter_xss(isset($parameter['description']) ? $parameter['description'] : ''),
        );
        // Init the parameter input mode.
        $form_state['parameter_mode'][$name] = !isset($form_state['parameter_mode'][$name]) ? NULL : $form_state['parameter_mode'][$name];
        $form['parameter'][$name] += $this->getParameterForm($name, $parameter, $settings, $form_state['parameter_mode'][$name]);
    }
    // Provide a form for editing the label and name of provided variables.
    $settings = $this->element->settings;
    foreach ($this->element
        ->pluginProvidesVariables() as $var_name => $var_info) {
        $form['provides'][$var_name] = array(
            '#type' => 'fieldset',
            '#title' => check_plain($var_info['label']),
            '#description' => filter_xss(isset($var_info['description']) ? $var_info['description'] : ''),
        );
        $form['provides'][$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['provides'][$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 (!empty($form['provides'])) {
        $help = '<div class="description">' . t('Adjust the names and labels of provided variables, but note that renaming of already utilized variables invalidates the existing uses.') . '</div>';
        $form['provides'] += array(
            '#tree' => TRUE,
            '#prefix' => '<h4 class="rules-form-heading">' . t('Provided variables') . '</h4>' . $help,
        );
    }
    // Add settings form, if specified.
    if (!empty($options['show settings'])) {
        $this->settingsForm($form, $form_state);
    }
    // Add submit button, if specified.
    if (!empty($options['button'])) {
        $form['submit'] = array(
            '#type' => 'submit',
            '#value' => t('Save'),
            '#weight' => 10,
        );
    }
}