protected SqlContentEntityStorage::loadFromSharedTables(array &$values, array &$translations)
Loads values for fields stored in the shared data tables.
Parameters
array &$values: Associative array of entities values, keyed on the entity ID.
array &$translations: List of translations, keyed on the entity ID.
File
- core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php, line 502
Class
- SqlContentEntityStorage
- A content entity database storage implementation.
Namespace
Drupal\Core\Entity\Sql
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | protected function loadFromSharedTables( array & $values , array & $translations ) { if ( $this ->dataTable) { // If a revision table is available, we need all the properties of the // latest revision. Otherwise we fall back to the data table. $table = $this ->revisionDataTable ? : $this ->dataTable; $alias = $this ->revisionDataTable ? 'revision' : 'data' ; $query = $this ->database->select( $table , $alias , array ( 'fetch' => \PDO::FETCH_ASSOC)) ->fields( $alias ) ->condition( $alias . '.' . $this ->idKey, array_keys ( $values ), 'IN' ) ->orderBy( $alias . '.' . $this ->idKey); $table_mapping = $this ->getTableMapping(); if ( $this ->revisionDataTable) { // Find revisioned fields that are not entity keys. Exclude the langcode // key as the base table holds only the default language. $base_fields = array_diff ( $table_mapping ->getFieldNames( $this ->baseTable), array ( $this ->langcodeKey)); $revisioned_fields = array_diff ( $table_mapping ->getFieldNames( $this ->revisionDataTable), $base_fields ); // Find fields that are not revisioned or entity keys. Data fields have // the same value regardless of entity revision. $data_fields = array_diff ( $table_mapping ->getFieldNames( $this ->dataTable), $revisioned_fields , $base_fields ); // If there are no data fields then only revisioned fields are needed // else both data fields and revisioned fields are needed to map the // entity values. $all_fields = $revisioned_fields ; if ( $data_fields ) { $all_fields = array_merge ( $revisioned_fields , $data_fields ); $query ->leftJoin( $this ->dataTable, 'data' , "(revision.$this->idKey = data.$this->idKey and revision.$this->langcodeKey = data.$this->langcodeKey)" ); $column_names = []; // Some fields can have more then one columns in the data table so // column names are needed. foreach ( $data_fields as $data_field ) { // \Drupal\Core\Entity\Sql\TableMappingInterface:: getColumNames() // returns an array keyed by property names so remove the keys // before array_merge() to avoid losing data with fields having the // same columns i.e. value. $column_names = array_merge ( $column_names , array_values ( $table_mapping ->getColumnNames( $data_field ))); } $query ->fields( 'data' , $column_names ); } // Get the revision IDs. $revision_ids = array (); foreach ( $values as $entity_values ) { $revision_ids [] = $entity_values [ $this ->revisionKey][LanguageInterface::LANGCODE_DEFAULT]; } $query ->condition( 'revision.' . $this ->revisionKey, $revision_ids , 'IN' ); } else { $all_fields = $table_mapping ->getFieldNames( $this ->dataTable); } $result = $query ->execute(); foreach ( $result as $row ) { $id = $row [ $this ->idKey]; // Field values in default language are stored with // LanguageInterface::LANGCODE_DEFAULT as key. $langcode = empty ( $row [ $this ->defaultLangcodeKey]) ? $row [ $this ->langcodeKey] : LanguageInterface::LANGCODE_DEFAULT; $translations [ $id ][ $langcode ] = TRUE; foreach ( $all_fields as $field_name ) { $columns = $table_mapping ->getColumnNames( $field_name ); // Do not key single-column fields by property name. if ( count ( $columns ) == 1) { $values [ $id ][ $field_name ][ $langcode ] = $row [reset( $columns )]; } else { foreach ( $columns as $property_name => $column_name ) { $values [ $id ][ $field_name ][ $langcode ][ $property_name ] = $row [ $column_name ]; } } } } } } |
Please login to continue.