function theme_rules_admin_rule_render in Rules 6
Adds surrounding elements like headlines for conditions and actions and renders the rule
File
- rules_admin/
rules_admin.render.inc, line 14 - Rules Admin UI Functions for rendering a rule. If a rule is viewed, it's passed to drupal_get_form so it is rendered with drupal_render().
Code
function theme_rules_admin_rule_render($element) {
//add css
$path = drupal_get_path('module', 'rules_admin') . '/rules_admin.css';
drupal_add_css($path, 'module', 'all', FALSE);
if (rules_admin_is_event_rule($element)) {
// Render event headline on event-triggered rules
$events = rules_get_event_sets();
$event_label = $events[$element['#set']]['label'];
$render['event_headline'] = array(
'#weight' => -10,
'#value' => '<h3 class="event">' . t('ON event %event', array(
'%event' => $event_label,
)) . '</h3>',
);
}
else {
// Render rule set headline
$rulesets = rules_get_rule_sets();
$ruleset_label = $rulesets[$element['#set']]['label'];
$render['event_headline'] = array(
'#weight' => -10,
'#value' => '<h3 class="event">' . t('IN rule set %ruleset', array(
'%ruleset' => $ruleset_label,
)) . '</h3>',
);
}
$conditions = element_children($element['#conditions']);
if (!empty($conditions)) {
$render['condition_headline'] = array(
'#weight' => -6,
'#value' => '<h3 class="conditions">' . t('IF') . '</h3>',
);
$render['conditions'] = $element['#conditions'];
$render['conditions']['#weight'] = 0;
/* render the conditions of the rule like an AND */
$render['conditions'] += array(
'#theme' => 'rules_operation',
'#label' => t('AND'),
'#_root' => TRUE,
);
}
$render['actions_headline'] = array(
'#weight' => 10,
'#value' => '<h3 class="actions">' . t('DO') . '</h3>',
);
$render['actions'] = $element['#actions'];
$render['actions']['#weight'] = 20;
$add_img = theme('rules_icon', 'add') . '';
$link_options = array(
'attributes' => array(
'class' => 'modify',
),
'query' => drupal_get_destination(),
);
$render['condition_add'] = array(
'#weight' => 5,
'#value' => $add_img . l(t('Add a condition'), RULES_ADMIN_RULE_PATH . '/' . $element['#name'] . '/add/condition/1', $link_options),
'#prefix' => '<p>',
'#suffix' => '</p>',
);
$render['action_add'] = array(
'#weight' => 100,
'#value' => $add_img . l(t('Add an action'), RULES_ADMIN_RULE_PATH . '/' . $element['#name'] . '/add/action/' . $element['#actions']['#id'], $link_options),
'#prefix' => '<p>',
'#suffix' => '</p>',
);
//propagate the rule name down the tree, as the name is needed for rendering the elements
$render['#rule'] = $element['#name'];
rules_prepare_render($render);
//add a surrounding div to prevent bugs with the fieldset
$render['#prefix'] = '<div>';
$render['#suffix'] = '</div>';
return drupal_render($render);
}