getEntityFieldManager 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. */
  

  protected function extractBundleData(array &$data, EntityTypeInterface $entity_type_definition) {
    $bundle_key = $entity_type_definition->getKey('bundle');
    // Get the base field definitions for this entity type.     $base_field_definitions = $this->getEntityFieldManager()->getBaseFieldDefinitions($entity_type_definition->id());

    // Get the ID key from the base field definition for the bundle key or     // default to 'value'.     $key_id = isset($base_field_definitions[$bundle_key]) ? $base_field_definitions[$bundle_key]->getFieldStorageDefinition()->getMainPropertyName() : 'value';

    // Normalize the bundle if it is not explicitly set.     $bundle_value = $data[$bundle_key][0][$key_id] ?? ($data[$bundle_key] ?? NULL);
    // Unset the bundle from the data.     unset($data[$bundle_key]);

    // Get the bundle entity type from the entity type definition.
Home | Imprint | This part of the site doesn't use cookies.