getFieldStorageDefinitions example

return $this->fieldDefinition;
  }

  /** * Gets the field storage configuration. * * @return \Drupal\field\FieldStorageConfigInterface * The field storage definition used by this handler */
  protected function getFieldStorageDefinition() {
    if (!$this->fieldStorageDefinition) {
      $field_storage_definitions = $this->getEntityFieldManager()->getFieldStorageDefinitions($this->definition['entity_type']);
      $this->fieldStorageDefinition = $field_storage_definitions[$this->definition['field_name']];
    }
    return $this->fieldStorageDefinition;
  }

  /** * Returns the entity field manager. * * @return \Drupal\Core\Entity\EntityFieldManagerInterface * The entity field manager. */
  

          'example_module',
        );
      });
    $this->moduleHandler->alter('entity_field_storage_info', $definitions$this->entityType)->willReturn(NULL);

    $expected = [
      'id' => $field_definition,
      'base_field' => $base_field_definition->reveal(),
      'field_storage' => $field_storage_definition->reveal(),
    ];
    $this->assertSame($expected$this->entityFieldManager->getFieldStorageDefinitions('test_entity_type'));
  }

  /** * Tests the getBaseFieldDefinitions() method with a translatable entity type. * * @covers ::getBaseFieldDefinitions * @covers ::buildBaseFieldDefinitions * * @dataProvider providerTestGetBaseFieldDefinitionsTranslatableEntityTypeDefaultLangcode */
  public function testGetBaseFieldDefinitionsTranslatableEntityTypeDefaultLangcode($default_langcode_key) {
    
/** * Asserts that the bundle field schema is correct. * * @param bool $revisionable * Whether the entity type is revisionable or not. * * @internal */
  protected function assertBundleFieldSchema(bool $revisionable): void {
    $entity_type_id = 'entity_test_update';
    $field_storage_definition = $this->entityFieldManager->getFieldStorageDefinitions($entity_type_id)['new_bundle_field'];
    $database_schema = $this->database->schema();
    /** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
    $table_mapping = $this->entityTypeManager
      ->getStorage($entity_type_id)
      ->getTableMapping();
    $this->assertTrue($database_schema->tableExists($table_mapping->getDedicatedDataTableName($field_storage_definition)));
    if ($revisionable) {
      $this->assertTrue($database_schema->tableExists($table_mapping->getDedicatedRevisionTableName($field_storage_definition)));
    }
  }

  
$definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($this->entityType, $this->bundle);
    $this->assertTrue(isset($definitions[$this->fieldTestData->field->getName()]));
    $this->assertInstanceOf(FieldDefinitionInterface::class$definitions[$this->fieldTestData->field->getName()]);
    // Make sure fields on other entity types are not exposed.     $this->assertFalse(isset($definitions[$this->fieldTestData->field_rev->getName()]));
  }

  /** * Makes sure a field storage definition is exposed for a configurable field. */
  public function testFieldStorageDefinition() {
    $field_storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($this->entityType);
    $this->assertTrue(isset($field_storage_definitions[$this->fieldTestData->field->getName()]));
    $this->assertInstanceOf(FieldStorageDefinitionInterface::class$field_storage_definitions[$this->fieldTestData->field->getName()]);
    // Make sure storages on other entity types are not exposed.     $this->assertFalse(isset($field_storage_definitions[$this->fieldTestData->field_rev->getName()]));
  }

}
$entity_type_id = $entity_type->id();

    // @todo Forward this to all interested handlers, not only storage, once     // iterating handlers is possible: https://www.drupal.org/node/2332857.     $storage = $this->entityTypeManager->getStorage($entity_type_id);
    if ($storage instanceof EntityTypeListenerInterface) {
      $storage->onEntityTypeCreate($entity_type);
    }

    $this->entityLastInstalledSchemaRepository->setLastInstalledDefinition($entity_type);
    if ($entity_type->entityClassImplements(FieldableEntityInterface::class)) {
      $this->entityLastInstalledSchemaRepository->setLastInstalledFieldStorageDefinitions($entity_type_id$this->entityFieldManager->getFieldStorageDefinitions($entity_type_id));
    }

    $this->eventDispatcher->dispatch(new EntityTypeEvent($entity_type), EntityTypeEvents::CREATE);
    $this->clearCachedDefinitions();
  }

  /** * {@inheritdoc} */
  public function onFieldableEntityTypeCreate(EntityTypeInterface $entity_type, array $field_storage_definitions) {
    $entity_type_id = $entity_type->id();

    

  public function setThread($thread) {
    $this->set('thread', $thread);
    return $this;
  }

  /** * {@inheritdoc} */
  public static function preCreate(EntityStorageInterface $storage, array &$values) {
    if (empty($values['comment_type']) && !empty($values['field_name']) && !empty($values['entity_type'])) {
      $fields = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($values['entity_type']);
      $values['comment_type'] = $fields[$values['field_name']]->getSetting('comment_type');
    }
  }

  /** * {@inheritdoc} */
  public function getOwner() {
    $user = $this->get('uid')->entity;
    if (!$user || $user->isAnonymous()) {
      $user = User::getAnonymousUser();
      
$field_storages = \Drupal::entityQuery('field_storage_config')
        ->condition('id', $field_storage_ids, 'IN')
        ->condition('module', $providers, 'NOT IN')
        ->execute();
      if (!empty($field_storages)) {
        $storages_to_delete = FieldStorageConfig::loadMultiple($field_storages);
      }
    }

    // Gather deleted fields from modules that are being uninstalled.     /** @var \Drupal\field\FieldStorageConfigInterface[] $deleted_storage_definitions */
    $deleted_storage_definitions = \Drupal::service('entity_field.deleted_fields_repository')->getFieldStorageDefinitions();
    foreach ($deleted_storage_definitions as $field_storage_definition) {
      if ($field_storage_definition instanceof FieldStorageConfigInterface && !in_array($field_storage_definition->getTypeProvider()$providers)) {
        $storages_to_delete[$field_storage_definition->id()] = $field_storage_definition;
      }
    }
    return $storages_to_delete;
  }

}
return;
    }
    foreach ($tree as $specifier => $children) {
      // The field path reconstructs the entity condition fields.       // E.g. `uid.0` would become `uid.0.name` if $specifier === 'name'.       $child_prefix = (is_null($field_prefix)) ? $specifier : "$field_prefix.$specifier";
      if (is_null($field_storage_definition)) {
        // When the field storage definition is NULL, this specifier is the         // first specifier in an entity query field path or the previous         // specifier was a data reference that has been traversed. In both         // cases, the specifier must be a field name.         $field_storage_definitions = static::$fieldManager->getFieldStorageDefinitions($entity_type_id);
        static::secureQuery($query$entity_type_id$children$cacheability$child_prefix$field_storage_definitions[$specifier]);
        // When $field_prefix is NULL, this must be the first specifier in the         // entity query field path and a condition for the query's base entity         // type must be applied.         if (is_null($field_prefix)) {
          static::applyAccessConditions($query$entity_type_id, NULL, $cacheability);
        }
      }
      else {
        // When the specifier is an entity reference, it can contain an entity         // type specifier, like so: `entity:node`. This extracts the `entity`
$this->query->addOrderBy(NULL, NULL, $order$this->aliases[$column]);
  }

  /** * Gets the field storage definition. * * @return \Drupal\Core\Field\FieldStorageDefinitionInterface * The field storage definition used by this handler. */
  protected function getFieldStorageDefinition() {
    $entity_type_id = $this->definition['entity_type'];
    $field_storage_definitions = $this->entityFieldManager->getFieldStorageDefinitions($entity_type_id);

    // @todo Unify 'entity field'/'field_name' instead of converting back and     // forth. https://www.drupal.org/node/2410779     if (isset($this->definition['field_name']) && isset($field_storage_definitions[$this->definition['field_name']])) {
      return $field_storage_definitions[$this->definition['field_name']];
    }

    if (isset($this->definition['entity field']) && isset($field_storage_definitions[$this->definition['entity field']])) {
      return $field_storage_definitions[$this->definition['entity field']];
    }

    
