class MultifieldEntityController in Multifield 7
Same name and namespace in other branches
- 7.2 MultifieldEntityController.php \MultifieldEntityController
Hierarchy
- class \DrupalDefaultEntityController implements DrupalEntityControllerInterface
- class \MultifieldEntityController
Expanded class hierarchy of MultifieldEntityController
1 string reference to 'MultifieldEntityController'
- multifield_entity_info in ./
multifield.module - Implements hook_entity_info().
File
- ./
MultifieldEntityController.php, line 3
View source
class MultifieldEntityController extends DrupalDefaultEntityController {
public function load($ids = array(), $conditions = array()) {
if (!empty($conditions)) {
throw new InvalidArgumentException('MultifieldEntityController does not support entity_load() using conditions.');
}
$entities = array();
// Create a new variable which is either a prepared version of the $ids
// array for later comparison with the entity cache, or FALSE if no $ids
// were passed. The $ids array is reduced as items are loaded from cache,
// and we need to know if it's empty for this reason to avoid querying the
// database when all requested entities are loaded from cache.
$passed_ids = !empty($ids) ? array_flip($ids) : FALSE;
// Try to load entities from the static cache, if the entity type supports
// static caching.
if ($this->cache) {
$entities += $this
->cacheGet($ids, $conditions);
// If any entities were loaded, remove them from the ids still to load.
if ($passed_ids) {
$ids = array_keys(array_diff_key($passed_ids, $entities));
}
}
// Load any remaining entities from the database. This is the case if $ids
// is set to FALSE (so we load all entities), if there are any ids left to
// load, if loading a revision, or if $conditions was passed without $ids.
if ($ids === FALSE || $ids) {
$entities += $this
->queryLoad($ids);
}
return $entities;
}
protected function queryLoad($ids) {
$multifields = multifield_get_fields();
foreach (array_keys($multifields) as $field_name) {
$query = new EntityFieldQuery();
if ($ids) {
$query
->fieldCondition($field_name, 'id', $ids, 'IN');
}
else {
$query
->fieldCondition($field_name, 'id', 0, '>');
}
if ($results = $query
->execute()) {
$pseudo_entities = array();
$field = field_info_field($field_name);
foreach ($results as $entity_type => $entities) {
// Simply doing an entity load on the entities with multifield values
// will cause the cacheSet() from multifield_field_load() to get
// invoked.
$entities = entity_load($entity_type, array_keys($entities));
foreach ($entities as $entity) {
if ($items = field_get_items($entity_type, $entity, $field_name)) {
foreach ($items as $item) {
$pseudo_entities[$item['id']] = _multifield_field_item_to_entity($field['type'], $item);
}
}
}
}
$this
->cacheSet($pseudo_entities);
}
}
return array_intersect_key($this->entityCache, drupal_map_assoc($ids, $ids));
}
public function cacheSet($entities) {
$this->entityCache += $entities;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalDefaultEntityController:: |
protected | property | Whether this entity type should use the static cache. | |
DrupalDefaultEntityController:: |
protected | property | Static cache of entities, keyed by entity ID. | |
DrupalDefaultEntityController:: |
protected | property | Array of information about the entity. | |
DrupalDefaultEntityController:: |
protected | property | Entity type for this controller instance. | |
DrupalDefaultEntityController:: |
protected | property | Additional arguments to pass to hook_TYPE_load(). | |
DrupalDefaultEntityController:: |
protected | property | Name of the entity's ID field in the entity database table. | |
DrupalDefaultEntityController:: |
protected | property | Name of entity's revision database table field, if it supports revisions. | |
DrupalDefaultEntityController:: |
protected | property | The table that stores revisions, if the entity supports revisions. | |
DrupalDefaultEntityController:: |
protected | function | Attaches data to entities upon loading. | 4 |
DrupalDefaultEntityController:: |
protected | function | Builds the query to load the entity. | 4 |
DrupalDefaultEntityController:: |
protected | function | Gets entities from the static cache. | 1 |
DrupalDefaultEntityController:: |
protected | function | Ensures integer entity IDs are valid. | |
DrupalDefaultEntityController:: |
protected | function | Callback for array_filter that removes non-integer IDs. | |
DrupalDefaultEntityController:: |
public | function |
Implements DrupalEntityControllerInterface::resetCache(). Overrides DrupalEntityControllerInterface:: |
|
DrupalDefaultEntityController:: |
public | function | Constructor: sets basic variables. | |
MultifieldEntityController:: |
public | function |
Stores entities in the static entity cache. Overrides DrupalDefaultEntityController:: |
|
MultifieldEntityController:: |
public | function |
Implements DrupalEntityControllerInterface::load(). Overrides DrupalDefaultEntityController:: |
|
MultifieldEntityController:: |
protected | function |