It looks like Rules is interfering when you have an Entity named "element". I think the name of this function should be changed since this is determined from the Entity module.

Steps to Reproduce:
1) Create an Entity named "element". (Or use https://www.drupal.org/project/element)
2) Load an element entity with Rules installed "rules_element_load"
3) Note that Entity module is trying to call "hook_ENTITY_load" and is hitting the rules module, erroring out

Since this is just a menu loader, maybe it should be prefixed with an underscore?

Thoughts? This probably won't happen too often but it would be a shame if other modules conflicted like this. Since it's not an entity in rules it probably shouldn't be calling that anyway I would think.

Workaround thanks to @davidwbarratt

function HOOK_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'element_load') {
    unset($implementations['rules']);
  }
}

Comments

davidwbarratt’s picture

Issue summary: View changes
davidwbarratt’s picture

I discovered that the reason this is happening is because the the function `rules_element_load()` followed the pattern `hook_TYPE_load`. which is being called by DrupalDefaultEntityController::attachLoad.

Since I have an entity named "element", this causes the hook to execute, which throws an error since the arguments passed are not correct.

There is an issue to remove the hook, #1792888: Remove hook_TYPE_load call from DrupalDefaultEntityController::attachLoad(), but that request appears to have been denied.

I see three possible solutions:

  1. Rename rules_element_load() to something else.
  2. Check that the arguments are valid before proceeding.
  3. Ask Entity Construction Kit (ECK) to prefix the entity name.
  4. Remove hook_TYPE_load()

Thanks!

davidwbarratt’s picture

Here's a workaround for anyone who runs into this problem:

function HOOK_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'element_load') {
    unset($implementations['rules']);
  }
}

Thanks!

Derimagia’s picture

Derimagia’s picture

Title: Fatal error: Call to a member function elementMap() on a non-object in sites/all/modules/rules/rules.module on line 1217 » Function / Entity issues with function name "rules_element_load"
Issue summary: View changes

Looks like I made a duplicate bug for this, I'm going to update it here with some more details in the main thread.

tr’s picture

Status: Active » Closed (outdated)

The Element module committed a patch about a year ago which fixes this issue for Rules and for one other module (Personalize). See https://cgit.drupalcode.org/element/commit/?id=401367f3a25d915e2c2efa9b1...
That patch is very similar to the solution proposed in the original post above.

I'm closing this issue now, because this is no longer a problem.

Because Drupal hooks require magic naming in order to identify them, and because Drupal modules have a totally flat namespace, there will always be cases where function names are misidentified as hook implementations. The best way to avoid this is to avoid generic naming. 'element' is a really bad name for an entity type, because it's almost certain to conflict with other modules. Fortunately, the Element module maintainer has added that solution to prevent known conflicts.