You are here

DataDynamicReferenceDefinition.php in Dynamic Entity Reference 8.2

Same filename and directory in other branches
  1. 8 src/DataDynamicReferenceDefinition.php

File

src/DataDynamicReferenceDefinition.php
View source
<?php

namespace Drupal\dynamic_entity_reference;

use Drupal\Core\TypedData\DataReferenceDefinition;

/**
 * A typed data definition class for defining dynamic references.
 */
class DataDynamicReferenceDefinition extends DataReferenceDefinition {

  /**
   * The data definition of target.
   *
   * @var \Drupal\Core\TypedData\DataDefinitionInterface
   */
  protected $targetDefinition;

  /**
   * Creates a new data reference definition.
   *
   * @param string $target_data_type
   *   The data type of the referenced data.
   *
   * @return $this
   */
  public static function create($target_data_type) {
    $definition['type'] = 'dynamic_' . $target_data_type . '_reference';

    /** @var \Drupal\Core\TypedData\DataReferenceDefinition $definition */
    $definition = new static($definition);
    return $definition
      ->setTargetDefinition(\Drupal::typedDataManager()
      ->createDataDefinition($target_data_type));
  }

}

Classes

Namesort descending Description
DataDynamicReferenceDefinition A typed data definition class for defining dynamic references.