| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: rules_admin.render.inc,v 1.1.2.3 2009/08/03 16:42:25 fago Exp $ 3 4 5 /** 6 * @file Rules Admin UI 7 * Functions for rendering a rule. 8 * If a rule is viewed, it's passed to drupal_get_form so it is rendered with drupal_render(). 9 */ 10 11 /** 12 * Adds surrounding elements like headlines for conditions and actions 13 * and renders the rule 14 */ 15 function theme_rules_admin_rule_render($element) { 16 //add css 17 $path = drupal_get_path('module', 'rules_admin') .'/rules_admin.css'; 18 drupal_add_css($path, 'module', 'all', FALSE); 19 20 if (rules_admin_is_event_rule($element)) { 21 // Render event headline on event-triggered rules 22 $events = rules_get_event_sets(); 23 $event_label = $events[$element['#set']]['label']; 24 $render['event_headline'] = array('#weight' => -10, '#value' => '<h3 class="event">'. t('ON event %event', array('%event' => $event_label)) .'</h3>'); 25 } 26 else { 27 // Render rule set headline 28 $rulesets = rules_get_rule_sets(); 29 $ruleset_label = $rulesets[$element['#set']]['label']; 30 $render['event_headline'] = array('#weight' => -10, '#value' => '<h3 class="event">'. t('IN rule set %ruleset', array('%ruleset' => $ruleset_label)) .'</h3>'); 31 } 32 33 $conditions = element_children($element['#conditions']); 34 if (!empty($conditions)) { 35 $render['condition_headline'] = array('#weight' => -6, '#value' => '<h3 class="conditions">'. t('IF') .'</h3>'); 36 $render['conditions'] = $element['#conditions']; 37 $render['conditions']['#weight'] = 0; 38 39 /* render the conditions of the rule like an AND */ 40 $render['conditions'] += array('#theme' => 'rules_operation', '#label' => t('AND'), '#_root' => TRUE); 41 } 42 43 $render['actions_headline'] = array('#weight' => 10, '#value' => '<h3 class="actions">'. t('DO') .'</h3>'); 44 $render['actions'] = $element['#actions']; 45 $render['actions']['#weight'] = 20; 46 47 $add_img = theme('rules_icon', 'add') .''; 48 $link_options = array('attributes' => array('class' => 'modify'), 'query' => drupal_get_destination()); 49 $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>'); 50 $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>'); 51 52 //propagate the rule name down the tree, as the name is needed for rendering the elements 53 $render['#rule'] = $element['#name']; 54 rules_prepare_render($render); 55 56 //add a surrounding div to prevent bugs with the fieldset 57 $render['#prefix'] = '<div>'; 58 $render['#suffix'] = '</div>'; 59 60 return drupal_render($render); 61 } 62 63 /** 64 * Propagates the #rule property down the tree 65 * and set #sorted, as we have already sorted the rule. 66 */ 67 function rules_prepare_render(&$elements) { 68 foreach (element_children($elements) as $key) { 69 $elements[$key]['#rule'] = $elements['#rule']; 70 $elements[$key]['#sorted'] = TRUE; 71 rules_prepare_render($elements[$key]); 72 } 73 } 74 75 function theme_rule($element) { 76 return $element['#children']; 77 } 78 79 /** 80 * Renders a condition 81 */ 82 function theme_condition($element) { 83 $attributes = isset($element['#attributes']) ? $element['#attributes'] : array(); 84 $title = theme('rules_icon', 'condition') . check_plain(rules_get_element_label($element)); 85 $path = RULES_ADMIN_RULE_PATH .'/'. $element['#rule'] .'/edit/'. $element['#id']; 86 $options = array('attributes' => _rules_attributes_add_class($attributes, 'condition'), 'query' => drupal_get_destination(), 'html' => TRUE); 87 $link = l($title, $path, $options); 88 89 $path = RULES_ADMIN_RULE_PATH .'/'. $element['#rule'] .'/add/op/'. $element['#id']; 90 $options['attributes'] = _rules_attributes_add_class($attributes, 'condition_add'); 91 $indent_link = l(theme_rules_icon('indent', t('Indent this condition by adding a logical operation.')), $path, $options); 92 93 $print_op = $element['#negate'] ? theme('rules_logical_operation_label', 'not', t('NOT')) .' ' : ''; 94 return $print_op . $link .' '. $indent_link; 95 } 96 97 /** 98 * Renders an action 99 */ 100 function theme_action($element) { 101 $attributes = isset($element['#attributes']) ? $element['#attributes'] : array(); 102 $title = theme('rules_icon', 'action') . check_plain(rules_get_element_label($element)); 103 $path = RULES_ADMIN_RULE_PATH .'/'. $element['#rule'] .'/edit/'. $element['#id']; 104 $options = array('attributes' => _rules_attributes_add_class($attributes, 'action'), 'query' => drupal_get_destination(), 'html' => TRUE); 105 return l($title, $path, $options); 106 } 107 108 /** 109 * Themes a icon 110 */ 111 function theme_rules_icon($name, $title = NULL) { 112 $path = drupal_get_path('module', 'rules_admin') .'/icons/'. $name .'.png'; 113 return theme('image', $path, $name, $title ? $title : $name, array('class' => 'rules-icon')); 114 } 115 116 function _rules_attributes_add_class($attributes, $class) { 117 if (isset($attributes['class'])) { 118 $attributes['class'] .= ' '. $class; 119 } 120 else { 121 $attributes['class'] = $class; 122 } 123 return $attributes; 124 } 125 126 /** 127 * Themes the children of a logical operation. It put the operation in between each children. 128 * This function is invoked through the #theme property of the logical operations. 129 */ 130 function theme_rules_operation($element) { 131 if (count(element_children($element)) == 0 && !isset($element['#_root'])) { 132 //no children, so drupal_render() won't render the element itself, so we do it ourself except for the condition root (AND) 133 $element['#children'] = t('Empty'); 134 return theme('OR', $element); 135 } 136 //render the children and put the operation between them 137 $content = array(); 138 foreach (element_children($element) as $key) { 139 $content[] = drupal_render($element[$key]); 140 } 141 $print_op = theme('rules_logical_operation_label', drupal_strtolower($element['#label']), $element['#label']); 142 return implode($print_op, $content); 143 } 144 145 /** 146 * Themes the OR condition group 147 */ 148 function theme_OR($element) { 149 $attributes = isset($element['#attributes']) ? $element['#attributes'] : array(); 150 $element['#attributes'] = _rules_attributes_add_class($attributes, 'rules_'. $element['#type']); 151 $element['#collapsible'] = FALSE; 152 153 $print_op = $element['#negate'] ? t('NOT') .' ' : ''; 154 $element['#title'] = t("!not%label group", array('!not' => $print_op, '%label' => $element['#label'])); 155 $element['#children'] .= '<p class="logical-op-add">'. theme('rules_icon', 'add') . l(t('Add another condition to this group'), RULES_ADMIN_RULE_PATH .'/'. $element['#rule'] .'/add/condition/'. $element['#id']) .'</p>'; 156 $element['#children'] .= '<p class="logical-op-edit">'. theme('rules_icon', 'edit') . l(t('Edit this condition group'), RULES_ADMIN_RULE_PATH .'/'. $element['#rule'] .'/edit/'. $element['#id']) .'</p>'; 157 return theme('fieldset', $element); 158 } 159 160 /** 161 * Themes the AND condition group 162 */ 163 function theme_AND($element) { 164 return theme('OR', $element); 165 } 166 167 /** 168 * Themes the operation label 169 */ 170 function theme_rules_logical_operation_label($op, $label) { 171 return "<div class='logical-op-$op'>$label</div>"; 172 } 173
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |