protected Query::prepare()
Prepares the basic query with proper metadata/tags and base fields.
Return value
\Drupal\Core\Entity\Query\Sql\Query Returns the called object.
Throws
\Drupal\Core\Entity\Query\QueryException Thrown if the base table does not exist.
File
- core/lib/Drupal/Core/Entity/Query/Sql/Query.php, line 89
Class
- Query
- The SQL storage entity query class.
Namespace
Drupal\Core\Entity\Query\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 | protected function prepare() { if ( $this ->allRevisions) { if (! $base_table = $this ->entityType->getRevisionTable()) { throw new QueryException( "No revision table for " . $this ->entityTypeId . ", invalid query." ); } } else { if (! $base_table = $this ->entityType->getBaseTable()) { throw new QueryException( "No base table for " . $this ->entityTypeId . ", invalid query." ); } } $simple_query = TRUE; if ( $this ->entityType->getDataTable()) { $simple_query = FALSE; } $this ->sqlQuery = $this ->connection->select( $base_table , 'base_table' , array ( 'conjunction' => $this ->conjunction)); $this ->sqlQuery->addMetaData( 'entity_type' , $this ->entityTypeId); $id_field = $this ->entityType->getKey( 'id' ); // Add the key field for fetchAllKeyed(). if (! $revision_field = $this ->entityType->getKey( 'revision' )) { // When there is no revision support, the key field is the entity key. $this ->sqlFields[ "base_table.$id_field" ] = array ( 'base_table' , $id_field ); // Now add the value column for fetchAllKeyed(). This is always the // entity id. $this ->sqlFields[ "base_table.$id_field" . '_1' ] = array ( 'base_table' , $id_field ); } else { // When there is revision support, the key field is the revision key. $this ->sqlFields[ "base_table.$revision_field" ] = array ( 'base_table' , $revision_field ); // Now add the value column for fetchAllKeyed(). This is always the // entity id. $this ->sqlFields[ "base_table.$id_field" ] = array ( 'base_table' , $id_field ); } if ( $this ->accessCheck) { $this ->sqlQuery->addTag( $this ->entityTypeId . '_access' ); } $this ->sqlQuery->addTag( 'entity_query' ); $this ->sqlQuery->addTag( 'entity_query_' . $this ->entityTypeId); // Add further tags added. if (isset( $this ->alterTags)) { foreach ( $this ->alterTags as $tag => $value ) { $this ->sqlQuery->addTag( $tag ); } } // Add further metadata added. if (isset( $this ->alterMetaData)) { foreach ( $this ->alterMetaData as $key => $value ) { $this ->sqlQuery->addMetaData( $key , $value ); } } // This now contains first the table containing entity properties and // last the entity base table. They might be the same. $this ->sqlQuery->addMetaData( 'all_revisions' , $this ->allRevisions); $this ->sqlQuery->addMetaData( 'simple_query' , $simple_query ); return $this ; } |
Please login to continue.