Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading all entities of a type twice returns no result on second call #168

Open
argiepiano opened this issue Nov 11, 2023 · 0 comments
Open

Comments

@argiepiano
Copy link
Collaborator

argiepiano commented Nov 11, 2023

This is a known issues in the Drupal Entity API module that has not been resolved, presumably because of backward compatibility and custom modules that may have already adapted their own solutions. See these issues 1572466, 1823926 and 1273756

To reproduce

  1. Create a new entity type that uses EntityPlusController, or use the contrib module Basic Entity Plus
  2. Create some entities of that type
  3. In devel PHP window, run this twice:
dpm(entity_load_multiple('MY_TYPE', FALSE));
dpm(entity_load_multiple('MY_TYPE', FALSE));

The first output is correct (it includes all entities). The second output is an empty array.

The patch in 1273756 could be partially adapted.

Otherwise, a good workaround is to override EntityPlusController::cacheGet() as explained in 1572466, as follows:

/**
 * Implements a controller class for MyEntity.
 */
class MyEntityController extends EntityPlusController {

  /**
   * Overrides EntityPlusController::cacheGet()
   */
  protected function cacheGet($ids, $conditions = array()) {
    // Load any available entities from the internal cache.
    if ($ids === FALSE && !$conditions) {
      return $this->entityCache;
    }

    return parent::cacheGet($ids, $conditions);
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant