TypedDataTrait.php

Same filename in other branches
  1. 9 core/lib/Drupal/Core/TypedData/TypedDataTrait.php
  2. 8.9.x core/lib/Drupal/Core/TypedData/TypedDataTrait.php
  3. 11.x core/lib/Drupal/Core/TypedData/TypedDataTrait.php

Namespace

Drupal\Core\TypedData

File

core/lib/Drupal/Core/TypedData/TypedDataTrait.php

View source
<?php

namespace Drupal\Core\TypedData;


/**
 * Wrapper methods for classes that needs typed data manager object.
 */
trait TypedDataTrait {
    
    /**
     * The typed data manager used for creating the data types.
     *
     * @var \Drupal\Core\TypedData\TypedDataManagerInterface
     */
    protected $typedDataManager;
    
    /**
     * Sets the typed data manager.
     *
     * @param \Drupal\Core\TypedData\TypedDataManagerInterface $typed_data_manager
     *   The typed data manager.
     *
     * @return $this
     */
    public function setTypedDataManager(TypedDataManagerInterface $typed_data_manager) {
        $this->typedDataManager = $typed_data_manager;
        return $this;
    }
    
    /**
     * Gets the typed data manager.
     *
     * @return \Drupal\Core\TypedData\TypedDataManagerInterface
     *   The typed data manager.
     */
    public function getTypedDataManager() {
        if (empty($this->typedDataManager)) {
            $this->typedDataManager = \Drupal::typedDataManager();
        }
        return $this->typedDataManager;
    }

}

Traits

Title Deprecated Summary
TypedDataTrait Wrapper methods for classes that needs typed data manager object.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.