Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I find calculate a value very hard to read in the GUI.
Old GUI: Calculate a value
New GUI: result = [my_var] + 1
Changing data.eval.inc rules_action_data_calc_info_alter
helps:
function rules_action_data_calc_info_alter(&$element_info, RulesPlugin $element) {
if ($info = $element->getArgumentInfo('input_1')) {
// Only allow durations as offset for date values.
if ($info['type'] == 'date') {
$element_info['parameter']['input_2']['type'] = 'duration';
}
// Specify the data type of the result.
$element_info['provides']['result']['type'] = $info['type'];
if ($info['type'] == 'integer' && ($info2 = $element->getArgumentInfo('input_2')) && $info2['type'] == 'decimal') {
$element_info['provides']['result']['type'] = 'decimal';
}
// A division with two integers results in a decimal.
elseif (isset($element->settings['op']) && $element->settings['op'] == '/') {
$element_info['provides']['result']['type'] = 'decimal';
}
}
// ---- code changes follow: ----
$element_info['label'] = '';
$element_info['label'] .= $element->settings['result:var'];
$element_info['label'] .= ' = ';
if (isset($element->settings['input_1:select']))
$element_info['label'] .= "[{$element->settings['input_1:select']}]";
$element_info['label'] .= ' ';
$element_info['label'] .= $element->settings['op'];
$element_info['label'] .= ' ';
$element_info['label'] .= $element->settings['input_2'];
}
I'm sure I've missed loads of bugs. But as a proof of concept, this reads much easier in the GUI
Comments
Comment #1
ITWest-jg CreditAttribution: ITWest-jg commentedComment #2
ITWest-jg CreditAttribution: ITWest-jg commentedComment #3
TR CreditAttribution: TR commentedPlease make a proper patch and post it here so we can review and discuss your changes.
Comment #4
TR CreditAttribution: TR commented