$this->installSchema('user', ['users_data']);
    $this->installEntitySchema('entity_test_update');
    $this->database = $this->container->get('database');
  }

  /** * Tests the custom bundle field creation and deletion. */
  public function testCustomFieldCreateDelete() {
    // Install the module which adds the field.     $this->installModule('entity_schema_test');
    $storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions('entity_test_update');
    $this->assertNotNull($storage_definitions['custom_base_field'], 'Base field definition found.');
    $this->assertNotNull($storage_definitions['custom_bundle_field'], 'Bundle field definition found.');

    // Make sure the field schema can be created.     \Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionCreate($storage_definitions['custom_base_field']);
    \Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionCreate($storage_definitions['custom_bundle_field']);
    /** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
    $table_mapping = $this->entityTypeManager->getStorage('entity_test_update')->getTableMapping();
    $base_table = current($table_mapping->getTableNames());
    $base_column = current($table_mapping->getColumnNames('custom_base_field'));
    $this->assertTrue($this->database->schema()->fieldExists($base_table$base_column), 'Table column created');
    
public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account, string $bundle = NULL): AccessResultInterface {
    $access = AccessResult::neutral();
    if ($entity_type_id = $route->getDefault('entity_type_id')) {
      if (empty($bundle)) {
        $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
        $bundle = $route_match->getRawParameter($entity_type->getBundleEntityType());
      }

      $field_types = $this->fieldTypePluginManager->getDefinitions();
      // Allows access if there are any existing fields and the user       // correct permissions.       foreach ($this->entityFieldManager->getFieldStorageDefinitions($entity_type_id) as $field_storage) {
        // Do not include fields with         // - non-configurable field storages,         // - locked field storages,         // - field storages that should not be added via user interface,         // - field storages that already have a field in the bundle.         $field_type = $field_storage->getType();
        $access->addCacheableDependency($field_storage);
        if ($field_storage instanceof FieldStorageConfigInterface
          && !$field_storage->isLocked()
          && empty($field_types[$field_type]['no_ui'])
          && !in_array($bundle$field_storage->getBundles(), TRUE)) {
          

  public function getActiveFieldStorageDefinitions($entity_type_id) {
    if (!isset($this->activeFieldStorageDefinitions[$entity_type_id])) {
      $this->activeFieldStorageDefinitions[$entity_type_id] = $this->entityLastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions($entity_type_id);
    }
    return $this->activeFieldStorageDefinitions[$entity_type_id] ?: $this->getFieldStorageDefinitions($entity_type_id);
  }

  /** * {@inheritdoc} */
  public function setFieldMap(array $field_map) {
    $this->fieldMap = $field_map;
    return $this;
  }

  /** * {@inheritdoc} */
->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());
    $this->entityStorage->setModuleHandler($this->moduleHandler);
  }

  /** * @covers ::doLoadMultiple * @covers ::buildCacheId * @covers ::getFromPersistentCache */

  protected function getSourceFieldOptions() {
    // If there are existing fields to choose from, allow the user to reuse one.     $options = [];
    foreach ($this->entityFieldManager->getFieldStorageDefinitions('media') as $field_name => $field) {
      $allowed_type = in_array($field->getType()$this->pluginDefinition['allowed_field_types'], TRUE);
      if ($allowed_type && !$field->isBaseField()) {
        $options[$field_name] = $field->getLabel();
      }
    }
    return $options;
  }

  /** * {@inheritdoc} */
  


  /** * Validates the cardinality. * * @param array $element * The cardinality form render array. * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state. */
  public function validateCardinality(array &$element, FormStateInterface $form_state) {
    $field_storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($this->entity->getTargetEntityTypeId());

    // Validate field cardinality.     if ($form_state->getValue('cardinality') === 'number' && !$form_state->getValue('cardinality_number')) {
      $form_state->setError($element['cardinality_number']$this->t('Number of values is required.'));
    }
    // If a specific cardinality is used, validate that there are no entities     // with a higher delta.     elseif (!$this->entity->isNew() && isset($field_storage_definitions[$this->entity->getName()]) && $form_state->getValue('cardinality') != FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) {

      // Get a count of entities that have a value in a delta higher than the       // one selected. Deltas start with 0, so the selected value does not
Home | Imprint | This part of the site doesn't use cookies.