You are here

public function ReferenceUri::process in YAML Content 8

Processes field data.

Parameters

\Drupal\yaml_content\Plugin\ProcessingContext $context: The processing context.

array $field_data: The field data.

Return value

array|int The entity id.

Throws

\Drupal\Core\TypedData\Exception\MissingDataException Error for missing data.

Overrides Reference::process

See also

\Drupal\yaml_content\Plugin\YamlContentProcessManager::preprocessFieldData()

File

src/Plugin/yaml_content/process/ReferenceUri.php, line 21

Class

ReferenceUri
Plugin for querying and loading a referenced entity URI.

Namespace

Drupal\yaml_content\Plugin\yaml_content\process

Code

public function process(ProcessingContext $context, array &$field_data) {

  // Run the reference plugin process method.
  parent::process($context, $field_data);

  // If an entity id was stored in the field_data array.
  if (!empty($field_data['target_id'])) {

    // Get the entity type from the configuration.
    $entity_type = $this->configuration[0];

    // Create an internal path for the referenced entity.
    $uri = 'entity:' . $entity_type . '/' . $field_data['target_id'];

    // Replace 'target_id' with 'uri'.
    unset($field_data['target_id']);
    $field_data['uri'] = $uri;
  }
}