Created
March 21, 2019 15:13
-
-
Save daggerhart/4ef2d3135cff4d3d7cd2f7ef4011fcc7 to your computer and use it in GitHub Desktop.
Drupal 7 Rules UI improvements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Override the rules ui component row theme function so that we can show much | |
* more information about each parameter. | |
* | |
* - Changed "30" to "200" in the truncate_utf8 function call. | |
* | |
* @ingroup themeable | |
*/ | |
function MYTHEME_rules_parameter_configuration($variables) { | |
$element = $variables['element']; | |
$content = drupal_render_children($element); | |
// Add the full content to the span's title, but don't use drupal_attributes | |
// for that as this would invoke check_plain() again. | |
$title = strip_tags($content); | |
$element['#attributes']['class'][] = 'rules-parameter-configuration'; | |
$attributes = drupal_attributes($element['#attributes']) . " title='$title'"; | |
$label_attributes['class'][] = 'rules-parameter-label'; | |
if (!empty($element['#info']['description'])) { | |
$label_attributes['title'] = $element['#info']['description']; | |
} | |
$label_attributes = drupal_attributes($label_attributes); | |
$output = "<span $label_attributes>" . check_plain($element['#info']['label']) . ': </span>'; | |
$output .= "<span $attributes>" . truncate_utf8($content, 200, TRUE, TRUE) . "</span>"; | |
return $output; | |
} | |
/** | |
* Implements hook_form_FORM_ID_alter(). | |
* | |
* Give us some useful info about a rule when working with them in the UI. | |
* | |
* @param $form | |
* @param $form_state | |
*/ | |
function MYTHEME_form_rules_admin_reaction_overview_alter(&$form, &$form_state) { | |
foreach (['active', 'inactive'] as $status) { | |
foreach ($form[$status]['#rows'] as &$row) { | |
$machine_name = str_replace('Machine name: ', '', $row[0]['data']['description']['settings']['machine_name']['#markup']); | |
if (!empty($machine_name)) { | |
$rule = rules_config_load($machine_name); | |
if ($rule instanceof RulesTriggerableInterface) { | |
$events = []; | |
foreach ($rule->events() as $event_name) { | |
$event_handler = rules_get_event_handler($event_name, $rule->getEventSettings($event_name)); | |
$summary = $event_handler->summary(); | |
/** @var array $info */ | |
$info = $event_handler->getEventInfo(); | |
if (!empty($info['group'])) { | |
$summary = "<small>({$info['group']})</small> " . $summary; | |
} | |
$events[] = $summary; | |
} | |
$row[1] = implode('<br>', $events); | |
} | |
} | |
} | |
} | |
} | |
/** | |
* Implements theme_rules_content_group(). | |
* | |
* Give us some useful info about a rule when working with them in the UI. | |
* | |
* @param $variables | |
* | |
* @return string | |
*/ | |
function MYTHEME_rules_content_group($variables) { | |
$machine_name = str_replace('Machine name: ', '', $variables['element']['machine_name']['#markup']); | |
if (!empty($machine_name)) { | |
/** @var \RulesPlugin $rule */ | |
$rule = rules_config_load($machine_name); | |
if (!empty($rule) && !empty($rule->module)) { | |
$variables['element']['module'] = [ | |
'#markup' => t('Module') . ': ' . $rule->module, | |
]; | |
ksort($variables['element']); | |
} | |
} | |
$element = $variables['element']; | |
$output = array(); | |
foreach (element_children($element) as $key) { | |
$output[] = drupal_render($element[$key]); | |
} | |
$output = array_filter($output); | |
$heading = !empty($element['#caption']) ? "<span class='rules-content-heading'>" . $element['#caption'] . ': </span>' : ''; | |
if (!empty($output)) { | |
$element['#attributes']['class'][] = 'rules-element-content-group'; | |
return '<div' . drupal_attributes($element['#attributes']) . '>' . $heading . implode('<br>', $output) . '</div>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment