function RulesPluginUI::settingsForm
Adds the configuration settings form (label, tags, description, ...).
2 calls to RulesPluginUI::settingsForm()
- RulesPluginUI::form in ui/
ui.core.inc - Implements RulesPluginUIInterface::form().
- RulesReactionRuleUI::settingsForm in ui/
ui.plugins.inc - Adds the configuration settings form (label, tags, description, ..).
1 method overrides RulesPluginUI::settingsForm()
- RulesReactionRuleUI::settingsForm in ui/
ui.plugins.inc - Adds the configuration settings form (label, tags, description, ..).
File
-
ui/
ui.core.inc, line 424
Class
- RulesPluginUI
- Faces UI extender for all kind of Rules plugins.
Code
public function settingsForm(&$form, &$form_state) {
$form_values = RulesPluginUI::getFormStateValues($form, $form_state);
// Add the settings in a separate fieldset below.
$form['settings'] = array(
'#type' => 'fieldset',
'#title' => t('Settings'),
'#collapsible' => TRUE,
'#collapsed' => empty($form_values['settings']['vars']['more']),
'#weight' => 5,
'#tree' => TRUE,
);
$form['settings']['label'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#default_value' => $this->element
->label(),
'#required' => TRUE,
'#weight' => -5,
);
// @todo For Drupal 8 use "owner" for generating machine names and
// module only for the modules providing default configurations.
if (!empty($this->element->module) && !empty($this->element->name) && $this->element->module == 'rules' && strpos($this->element->name, 'rules_') === 0) {
// Remove the Rules module prefix from the machine name.
$machine_name = substr($this->element->name, strlen($this->element->module) + 1);
}
else {
$machine_name = $this->element->name;
}
$form['settings']['name'] = array(
'#type' => 'machine_name',
'#default_value' => isset($machine_name) ? $machine_name : '',
// The string 'rules_' is pre-pended to machine names, so the
// maxlength must be less than the field length of 64 characters.
'#maxlength' => 58,
'#disabled' => entity_has_status('rules_config', $this->element, ENTITY_IN_CODE) && !(isset($form_state['op']) && $form_state['op'] == 'clone'),
'#machine_name' => array(
'exists' => 'rules_config_load',
'source' => array(
'settings',
'label',
),
),
'#required' => TRUE,
'#description' => t('The machine-readable name of this configuration is used by rules internally to identify the configuration. This name must contain only lowercase letters, numbers, and underscores and must be unique.'),
);
$form['settings']['tags'] = array(
'#type' => 'textfield',
'#title' => t('Tags'),
'#default_value' => isset($this->element->tags) ? drupal_implode_tags($this->element->tags) : '',
'#autocomplete_path' => 'admin/config/workflow/rules/autocomplete_tags',
'#description' => t('Tags associated with this configuration, used for filtering in the admin interface. Separate multiple tags with commas.'),
);
// Show a form for editing variables for components.
if (($plugin_info = $this->element
->pluginInfo()) && !empty($plugin_info['component'])) {
if ($this->element
->hasStatus(ENTITY_IN_CODE)) {
$description = t('The variables used by the component. They can not be edited for configurations that are provided in code.');
}
else {
$description = t('Variables are normally input <em>parameters</em> for the component – data that should be available for the component to act on. Additionally, action components may <em>provide</em> variables back to the caller. Each variable must have a specified data type, a label and a unique machine readable name containing only lowercase alphanumeric characters and underscores. See <a href="@url">the online documentation</a> for more information about variables.', array(
'@url' => rules_external_help('variables'),
));
}
$form['settings']['vars'] = array(
'#prefix' => '<div id="rules-component-variables">',
'#suffix' => '</div>',
'#tree' => TRUE,
'#element_validate' => array(
'rules_ui_element_variable_form_validate',
),
'#theme' => 'rules_ui_variable_form',
'#title' => t('Variables'),
'#description' => $description,
// Variables can not be edited on configurations in code.
'#disabled' => $this->element
->hasStatus(ENTITY_IN_CODE),
);
$weight = 0;
$provides = $this->element
->providesVariables();
foreach ($this->element
->componentVariables() as $name => $var_info) {
$form['settings']['vars']['items'][$name] = array(
'weight' => array(
'#default_value' => $weight++,
),
) + RulesPluginUI::getVariableForm($name, $var_info, isset($provides[$name]));
}
// Add one empty row in case user wants to add an additional variable.
$form['settings']['vars']['items'][] = array(
'weight' => array(
'#default_value' => $weight++,
),
) + RulesPluginUI::getVariableForm();
// Submit button will cause a form rebuild using the currently-entered
// values. If a variable has been added, a new empty row will also appear.
$form['settings']['vars']['more'] = array(
'#type' => 'submit',
'#value' => t('Add more'),
'#ajax' => rules_ui_form_default_ajax('none'),
'#limit_validation_errors' => array(
array(
'vars',
),
),
'#submit' => array(
'rules_form_submit_rebuild',
),
);
if (!empty($this->element->id)) {
// Display a setting to manage access.
$form['settings']['access'] = array(
'#weight' => 50,
);
$plugin_type = $this->element instanceof RulesActionInterface ? t('action') : t('condition');
$form['settings']['access']['access_exposed'] = array(
'#type' => 'checkbox',
'#title' => t('Configure access for using this component with a permission.'),
'#default_value' => !empty($this->element->access_exposed),
'#description' => t('By default, the @plugin-type for using this component may be only used by users that have access to configure the component. If checked, access is determined by a permission instead.', array(
'@plugin-type' => $plugin_type,
)),
);
$form['settings']['access']['permissions'] = array(
'#type' => 'container',
'#states' => array(
'visible' => array(
':input[name="settings[access][access_exposed]"]' => array(
'checked' => TRUE,
),
),
),
);
$form['settings']['access']['permissions']['matrix'] = $this->settingsFormPermissionMatrix();
}
}
// @todo Attach field form thus description.
}