trait TypedDataTrait

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/TypedData/TypedDataTrait.php \Drupal\Core\TypedData\TypedDataTrait
  2. 10 core/lib/Drupal/Core/TypedData/TypedDataTrait.php \Drupal\Core\TypedData\TypedDataTrait
  3. 11.x core/lib/Drupal/Core/TypedData/TypedDataTrait.php \Drupal\Core\TypedData\TypedDataTrait

Wrapper methods for classes that needs typed data manager object.

Hierarchy

3 files declare their use of TypedDataTrait
Context.php in core/lib/Drupal/Core/Plugin/Context/Context.php
ContextAwarePluginBase.php in core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php
ContextDefinition.php in core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php

File

core/lib/Drupal/Core/TypedData/TypedDataTrait.php, line 8

Namespace

Drupal\Core\TypedData
View source
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;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
TypedDataTrait::$typedDataManager protected property The typed data manager used for creating the data types.
TypedDataTrait::getTypedDataManager public function Gets the typed data manager. 2
TypedDataTrait::setTypedDataManager public function Sets the typed data manager. 2

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