Problem/Motivation

Currently the rules action "Fetch entity by id" defaults the data type of the identifier to integer. However, since remote entities can use the remote id it should be possible to use text - similar to when an entity supports loading by name.

Proposed resolution

Either we duplicate the action with all the surrounding code or we use hook_rules_action_info_alter() to make some adjustments.
I'd suggest the later one as it seems to be less maintenance work in the long run.
Attached patch introduces our own "info alter" callback remote_entity_rules_action_entity_fetch_info_alter(). The code in entity_rules_rules_action_info_alter() tries to maintain possible other changes by backing up a pre-existing "info alter" callback.

After fiddling with the code it turns out duplicating the function is quite easy and that we should be able to re-use most of the callbacks from the original entity fetch (e.g. access check) while we can adjust the execution callback nicely.

Remaining tasks

Reviews needed.

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

das-peter created an issue. See original summary.

das-peter’s picture

Oh, issue with argument not given as reference. Fixed in updated patch.

joachim’s picture

Status: Needs review » Postponed (maintainer needs more info)
+++ b/remote_entity.module
@@ -482,3 +482,42 @@ function remote_entity_views_api() {
+/**
+ * Implements hook_rules_action_info_alter().
+ *
+ * Inject our own info_alter callback for the entity_fetch action to be able to
+ * set the data-type of the identifier argument to text.
+ *
+ * @see remote_entity_rules_action_entity_fetch_info_alter()
+ */
+function entity_rules_rules_action_info_alter(&$actions) {
+  if (isset($actions['entity_fetch'])) {

Can this hook go in a Rules .inc file?

das-peter’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new2.04 KB

Indeed, it works. Didn't expect that for a _alter() hook :)
Updated the patch.

das-peter’s picture

Unfortunately I figured out that placing those hooks in the rules inc file wont always work :|
It seems that under certain circumstances the hooks are called while the inc file isn't loaded.
I gave the duplication of the entity fetch action from rules itself a shot and it turns out we should be able to do it nicely. As I've duplicated the code now it seems quite maintainable :) Maybe even better than adjusting the info hooks.

So the next patch introduces a special action to load entities by remote id - and even allows to force loading from remote.

das-peter’s picture

Darn, last patch is missing some bits in the module file. Here an update one.

Status: Needs review » Needs work
das-peter’s picture

Status: Needs work » Needs review
StatusFileSize
new4.39 KB

Freakin' windows...