getActiveDefinition example

    // ->condition('node_reference.nid.entity.tags', 2)     // The first two should use the same table but the last one needs to be a     // new table. So for the first two, the table array index will be 'tags'     // while the third will be 'node_reference.nid.tags'.     $index_prefix = '';
    $specifiers = explode('.', $field);
    $base_table = 'base_table';
    $count = count($specifiers) - 1;
    // This will contain the definitions of the last specifier seen by the     // system.     $propertyDefinitions = [];
    $entity_type = $this->entityTypeManager->getActiveDefinition($entity_type_id);

    $field_storage_definitions = $this->entityFieldManager->getActiveFieldStorageDefinitions($entity_type_id);
    for ($key = 0; $key <= $count$key++) {
      // This can either be the name of an entity base field or a configurable       // field.       $specifier = $specifiers[$key];
      if (isset($field_storage_definitions[$specifier])) {
        $field_storage = $field_storage_definitions[$specifier];
        $column = $field_storage->getMainPropertyName();
      }
      else {
        

  public function __construct(EntityTypeInterface $entity_type, Connection $database, EntityFieldManagerInterface $entity_field_manager, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, MemoryCacheInterface $memory_cache, EntityTypeBundleInfoInterface $entity_type_bundle_info, EntityTypeManagerInterface $entity_type_manager) {
    parent::__construct($entity_type$entity_field_manager$cache$memory_cache$entity_type_bundle_info);
    $this->database = $database;
    $this->languageManager = $language_manager;
    $this->entityTypeManager = $entity_type_manager;
    $this->entityType = $this->entityTypeManager->getActiveDefinition($entity_type->id());
    $this->fieldStorageDefinitions = $this->entityFieldManager->getActiveFieldStorageDefinitions($entity_type->id());

    $this->initTableLayout();
  }

  /** * Initializes table name variables. */
  protected function initTableLayout() {
    // Reset table field values to ensure changes in the entity type definition     // are correctly reflected in the table layout.

  public function __construct(EntityTypeManagerInterface $entity_type_manager, ContentEntityTypeInterface $entity_type, SqlContentEntityStorage $storage, Connection $database, EntityFieldManagerInterface $entity_field_manager) {
    $this->entityTypeManager = $entity_type_manager;
    $this->storage = clone $storage;
    $this->database = $database;
    $this->entityFieldManager = $entity_field_manager;

    $this->entityType = $entity_type_manager->getActiveDefinition($entity_type->id());
    $this->fieldStorageDefinitions = $entity_field_manager->getActiveFieldStorageDefinitions($entity_type->id());
  }

  /** * Gets the keyvalue collection for tracking the installed schema. * * @return \Drupal\Core\KeyValueStore\KeyValueStoreInterface * * @todo Inject this dependency in the constructor once this class can be * instantiated as a regular entity handler: * https://www.drupal.org/node/2332857. */

  protected function setUpEntityStorage() {
    $this->connection = $this->getMockBuilder('Drupal\Core\Database\Connection')
      ->disableOriginalConstructor()
      ->getMock();

    $this->entityTypeManager
      ->getDefinition($this->entityType->id())
      ->willReturn($this->entityType);

    $this->entityTypeManager
      ->getActiveDefinition($this->entityType->id())
      ->willReturn($this->entityType);

    $this->entityFieldManager
      ->getFieldStorageDefinitions($this->entityType->id())
      ->willReturn($this->fieldDefinitions);

    $this->entityFieldManager
      ->getActiveFieldStorageDefinitions($this->entityType->id())
      ->willReturn($this->fieldDefinitions);

    $this->entityStorage = new SqlContentEntityStorage($this->entityType, $this->connection, $this->entityFieldManager->reveal()$this->cache, $this->languageManager, new MemoryCache()$this->entityTypeBundleInfo, $this->entityTypeManager->reveal());
    
      // 1) if $base_table is of an entity type that can belong to a workspace;       // 2) if $id_field is the revision key of that entity type or the special       // 'revision_id' string used when joining dedicated field tables.       // If those two conditions are met, we have to update the join condition       // to also look for a possible workspace-specific revision using COALESCE.       $condition_parts = explode(' = ', $join_condition);
      $condition_parts_1 = str_replace(['[', ']'], '', $condition_parts[1]);
      [$base_table$id_field] = explode('.', $condition_parts_1);

      if (isset($this->baseTablesEntityType[$base_table])) {
        $entity_type_id = $this->baseTablesEntityType[$base_table];
        $revision_key = $this->entityTypeManager->getActiveDefinition($entity_type_id)->getKey('revision');

        if ($id_field === $revision_key || $id_field === 'revision_id') {
          $workspace_association_table = $this->contentWorkspaceTables[$base_table];
          $join_condition = "{$condition_parts[0]} = COALESCE($workspace_association_table.target_entity_revision_id, {$condition_parts[1]})";
        }
      }
    }

    return parent::addJoin($type$table$join_condition$langcode$delta);
  }

  

  protected function setUpStorageSchema(array $expected = []) {
    $this->entityTypeManager
      ->getDefinition($this->entityType->id())
      ->willReturn($this->entityType);

    $this->entityTypeManager
      ->getActiveDefinition($this->entityType->id())
      ->willReturn($this->entityType);

    $this->entityFieldManager
      ->getFieldStorageDefinitions($this->entityType->id())
      ->willReturn($this->storageDefinitions);

    $this->entityFieldManager
      ->getActiveFieldStorageDefinitions($this->entityType->id())
      ->willReturn($this->storageDefinitions);

    $this->dbSchemaHandler = $this->getMockBuilder('Drupal\Core\Database\Schema')
      
Home | Imprint | This part of the site doesn't use cookies.