public static function ContentEntitySource::getEmbeddableFields

Returns fields that should be embedded into the data for the given entity.

Includes explicitly enabled fields and composite entities that are implicitly included to the translatable data.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity to get the translatable data from.

Return value

\Drupal\Core\Field\FieldDefinitionInterface[] $embeddable_fields A list of field definitions that can be embedded.

3 calls to ContentEntitySource::getEmbeddableFields()
ContentEntitySource::doSaveTranslations in sources/content/src/Plugin/tmgmt/Source/ContentEntitySource.php
Saves translation data in an entity translation.
ContentEntitySource::extractTranslatableData in sources/content/src/Plugin/tmgmt/Source/ContentEntitySource.php
Extracts translatable data from an entity.
tmgmt_content_tmgmt_source_suggestions in sources/content/tmgmt_content.module
Implements hook_tmgmt_source_suggestions().

File

sources/content/src/Plugin/tmgmt/Source/ContentEntitySource.php, line 345

Class

ContentEntitySource
Content entity source plugin controller.

Namespace

Drupal\tmgmt_content\Plugin\tmgmt\Source

Code

public static function getEmbeddableFields(ContentEntityInterface $entity) {

  // Get the configurable embeddable references.
  $field_definitions = $entity
    ->getFieldDefinitions();
  $embeddable_field_names = \Drupal::config('tmgmt_content.settings')
    ->get('embedded_fields');
  $embeddable_fields = array_filter($field_definitions, function (FieldDefinitionInterface $field_definition) use ($embeddable_field_names) {
    return isset($embeddable_field_names[$field_definition
      ->getTargetEntityTypeId()][$field_definition
      ->getName()]);
  });

  // Get always embedded references.
  $content_translation_manager = \Drupal::service('content_translation.manager');
  foreach ($field_definitions as $field_name => $field_definition) {
    $storage_definition = $field_definition
      ->getFieldStorageDefinition();
    $property_definitions = $storage_definition
      ->getPropertyDefinitions();
    foreach ($property_definitions as $property_definition) {

      // Look for entity_reference properties where the storage definition
      // has a target type setting.
      if (in_array($property_definition
        ->getDataType(), [
        'entity_reference',
        'entity_revision_reference',
      ]) && ($target_type_id = $storage_definition
        ->getSetting('target_type'))) {
        $is_target_type_enabled = $content_translation_manager
          ->isEnabled($target_type_id);
        $target_entity_type = \Drupal::entityTypeManager()
          ->getDefinition($target_type_id);

        // Include current entity reference field that is considered a
        // composite and translatable or if the parent entity is considered a
        // composite as well. This allows to embed nested untranslatable
        // fields (For example: Paragraphs).
        if ($target_entity_type
          ->get('entity_revision_parent_type_field') && ($is_target_type_enabled || $entity
          ->getEntityType()
          ->get('entity_revision_parent_type_field'))) {
          $embeddable_fields[$field_name] = $field_definition;
        }
      }
    }
  }
  return $embeddable_fields;
}