function fusion_apply_rule_edit in Fusion Accelerator 7
Same name in this branch
- 7 fusion_apply/fusion_apply_ui.rules.inc \fusion_apply_rule_edit()
- 7 fusion_apply/fusion_apply_rules.inc \fusion_apply_rule_edit()
Same name and namespace in other branches
- 7.2 fusion_apply/fusion_apply_ui.rules.inc \fusion_apply_rule_edit()
Form builder for the rule configuration form.
Parameters
$rid: The rule ID.
See also
fusion_apply_rule_edit_submit()
1 string reference to 'fusion_apply_rule_edit'
- fusion_apply_ui_menu in fusion_apply/
fusion_apply_ui.module - Implements hook_menu().
File
- fusion_apply/
fusion_apply_ui.rules.inc, line 130 - Admin page callbacks for Fusion Apply skin rules.
Code
function fusion_apply_rule_edit($form, &$form_state, $rid = NULL) {
$form['rule'] = array(
'#weight' => -1,
);
if (isset($form_state['values'])) {
$rule = array(
'title' => $form_state['values']['title'],
'rule_type' => $form_state['values']['rule_type'],
'node_types' => $form_state['values']['types'],
'roles' => $form_state['values']['roles'],
'visibility' => $form_state['values']['visibility'],
'pages' => $form_state['values']['pages'],
);
}
elseif (isset($rid) && ($rule = fusion_apply_rule_load($rid))) {
$rule = (array) $rule;
$form['rule']['rid'] = array(
'#type' => 'value',
'#value' => $rid,
);
}
else {
$rule = array(
'title' => '',
'rule_type' => '',
'node_types' => array(),
'roles' => array(),
'visibility' => 0,
'pages' => '',
);
}
$form['rule']['title'] = array(
'#type' => 'textfield',
'#title' => t('Rule title'),
'#default_value' => $rule['title'],
'#description' => t('Descriptive title for this rule; used by administrators.'),
'#required' => TRUE,
);
$form['rule']['rule_type'] = array(
'#type' => 'hidden',
'#value' => $rule['rule_type'],
);
$form['rule']['rule_type_displayed'] = array(
'#type' => 'item',
'#title' => t('Rule type'),
'#markup' => $rule['rule_type'],
'#description' => t('Type of element the rule is applied to.'),
);
// Visibility settings.
$form['visibility_title'] = array(
'#type' => 'item',
'#title' => t('Visibility settings'),
);
$form['visibility'] = array(
'#type' => 'vertical_tabs',
'#attached' => array(
'js' => array(
drupal_get_path('module', 'fusion_apply_ui') . '/js/fusion_apply_ui.rules.js',
),
),
);
// Per-path visibility.
$form['visibility']['path'] = array(
'#type' => 'fieldset',
'#title' => t('Pages'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'visibility',
'#weight' => 0,
);
$access = user_access('use PHP for settings');
if (isset($rule['visibility']) && $rule['visibility'] == FUSION_APPLY_RULE_VISIBILITY_PHP && !$access) {
$form['visibility']['path']['visibility'] = array(
'#type' => 'value',
'#value' => FUSION_APPLY_RULE_VISIBILITY_PHP,
);
$form['visibility']['path']['pages'] = array(
'#type' => 'value',
'#value' => isset($rule['pages']) ? $rule['pages'] : '',
);
}
else {
$options = array(
FUSION_APPLY_RULE_VISIBILITY_NOTLISTED => t('All pages except those listed'),
FUSION_APPLY_RULE_VISIBILITY_LISTED => t('Only the listed pages'),
);
$description = t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array(
'%blog' => 'blog',
'%blog-wildcard' => 'blog/*',
'%front' => '<front>',
));
if (module_exists('php') && $access) {
$options += array(
FUSION_APPLY_RULE_VISIBILITY_PHP => t('Pages on which this PHP code returns <code>TRUE</code> (experts only)'),
);
$title = t('Pages or PHP code');
$description .= ' ' . t('If the PHP option is chosen, enter PHP code between %php. Note that executing incorrect PHP code can break your Drupal site.', array(
'%php' => '<?php ?>',
));
}
else {
$title = t('Pages');
}
$form['visibility']['path']['visibility'] = array(
'#type' => 'radios',
'#title' => t('Show block on specific pages'),
'#options' => $options,
'#default_value' => isset($rule['visibility']) ? $rule['visibility'] : FUSION_APPLY_RULE_VISIBILITY_NOTLISTED,
);
$form['visibility']['path']['pages'] = array(
'#type' => 'textarea',
'#title' => '<span class="element-invisible">' . $title . '</span>',
'#default_value' => isset($rule['pages']) ? $rule['pages'] : '',
'#description' => $description,
);
}
// Per-node visbility.
$form['visibility']['node_type'] = array(
'#type' => 'fieldset',
'#title' => t('Content types'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'visibility',
'#weight' => 5,
);
$form['visibility']['node_type']['types'] = array(
'#type' => 'checkboxes',
'#title' => t('Show block for specific content types'),
'#default_value' => $rule['node_types'],
'#options' => node_type_get_names(),
'#description' => t('Show this block only on pages that display content of the given type(s). If you select no types, there will be no type-specific limitation.'),
);
// Per-role visibility.
$role_options = array_map('check_plain', user_roles());
$form['visibility']['role'] = array(
'#type' => 'fieldset',
'#title' => t('Roles'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#group' => 'visibility',
'#weight' => 10,
);
$form['visibility']['role']['roles'] = array(
'#type' => 'checkboxes',
'#title' => t('Show block for specific roles'),
'#default_value' => $rule['roles'],
'#options' => $role_options,
'#description' => t('Show this rule only for the selected role(s). If you select no roles, the rule will be visible to all users.'),
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save rule'),
);
if (isset($rule['rid'])) {
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#submit' => array(
'fusion_apply_rule_delete_submit',
),
);
}
return $form;
}