Skip to content

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

@argiepiano

Description

@argiepiano

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);
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions