You are here

trait DataFetcherTrait in Typed Data API enhancements 8

Helper for classes that need the data fetcher object.

Hierarchy

File

src/DataFetcherTrait.php, line 8

Namespace

Drupal\typed_data
View source
trait DataFetcherTrait {

  /**
   * The data fetcher.
   *
   * @var \Drupal\typed_data\DataFetcherInterface
   */
  protected $dataFetcher;

  /**
   * Sets the data fetcher.
   *
   * @param \Drupal\typed_data\DataFetcherInterface $data_fetcher
   *   The data fetcher.
   *
   * @return $this
   */
  public function setDataFetcher(DataFetcherInterface $data_fetcher) {
    $this->dataFetcher = $data_fetcher;
    return $this;
  }

  /**
   * Gets the data fetcher.
   *
   * @return \Drupal\typed_data\DataFetcherInterface
   *   The data fetcher.
   */
  public function getDataFetcher() {
    if (empty($this->dataFetcher)) {
      $this->dataFetcher = \Drupal::service('typed_data.data_fetcher');
    }
    return $this->dataFetcher;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DataFetcherTrait::$dataFetcher protected property The data fetcher.
DataFetcherTrait::getDataFetcher public function Gets the data fetcher.
DataFetcherTrait::setDataFetcher public function Sets the data fetcher.