setTypedDataManager example

/** * Gets the typed configuration manager. * * Overrides \Drupal\Core\TypedData\TypedDataTrait::getTypedDataManager() to * ensure the typed configuration manager is returned. * * @return \Drupal\Core\Config\TypedConfigManagerInterface * The typed configuration manager. */
  public function getTypedDataManager() {
    if (empty($this->typedDataManager)) {
      $this->setTypedDataManager(\Drupal::service('config.typed'));
    }

    return $this->typedDataManager;
  }

  /** * Sets the typed config manager. * * Overrides \Drupal\Core\TypedData\TypedDataTrait::setTypedDataManager() to * ensure that only typed configuration manager can be used. * * @param \Drupal\Core\TypedData\TypedDataManagerInterface $typed_data_manager * The typed config manager. This must be an instance of * \Drupal\Core\Config\TypedConfigManagerInterface. If it is not, then this * method will error when assertions are enabled. We can not narrow the * typehint as this will cause PHP errors. * * @return $this */
$this->typedDataManager = $this->createMock(TypedDataManagerInterface::class);
  }

  /** * @covers ::getContextValue */
  public function testDefaultValue() {
    $this->setUpDefaultValue('test');

    $context = new Context($this->contextDefinition);
    $context->setTypedDataManager($this->typedDataManager);
    $this->assertEquals('test', $context->getContextValue());
  }

  /** * @covers ::getContextData */
  public function testDefaultDataValue() {
    $this->setUpDefaultValue('test');

    $context = new Context($this->contextDefinition);
    $context->setTypedDataManager($this->typedDataManager);
    
public function getCacheMaxAge() {
    return $this->cacheabilityMetadata->getCacheMaxAge();
  }

  /** * {@inheritdoc} */
  public static function createFromContext(ContextInterface $old_context$value) {
    $context = new static($old_context->getContextDefinition()$value);
    $context->addCacheableDependency($old_context);
    if (method_exists($old_context, 'getTypedDataManager')) {
      $context->setTypedDataManager($old_context->getTypedDataManager());
    }
    return $context;
  }

}
throw new \InvalidArgumentException("Invalid data type '$data_type' has been given");
    }

    // Allow per-data definition overrides of the used classes, i.e. take over     // classes specified in the type definition.     $class = $data_definition->getClass();

    if (!isset($class)) {
      throw new PluginException(sprintf('The plugin (%s) did not specify an instance class.', $data_type));
    }
    $typed_data = $class::createInstance($data_definition$configuration['name']$configuration['parent']);
    $typed_data->setTypedDataManager($this);
    return $typed_data;
  }

  /** * {@inheritdoc} */
  public function create(DataDefinitionInterface $definition$value = NULL, $name = NULL, $parent = NULL) {
    $typed_data = $this->createInstance($definition->getDataType()[
      'data_definition' => $definition,
      'name' => $name,
      'parent' => $parent,
    ]);
Home | Imprint | This part of the site doesn't use cookies.