123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981 |
- <?php
- interface EntityAPIControllerInterface extends DrupalEntityControllerInterface {
-
- public function delete($ids);
-
- public function invoke($hook, $entity);
-
- public function save($entity);
-
- public function create(array $values = array());
-
- public function export($entity, $prefix = '');
-
- public function import($export);
-
- public function buildContent($entity, $view_mode = 'full', $langcode = NULL);
-
- public function view($entities, $view_mode = 'full', $langcode = NULL, $page = NULL);
- }
- interface EntityAPIControllerRevisionableInterface extends EntityAPIControllerInterface {
-
- public function deleteRevision($revision_id);
- }
- class EntityAPIController extends DrupalDefaultEntityController implements EntityAPIControllerRevisionableInterface {
- protected $cacheComplete = FALSE;
- protected $bundleKey;
- protected $defaultRevisionKey;
-
- public function __construct($entityType) {
- parent::__construct($entityType);
-
- if (isset($this->entityInfo['bundle of'])) {
- $info = entity_get_info($this->entityInfo['bundle of']);
- $this->bundleKey = $info['bundle keys']['bundle'];
- }
- $this->defaultRevisionKey = !empty($this->entityInfo['entity keys']['default revision']) ? $this->entityInfo['entity keys']['default revision'] : 'default_revision';
- }
-
- protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
- $query = parent::buildQuery($ids, $conditions, $revision_id);
- if ($this->revisionKey) {
-
-
- $query->addExpression('CASE WHEN base.' . $this->revisionKey . ' = revision.' . $this->revisionKey . ' THEN 1 ELSE 0 END', $this->defaultRevisionKey);
- }
- return $query;
- }
-
- public function query($ids, $conditions, $revision_id = FALSE) {
-
- $query = $this->buildQuery($ids, $conditions, $revision_id);
- $result = $query->execute();
- if (!empty($this->entityInfo['entity class'])) {
- $result->setFetchMode(PDO::FETCH_CLASS, $this->entityInfo['entity class'], array(array(), $this->entityType));
- }
- return $result;
- }
-
- public function load($ids = array(), $conditions = array()) {
- $entities = array();
-
-
- if ($this->revisionKey && isset($conditions[$this->revisionKey])) {
- $revision_id = $conditions[$this->revisionKey];
- unset($conditions[$this->revisionKey]);
- }
- else {
- $revision_id = FALSE;
- }
-
-
-
-
-
- $passed_ids = !empty($ids) ? array_flip($ids) : FALSE;
-
- if ($this->cache && !$revision_id) {
- $entities = $this->cacheGet($ids, $conditions);
-
- if ($passed_ids) {
- $ids = array_keys(array_diff_key($passed_ids, $entities));
- }
- }
-
- if (!empty($this->entityInfo['entity cache']) && !$revision_id && $ids && !$conditions) {
- $cached_entities = EntityCacheControllerHelper::entityCacheGet($this, $ids, $conditions);
-
- $ids = array_diff($ids, array_keys($cached_entities));
- $entities += $cached_entities;
-
-
- if ($this->cache && !empty($cached_entities) && !$revision_id) {
- $this->cacheSet($cached_entities);
- }
- }
-
-
-
- if (!($this->cacheComplete && $ids === FALSE && !$conditions) && ($ids === FALSE || $ids || $revision_id)) {
- $queried_entities = array();
- foreach ($this->query($ids, $conditions, $revision_id) as $record) {
-
- if (isset($entities[$record->{$this->idKey}])) {
- continue;
- }
-
- if (!empty($this->entityInfo['base table'])) {
- $schema = drupal_get_schema($this->entityInfo['base table']);
- foreach ($schema['fields'] as $field => $info) {
- if (!empty($info['serialize']) && isset($record->$field)) {
- $record->$field = unserialize($record->$field);
-
- if (!empty($info['merge']) && is_array($record->$field)) {
- foreach ($record->$field as $key => $value) {
- $record->$key = $value;
- }
- unset($record->$field);
- }
- }
- }
- }
- $queried_entities[$record->{$this->idKey}] = $record;
- }
- }
-
-
-
- if (!empty($queried_entities)) {
- $this->attachLoad($queried_entities, $revision_id);
- $entities += $queried_entities;
- }
-
-
- if (!empty($this->entityInfo['entity cache']) && !empty($queried_entities) && !$revision_id) {
- EntityCacheControllerHelper::entityCacheSet($this, $queried_entities);
- }
- if ($this->cache) {
-
- if (!empty($queried_entities) && !$revision_id) {
- $this->cacheSet($queried_entities);
-
- if (!$conditions && $ids === FALSE) {
- $this->cacheComplete = TRUE;
- }
- }
- }
-
-
- if ($passed_ids && $passed_ids = array_intersect_key($passed_ids, $entities)) {
- foreach ($passed_ids as $id => $value) {
- $passed_ids[$id] = $entities[$id];
- }
- $entities = $passed_ids;
- }
- return $entities;
- }
-
- public function resetCache(array $ids = NULL) {
- $this->cacheComplete = FALSE;
- parent::resetCache($ids);
-
- if (!empty($this->entityInfo['entity cache'])) {
- EntityCacheControllerHelper::resetEntityCache($this, $ids);
- }
- }
-
- public function invoke($hook, $entity) {
-
-
-
-
- $field_attach_hook = ($hook == 'revision_delete' ? 'delete_revision' : $hook);
- if (!empty($this->entityInfo['fieldable']) && function_exists($function = 'field_attach_' . $field_attach_hook)) {
- $function($this->entityType, $entity);
- }
- if (!empty($this->entityInfo['bundle of']) && entity_type_is_fieldable($this->entityInfo['bundle of'])) {
- $type = $this->entityInfo['bundle of'];
-
- if ($hook == 'insert') {
- field_attach_create_bundle($type, $entity->{$this->bundleKey});
- }
- elseif ($hook == 'delete') {
- field_attach_delete_bundle($type, $entity->{$this->bundleKey});
- }
- elseif ($hook == 'update' && $entity->original->{$this->bundleKey} != $entity->{$this->bundleKey}) {
- field_attach_rename_bundle($type, $entity->original->{$this->bundleKey}, $entity->{$this->bundleKey});
- }
- }
-
- module_invoke_all($this->entityType . '_' . $hook, $entity);
-
- if ($hook == 'presave' || $hook == 'insert' || $hook == 'update' || $hook == 'delete') {
- module_invoke_all('entity_' . $hook, $entity, $this->entityType);
- }
-
- if (module_exists('rules')) {
- rules_invoke_event($this->entityType . '_' . $hook, $entity);
- }
- }
-
- public function delete($ids, DatabaseTransaction $transaction = NULL) {
- $entities = $ids ? $this->load($ids) : FALSE;
- if (!$entities) {
-
- return;
- }
- $transaction = isset($transaction) ? $transaction : db_transaction();
- try {
- $ids = array_keys($entities);
- db_delete($this->entityInfo['base table'])
- ->condition($this->idKey, $ids, 'IN')
- ->execute();
- if (isset($this->revisionTable)) {
- db_delete($this->revisionTable)
- ->condition($this->idKey, $ids, 'IN')
- ->execute();
- }
-
- $this->resetCache($ids);
- foreach ($entities as $id => $entity) {
- $this->invoke('delete', $entity);
- }
-
- db_ignore_slave();
- }
- catch (Exception $e) {
- $transaction->rollback();
- watchdog_exception($this->entityType, $e);
- throw $e;
- }
- }
-
- public function deleteRevision($revision_id) {
- if ($entity_revision = entity_revision_load($this->entityType, $revision_id)) {
-
- if (entity_revision_is_default($this->entityType, $entity_revision)) {
- return FALSE;
- }
- db_delete($this->revisionTable)
- ->condition($this->revisionKey, $revision_id)
- ->execute();
- $this->invoke('revision_delete', $entity_revision);
- return TRUE;
- }
- return FALSE;
- }
-
- public function save($entity, DatabaseTransaction $transaction = NULL) {
- $transaction = isset($transaction) ? $transaction : db_transaction();
- try {
-
- if (!empty($entity->{$this->idKey}) && !isset($entity->original)) {
-
-
- $entity->original = entity_load_unchanged($this->entityType, $entity->{$this->idKey});
- }
- $entity->is_new = !empty($entity->is_new) || empty($entity->{$this->idKey});
- $this->invoke('presave', $entity);
- if ($entity->is_new) {
- $return = drupal_write_record($this->entityInfo['base table'], $entity);
- if ($this->revisionKey) {
- $this->saveRevision($entity);
- }
- $this->invoke('insert', $entity);
- }
- else {
-
-
- if (!$this->revisionKey || !empty($entity->{$this->defaultRevisionKey})) {
- $return = drupal_write_record($this->entityInfo['base table'], $entity, $this->idKey);
- }
- if ($this->revisionKey) {
- $return = $this->saveRevision($entity);
- }
- $this->resetCache(array($entity->{$this->idKey}));
- $this->invoke('update', $entity);
-
-
-
- if ($this->revisionKey && !$entity->{$this->defaultRevisionKey} && !empty($this->entityInfo['fieldable'])) {
- field_attach_update($this->entityType, $entity->original);
- }
- }
-
- db_ignore_slave();
- unset($entity->is_new);
- unset($entity->is_new_revision);
- unset($entity->original);
- return $return;
- }
- catch (Exception $e) {
- $transaction->rollback();
- watchdog_exception($this->entityType, $e);
- throw $e;
- }
- }
-
- protected function saveRevision($entity) {
-
-
- $record = (array) $entity;
-
-
-
- $entity->is_new_revision = !empty($entity->is_new_revision) || !empty($entity->revision) || $entity->is_new;
- $entity->revision = &$entity->is_new_revision;
- $entity->{$this->defaultRevisionKey} = !empty($entity->{$this->defaultRevisionKey}) || $entity->is_new;
-
-
- if ($entity->is_new_revision && isset($record[$this->revisionKey])) {
- $record[$this->revisionKey] = NULL;
- }
- if ($entity->is_new_revision) {
- drupal_write_record($this->revisionTable, $record);
- $update_default_revision = $entity->{$this->defaultRevisionKey};
- }
- else {
- drupal_write_record($this->revisionTable, $record, $this->revisionKey);
-
-
- $update_default_revision = $entity->{$this->defaultRevisionKey} && $entity->{$this->revisionKey} != $entity->original->{$this->revisionKey};
- }
-
- $entity->{$this->revisionKey} = $record[$this->revisionKey];
-
- if ($update_default_revision) {
- db_update($this->entityInfo['base table'])
- ->fields(array($this->revisionKey => $record[$this->revisionKey]))
- ->condition($this->idKey, $entity->{$this->idKey})
- ->execute();
- }
- return $entity->is_new_revision ? SAVED_NEW : SAVED_UPDATED;
- }
-
- public function create(array $values = array()) {
-
- $values += array('is_new' => TRUE);
- if (isset($this->entityInfo['entity class']) && $class = $this->entityInfo['entity class']) {
- return new $class($values, $this->entityType);
- }
- return (object) $values;
- }
-
- public function export($entity, $prefix = '') {
- $vars = get_object_vars($entity);
- unset($vars['is_new']);
- return entity_var_json_export($vars, $prefix);
- }
-
- public function import($export) {
- $vars = drupal_json_decode($export);
- if (is_array($vars)) {
- return $this->create($vars);
- }
- return FALSE;
- }
-
- public function buildContent($entity, $view_mode = 'full', $langcode = NULL, $content = array()) {
-
- $entity->content = $content;
- $langcode = isset($langcode) ? $langcode : $GLOBALS['language_content']->language;
-
- $context = array(
- 'entity_type' => $this->entityType,
- 'entity' => $entity,
- 'langcode' => $langcode,
- );
- drupal_alter('entity_view_mode', $view_mode, $context);
-
- $entity->content += array('#view_mode' => $view_mode);
-
- if ($extra_field_controller = entity_get_extra_fields_controller($this->entityType)) {
- $wrapper = entity_metadata_wrapper($this->entityType, $entity);
- $extra = $extra_field_controller->fieldExtraFields();
- $type_extra = &$extra[$this->entityType][$this->entityType]['display'];
- $bundle_extra = &$extra[$this->entityType][$wrapper->getBundle()]['display'];
- foreach ($wrapper as $name => $property) {
- if (isset($type_extra[$name]) || isset($bundle_extra[$name])) {
- $this->renderEntityProperty($wrapper, $name, $property, $view_mode, $langcode, $entity->content);
- }
- }
- }
-
- if (!empty($this->entityInfo['fieldable'])) {
-
-
- $key = isset($entity->{$this->idKey}) ? $entity->{$this->idKey} : NULL;
- field_attach_prepare_view($this->entityType, array($key => $entity), $view_mode);
- $entity->content += field_attach_view($this->entityType, $entity, $view_mode, $langcode);
- }
-
- if (module_exists('rules')) {
- rules_invoke_all($this->entityType . '_view', $entity, $view_mode, $langcode);
- }
- else {
- module_invoke_all($this->entityType . '_view', $entity, $view_mode, $langcode);
- }
- module_invoke_all('entity_view', $entity, $this->entityType, $view_mode, $langcode);
- $build = $entity->content;
- unset($entity->content);
- return $build;
- }
-
- protected function renderEntityProperty($wrapper, $name, $property, $view_mode, $langcode, &$content) {
- $info = $property->info();
- $content[$name] = array(
- '#label_hidden' => FALSE,
- '#label' => $info['label'],
- '#entity_wrapped' => $wrapper,
- '#theme' => 'entity_property',
- '#property_name' => $name,
- '#access' => $property->access('view'),
- '#entity_type' => $this->entityType,
- );
- $content['#attached']['css']['entity.theme'] = drupal_get_path('module', 'entity') . '/theme/entity.theme.css';
- }
-
- public function view($entities, $view_mode = 'full', $langcode = NULL, $page = NULL) {
-
-
- $entities = entity_key_array_by_property($entities, $this->idKey);
- if (!empty($this->entityInfo['fieldable'])) {
- field_attach_prepare_view($this->entityType, $entities, $view_mode);
- }
- entity_prepare_view($this->entityType, $entities);
- $langcode = isset($langcode) ? $langcode : $GLOBALS['language_content']->language;
- $view = array();
- foreach ($entities as $entity) {
- $build = entity_build_content($this->entityType, $entity, $view_mode, $langcode);
- $build += array(
-
-
-
- '#theme' => 'entity',
- '#entity_type' => $this->entityType,
- '#entity' => $entity,
- '#view_mode' => $view_mode,
- '#language' => $langcode,
- '#page' => $page,
- );
-
- drupal_alter(array($this->entityType . '_view', 'entity_view'), $build, $this->entityType);
- $key = isset($entity->{$this->idKey}) ? $entity->{$this->idKey} : NULL;
- $view[$this->entityType][$key] = $build;
- }
- return $view;
- }
- }
- class EntityAPIControllerExportable extends EntityAPIController {
- protected $entityCacheByName = array();
- protected $nameKey, $statusKey, $moduleKey;
-
- public function __construct($entityType) {
- parent::__construct($entityType);
-
- $this->nameKey = isset($this->entityInfo['entity keys']['name']) ? $this->entityInfo['entity keys']['name'] : $this->idKey;
- if (!empty($this->entityInfo['exportable'])) {
- $this->statusKey = isset($this->entityInfo['entity keys']['status']) ? $this->entityInfo['entity keys']['status'] : 'status';
- $this->moduleKey = isset($this->entityInfo['entity keys']['module']) ? $this->entityInfo['entity keys']['module'] : 'module';
- }
- }
-
- protected function buildQuery($ids, $conditions = array(), $revision_id = FALSE) {
-
- $query = parent::buildQuery(array(), $conditions, $revision_id);
- if ($ids) {
-
- $key = is_numeric(reset($ids)) ? $this->idKey : $this->nameKey;
- $query->condition("base.$key", $ids, 'IN');
- }
- return $query;
- }
-
- public function load($ids = array(), $conditions = array()) {
- $entities = array();
-
- if (!$ids || $this->nameKey == $this->idKey || is_numeric(reset($ids))) {
- return parent::load($ids, $conditions);
- }
-
-
- if ($this->revisionKey && isset($conditions[$this->revisionKey])) {
- $revision_id = $conditions[$this->revisionKey];
- unset($conditions[$this->revisionKey]);
- }
- else {
- $revision_id = FALSE;
- }
- $passed_ids = !empty($ids) ? array_flip($ids) : FALSE;
-
- if ($this->cache && !$revision_id) {
- $entities = $this->cacheGetByName($ids, $conditions);
- }
-
- if ($entities) {
- $ids = array_keys(array_diff_key($passed_ids, $entities));
- }
- $entities_by_id = parent::load($ids, $conditions);
- $entities += entity_key_array_by_property($entities_by_id, $this->nameKey);
-
-
- $return = array();
- foreach ($passed_ids as $name => $value) {
- if (isset($entities[$name])) {
- $return[$entities[$name]->{$this->idKey}] = $entities[$name];
- }
- }
- return $return;
- }
-
- protected function cacheGet($ids, $conditions = array()) {
- if (!empty($this->entityCache) && $ids !== array()) {
- $entities = $ids ? array_intersect_key($this->entityCache, array_flip($ids)) : $this->entityCache;
- return $this->applyConditions($entities, $conditions);
- }
- return array();
- }
-
- protected function cacheGetByName($names, $conditions = array()) {
- if (!empty($this->entityCacheByName) && $names !== array() && $names) {
-
-
-
- $entities = array_intersect_key($this->entityCacheByName, array_flip($names));
- return $this->applyConditions($entities, $conditions);
- }
- return array();
- }
- protected function applyConditions($entities, $conditions = array()) {
- if ($conditions) {
- foreach ($entities as $key => $entity) {
- $entity_values = (array) $entity;
-
-
- foreach ($conditions as $condition_key => $condition_value) {
- if (is_array($condition_value)) {
- if (!isset($entity_values[$condition_key]) || !in_array($entity_values[$condition_key], $condition_value)) {
- unset($entities[$key]);
- }
- }
- elseif (!isset($entity_values[$condition_key]) || $entity_values[$condition_key] != $condition_value) {
- unset($entities[$key]);
- }
- }
- }
- }
- return $entities;
- }
-
- protected function cacheSet($entities) {
- $this->entityCache += $entities;
-
- if ($this->nameKey != $this->idKey) {
- $this->entityCacheByName += entity_key_array_by_property($entities, $this->nameKey);
- }
- }
-
- protected function attachLoad(&$queried_entities, $revision_id = FALSE) {
-
- if ($this->entityInfo['fieldable']) {
- if ($revision_id) {
- field_attach_load_revision($this->entityType, $queried_entities);
- }
- else {
- field_attach_load($this->entityType, $queried_entities);
- }
- }
-
- foreach (module_implements('entity_load') as $module) {
- $function = $module . '_entity_load';
- $function($queried_entities, $this->entityType);
- }
-
-
-
-
-
- if ($this->nameKey != $this->idKey) {
- $entities_by_name = entity_key_array_by_property($queried_entities, $this->nameKey);
- }
- else {
- $entities_by_name = $queried_entities;
- }
- $args = array_merge(array($entities_by_name), $this->hookLoadArguments);
- foreach (module_implements($this->entityInfo['load hook']) as $module) {
- call_user_func_array($module . '_' . $this->entityInfo['load hook'], $args);
- }
- }
- public function resetCache(array $ids = NULL) {
- $this->cacheComplete = FALSE;
- if (isset($ids)) {
- foreach (array_intersect_key($this->entityCache, array_flip($ids)) as $id => $entity) {
- unset($this->entityCacheByName[$this->entityCache[$id]->{$this->nameKey}]);
- unset($this->entityCache[$id]);
- }
- }
- else {
- $this->entityCache = array();
- $this->entityCacheByName = array();
- }
- }
-
- public function delete($ids, DatabaseTransaction $transaction = NULL) {
- $entities = $ids ? $this->load($ids) : FALSE;
- if ($entities) {
- parent::delete($ids, $transaction);
- foreach ($entities as $id => $entity) {
- if (entity_has_status($this->entityType, $entity, ENTITY_IN_CODE)) {
- entity_defaults_rebuild(array($this->entityType));
- break;
- }
- }
- }
- }
-
- public function invoke($hook, $entity) {
- if ($hook == 'delete') {
-
-
-
- if (entity_has_status($this->entityType, $entity, ENTITY_IN_CODE) && !module_exists($entity->{$this->moduleKey})) {
- $entity->{$this->statusKey} = ENTITY_CUSTOM;
- }
- $is_revert = entity_has_status($this->entityType, $entity, ENTITY_IN_CODE);
- }
- if (!empty($this->entityInfo['fieldable']) && function_exists($function = 'field_attach_' . $hook)) {
- $function($this->entityType, $entity);
- }
- if (isset($this->entityInfo['bundle of']) && $type = $this->entityInfo['bundle of']) {
-
- if ($hook == 'insert') {
- field_attach_create_bundle($type, $entity->{$this->bundleKey});
- }
- elseif ($hook == 'delete' && !$is_revert) {
- field_attach_delete_bundle($type, $entity->{$this->bundleKey});
- }
- elseif ($hook == 'update' && $id = $entity->{$this->nameKey}) {
- if ($entity->original->{$this->bundleKey} != $entity->{$this->bundleKey}) {
- field_attach_rename_bundle($type, $entity->original->{$this->bundleKey}, $entity->{$this->bundleKey});
- }
- }
- }
-
- module_invoke_all($this->entityType . '_' . $hook, $entity);
-
- if ($hook == 'presave' || $hook == 'insert' || $hook == 'update' || $hook == 'delete') {
- module_invoke_all('entity_' . $hook, $entity, $this->entityType);
- }
- }
-
- public function save($entity, DatabaseTransaction $transaction = NULL) {
-
- if (!empty($entity->{$this->nameKey}) && empty($entity->{$this->idKey}) && !isset($entity->original)) {
- $entity->original = entity_load_unchanged($this->entityType, $entity->{$this->nameKey});
- }
-
- if (entity_has_status($this->entityType, $entity, ENTITY_IN_CODE) && empty($entity->is_rebuild)) {
- $entity->{$this->statusKey} |= ENTITY_CUSTOM;
- }
- return parent::save($entity, $transaction);
- }
-
- public function export($entity, $prefix = '') {
- $vars = get_object_vars($entity);
- unset($vars[$this->statusKey], $vars[$this->moduleKey], $vars['is_new']);
- if ($this->nameKey != $this->idKey) {
- unset($vars[$this->idKey]);
- }
- return entity_var_json_export($vars, $prefix);
- }
-
- public function view($entities, $view_mode = 'full', $langcode = NULL, $page = NULL) {
- $view = parent::view($entities, $view_mode, $langcode, $page);
- if ($this->nameKey != $this->idKey) {
-
- $return = array();
- foreach ($view[$this->entityType] as $id => $content) {
- $key = isset($content['#entity']->{$this->nameKey}) ? $content['#entity']->{$this->nameKey} : NULL;
- $return[$this->entityType][$key] = $content;
- }
- $view = $return;
- }
- return $view;
- }
- }
|