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.
In message module I've defined for the metadata:
$properties['arguments'] = array(
'label' => t("Arguments"),
'type' => 'text',
'description' => t("The arguments to associate with the message."),
'getter callback' => 'entity_metadata_verbatim_get',
'setter callback' => 'entity_metadata_verbatim_set',
);
However, I'd like the data that is inputed to be transformed into an array. In D6, using rules I had this function to execute the user's input via Rules form:
function _message_rules_get_php_value($settings, &$state) {
$value = '';
if ($settings['code']) {
if (function_exists('rules_input_evaluator_php_apply')) {
// Support adding variables to the php code, if php module is present.
$value = rules_input_evaluator_php_apply($settings['code'], $settings['vars'], $state, FALSE);
}
else {
ob_start();
$value = eval($settings['code']);
ob_end_clean();
}
}
return $value;
}
The question - is there a similar way for me to process the user's input as possible PHP code? To clarify - in D6 the user could insert "simple" text in one text area, and PHP code in another.
Comments
Comment #1
fagoI'd not suggest going with PHP for message - having to use PHP is always bad. You could do a 'text' input and enable the PHP module, then it's automatically there though.
Anyway, I'd suggest allowing user to add X-arguments (similar rules allows adding variables to a rule component), however we know the supposed data-type - 'text'). Then use the _info_alter() callback to these additional arguments to the parameter of the action and rebuild the form, then Rules will render additional parameters people can configure using the data selector.
btw, could we get a 7.x branch pls? :)
Comment #2
fagoI took a stab on that -> https://github.com/fago/message/commits/DRUPAL-7--1
In my tests it worked fine. For testing I've used the following message and rule:
and the rule:
If that's ok, I'd have a look at improve the Rules related tests to cover argument creation too.
Comment #3
fagooh, I forgot my changes require the latest entity API and Rules code as I discovered some small bugs while working on it.
Comment #4
amitaibuThanks fago!
While I'm not "crazy" on the idea to add arguments keys (from UX view point it feels as duplication), the integration with entity-metadata is important enough to let it go. I've committed to github, and will sync back to Drupal after the git migration.
btw, for ones trying to import the rule from #2, make sure to install token module.
Comment #5
fagoThanks!
>btw, for ones trying to import the rule from #2, make sure to install token module.
It should not required that, as the token API is on core.
>from UX view point it feels as duplication
hm, how do you mean that? Why is it duplicated? Because the user has to enter the replacement tokens in the text message to? The problem is that we cannot really know something needs to be replaced just because there is a @foo in the text, while it will be the case usually. Maybe we could provide some JS that automatically populates the argument keys textfields with that as suggestions though.
Comment #6
amitaibu> It should not required that, as the token API is on core.
weird, It didn't allow me to import before.
> Why is it duplicated? Because the user has to enter the replacement tokens in the text message to?
Yes.
> Maybe we could provide some JS that automatically populates the argument keys textfields with that as suggestions though.
I've been thinking about it, but it might be hard to accomplish :)
Comment #8
bluegeek9 CreditAttribution: bluegeek9 as a volunteer commented