Commit 12f895ec authored by webchick's avatar webchick

Issue #2132145 by plopesc, amateescu, Xano: Rename 'typed_data' /...

Issue #2132145 by plopesc, amateescu, Xano: Rename 'typed_data' / Drupal::typedData() to 'typed_data_manager' / Drupal::typedDataManager.
parent 8aab1a03
......@@ -248,7 +248,7 @@ services:
factory_class: Drupal\Core\Database\Database
factory_method: getConnection
arguments: [slave]
typed_data:
typed_data_manager:
class: Drupal\Core\TypedData\TypedDataManager
parent: default_plugin_manager
calls:
......
......@@ -366,8 +366,8 @@ public static function moduleHandler() {
*
* @see \Drupal\Core\TypedData\TypedDataManager::create()
*/
public static function typedData() {
return static::$container->get('typed_data');
public static function typedDataManager() {
return static::$container->get('typed_data_manager');
}
/**
......
......@@ -261,7 +261,7 @@ public function getString() {
*/
public function validate() {
// @todo: Add the typed data manager as proper dependency.
return \Drupal::typedData()->getValidator()->validate($this);
return \Drupal::typedDataManager()->getValidator()->validate($this);
}
/**
......@@ -414,7 +414,7 @@ protected function getTranslatedField($name, $langcode) {
if (isset($this->values[$name][$langcode])) {
$value = $this->values[$name][$langcode];
}
$field = \Drupal::typedData()->getPropertyInstance($this, $name, $value);
$field = \Drupal::typedDataManager()->getPropertyInstance($this, $name, $value);
if ($default) {
// $this->defaultLangcode might not be set if we are initializing the
// default language code cache, in which case there is no valid
......
......@@ -266,7 +266,7 @@ public function onBundleDelete($bundle) { }
*/
public function onFieldItemsPurge(EntityInterface $entity, FieldInstanceInterface $instance) {
if ($values = $this->readFieldItemsToPurge($entity, $instance)) {
$items = \Drupal::typedData()->create($instance, $values, $instance->getName(), $entity);
$items = \Drupal::typedDataManager()->create($instance, $values, $instance->getName(), $entity);
$items->delete();
}
$this->purgeFieldItems($entity, $instance);
......
......@@ -95,7 +95,7 @@ public function getConfig() {
*/
public function setConfig($key, $value) {
if ($definition = $this->getConfigDefinition($key)) {
$typed_data = \Drupal::typedData()->create($definition, $value);
$typed_data = \Drupal::typedDataManager()->create($definition, $value);
if ($typed_data->validate()->count() > 0) {
throw new PluginException("The provided configuration value does not pass validation.");
......
......@@ -66,7 +66,7 @@ public function getConstraints() {
// widgets.
$cardinality = $this->getFieldDefinition()->getCardinality();
if ($cardinality != FieldDefinitionInterface::CARDINALITY_UNLIMITED) {
$constraints[] = \Drupal::typedData()
$constraints[] = \Drupal::typedDataManager()
->getValidationConstraintManager()
->create('Count', array(
'max' => $cardinality,
......
......@@ -108,7 +108,7 @@ public function setSetting($setting_name, $value) {
* {@inheritdoc}
*/
public function getPropertyNames() {
return array_keys(\Drupal::typedData()->create($this->getItemDefinition())->getPropertyDefinitions());
return array_keys(\Drupal::typedDataManager()->create($this->getItemDefinition())->getPropertyDefinitions());
}
/**
......
......@@ -32,7 +32,7 @@ public function __construct(DataDefinitionInterface $definition, $name = NULL, T
// with the whole item.
foreach ($this->getPropertyDefinitions() as $name => $definition) {
if ($definition->isComputed()) {
$this->properties[$name] = \Drupal::typedData()->getPropertyInstance($this, $name);
$this->properties[$name] = \Drupal::typedDataManager()->getPropertyInstance($this, $name);
}
}
}
......
......@@ -46,7 +46,7 @@ public function getContextValue() {
public function setContextValue($value) {
// Make sure the value set is a typed data object.
if (!empty($this->contextDefinition['type']) && !$value instanceof TypedDataInterface) {
$value = \Drupal::typedData()->create(new DataDefinition($this->contextDefinition), $value);
$value = \Drupal::typedDataManager()->create(new DataDefinition($this->contextDefinition), $value);
}
parent::setContextValue($value);
}
......
......@@ -28,7 +28,7 @@
* type, is ordered and may contain duplicates. The class used for a list of
* items of a certain type may be specified using the 'list class' key.
*
* @see \Drupal::typedData()
* @see \Drupal::typedDataManager()
* @see \Drupal\Core\TypedData\TypedDataManager::create()
* @see hook_data_type_info_alter()
*
......
......@@ -43,7 +43,7 @@ public function getValue() {
* {@inheritdoc}
*/
public function setValue($value, $notify = TRUE) {
$this->target = \Drupal::typedData()->create($this->getTargetDefinition(), $value);
$this->target = \Drupal::typedDataManager()->create($this->getTargetDefinition(), $value);
// Notify the parent of any changes.
if ($notify && isset($this->parent)) {
$this->parent->onChange($this->name);
......
......@@ -69,7 +69,7 @@ public function getClass() {
else {
// If a list definition is used but no class has been specified, derive
// the default list class from the item type.
$item_type_definition = \Drupal::typedData()
$item_type_definition = \Drupal::typedDataManager()
->getDefinition($this->getItemDefinition()->getDataType());
return $item_type_definition['list_class'];
}
......
......@@ -137,7 +137,7 @@ public function offsetGet($offset) {
* @return \Drupal\Core\TypedData\TypedDataInterface
*/
protected function createItem($offset = 0, $value = NULL) {
return \Drupal::typedData()->getPropertyInstance($this, $offset, $value);
return \Drupal::typedDataManager()->getPropertyInstance($this, $offset, $value);
}
/**
......
......@@ -119,7 +119,7 @@ public function get($property_name) {
$value = $this->values[$property_name];
}
// If the property is unknown, this will throw an exception.
$this->properties[$property_name] = \Drupal::typedData()->getPropertyInstance($this, $property_name, $value);
$this->properties[$property_name] = \Drupal::typedDataManager()->getPropertyInstance($this, $property_name, $value);
}
return $this->properties[$property_name];
}
......
......@@ -73,7 +73,7 @@ public function getPluginId() {
* {@inheritdoc}
*/
public function getPluginDefinition() {
return \Drupal::typedData()->getDefinition($this->definition->getDataType());
return \Drupal::typedDataManager()->getDefinition($this->definition->getDataType());
}
/**
......@@ -113,7 +113,7 @@ public function getString() {
*/
public function getConstraints() {
// @todo: Add the typed data manager as proper dependency.
return \Drupal::typedData()->getConstraints($this->definition);
return \Drupal::typedDataManager()->getConstraints($this->definition);
}
/**
......@@ -121,7 +121,7 @@ public function getConstraints() {
*/
public function validate() {
// @todo: Add the typed data manager as proper dependency.
return \Drupal::typedData()->getValidator()->validate($this);
return \Drupal::typedDataManager()->getValidator()->validate($this);
}
/**
......
......@@ -109,7 +109,7 @@ public function createInstance($data_type, array $configuration) {
* @return \Drupal\Core\TypedData\TypedDataInterface
* The instantiated typed data object.
*
* @see \Drupal::typedData()
* @see \Drupal::typedDataManager()
* @see \Drupal\Core\TypedData\TypedDataManager::getPropertyInstance()
* @see \Drupal\Core\TypedData\Plugin\DataType\Integer
* @see \Drupal\Core\TypedData\Plugin\DataType\Float
......
......@@ -49,7 +49,7 @@ public static function schema(FieldInterface $field) {
* {@inheritdoc}
*/
public function getConstraints() {
$constraint_manager = \Drupal::typedData()->getValidationConstraintManager();
$constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
$constraints = parent::getConstraints();
$constraints[] = $constraint_manager->create('ComplexData', array(
......
......@@ -36,7 +36,7 @@ function field_info_cache_clear() {
entity_info_cache_clear();
// Clear typed data definitions.
\Drupal::typedData()->clearCachedDefinitions();
\Drupal::typedDataManager()->clearCachedDefinitions();
\Drupal::service('plugin.manager.field.field_type')->clearCachedDefinitions();
\Drupal::service('config.factory')->reset();
......
......@@ -128,7 +128,7 @@ public function delete() {
* {@inheritdoc}
*/
public function getConstraints() {
$constraint_manager = \Drupal::typedData()->getValidationConstraintManager();
$constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
$constraints = parent::getConstraints();
$constraints[] = $constraint_manager->create('ComplexData', array(
......
......@@ -46,7 +46,7 @@ class FieldEditForm extends FormBase {
*
* @var \Drupal\Core\TypedData\TypedDataManager
*/
protected $typedData;
protected $typedDataManager;
/**
* {@inheritdoc}
......@@ -62,13 +62,13 @@ public function getFormId() {
* The entity manager.
* @param \Drupal\field\FieldInfo $field_info
* The field info service.
* @param \Drupal\Core\TypedData\TypedDataManager $typed_data
* @param \Drupal\Core\TypedData\TypedDataManager $typed_data_manager
* The typed data manager.
*/
public function __construct(EntityManagerInterface $entity_manager, FieldInfo $field_info, TypedDataManager $typed_data) {
public function __construct(EntityManagerInterface $entity_manager, FieldInfo $field_info, TypedDataManager $typed_data_manager) {
$this->entityManager = $entity_manager;
$this->fieldInfo = $field_info;
$this->typedData = $typed_data;
$this->typedDataManager = $typed_data_manager;
}
/**
......@@ -78,7 +78,7 @@ public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager'),
$container->get('field.info'),
$container->get('typed_data')
$container->get('typed_data_manager')
);
}
......
......@@ -193,7 +193,7 @@ function testFilterFormatAPI() {
*/
function testTypedDataAPI() {
$definition = DataDefinition::create('filter_format');
$data = \Drupal::typedData()->create($definition);
$data = \Drupal::typedDataManager()->create($definition);
$this->assertTrue($data instanceof AllowedValuesInterface, 'Typed data object implements \Drupal\Core\TypedData\AllowedValuesInterface');
......
......@@ -74,7 +74,7 @@ public function isEmpty() {
* {@inheritdoc}
*/
public function getConstraints() {
$constraint_manager = \Drupal::typedData()->getValidationConstraintManager();
$constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
$constraints = parent::getConstraints();
$settings = $this->getFieldSettings();
......
......@@ -62,14 +62,14 @@ public function setUp() {
->method('getPropertyInstance')
->will($this->returnValue($typed_data));
// Set up a mock container as ItemList() will call for the 'typed_data'
// Set up a mock container as ItemList() will call for the 'typed_data_manager'
// service.
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')
->setMethods(array('get'))
->getMock();
$container->expects($this->any())
->method('get')
->with($this->equalTo('typed_data'))
->with($this->equalTo('typed_data_manager'))
->will($this->returnValue($typed_data_manager));
\Drupal::setContainer($container);
......
......@@ -519,13 +519,13 @@ public function getContainedStrings(TypedDataInterface $wrapper, $depth, array &
* Makes sure data types are correctly derived for all entity types.
*/
public function testDataTypes() {
$types = \Drupal::typedData()->getDefinitions();
$types = \Drupal::typedDataManager()->getDefinitions();
foreach (entity_test_entity_types() as $entity_type) {
$this->assertTrue($types['entity:' . $entity_type]['class'], 'Entity data type registed.');
}
// Check bundle types are provided as well.
entity_test_create_bundle('bundle');
$types = \Drupal::typedData()->getDefinitions();
$types = \Drupal::typedDataManager()->getDefinitions();
$this->assertTrue($types['entity:entity_test:bundle']['class'], 'Entity bundle data type registed.');
}
......@@ -539,7 +539,7 @@ public function testEntityConstraintValidation() {
$definition = FieldDefinition::create('entity_reference')
->setLabel('Test entity')
->setSetting('target_type', 'entity_test');
$reference_field_item = \Drupal::TypedData()->create($definition);
$reference_field_item = \Drupal::typedDataManager()->create($definition);
$reference = $reference_field_item->get('entity');
$reference->setValue($entity);
......@@ -565,7 +565,7 @@ public function testEntityConstraintValidation() {
'target_type' => 'node',
'target_bundle' => 'article',
));
$reference_field_item = \Drupal::TypedData()->create($definition);
$reference_field_item = \Drupal::TypedDataManager()->create($definition);
$reference = $reference_field_item->get('entity');
$reference->setValue($node);
$violations = $reference->validate();
......
......@@ -23,7 +23,7 @@ class TypedDataTest extends DrupalUnitTestBase {
*
* @var \Drupal\Core\TypedData\TypedDataManager
*/
protected $typedData;
protected $typedDataManager;
/**
* Modules to enable.
......@@ -44,7 +44,7 @@ public function setUp() {
parent::setup();
$this->installSchema('file', array('file_managed', "file_usage"));
$this->typedData = $this->container->get('typed_data');
$this->typedDataManager = $this->container->get('typed_data_manager');
}
/**
......@@ -56,7 +56,7 @@ protected function createTypedData($definition, $value = NULL, $name = NULL) {
if (is_array($definition)) {
$definition = DataDefinition::create($definition['type']);
}
$data = $this->typedData->create($definition, $value, $name);
$data = $this->typedDataManager->create($definition, $value, $name);
$this->assertTrue($data instanceof \Drupal\Core\TypedData\TypedDataInterface, 'Typed data object is an instance of the typed data interface.');
return $data;
}
......@@ -507,10 +507,10 @@ public function testTypedDataValidation() {
->setConstraints(array(
'Range' => array('min' => 5),
));
$violations = $this->typedData->create($definition, 10)->validate();
$violations = $this->typedDataManager->create($definition, 10)->validate();
$this->assertEqual($violations->count(), 0);
$integer = $this->typedData->create($definition, 1);
$integer = $this->typedDataManager->create($definition, 1);
$violations = $integer->validate();
$this->assertEqual($violations->count(), 1);
......@@ -525,7 +525,7 @@ public function testTypedDataValidation() {
->setConstraints(array(
'Length' => array('min' => 10),
));
$violations = $this->typedData->create($definition, "short")->validate();
$violations = $this->typedDataManager->create($definition, "short")->validate();
$this->assertEqual($violations->count(), 1);
$message = t('This value is too short. It should have %limit characters or more.', array('%limit' => 10));
$this->assertEqual($violations[0]->getMessage(), $message, 'Translated violation message retrieved.');
......@@ -536,46 +536,46 @@ public function testTypedDataValidation() {
'Range' => array('min' => 5),
'Null' => array(),
));
$violations = $this->typedData->create($definition, 10)->validate();
$violations = $this->typedDataManager->create($definition, 10)->validate();
$this->assertEqual($violations->count(), 1);
$violations = $this->typedData->create($definition, 1)->validate();
$violations = $this->typedDataManager->create($definition, 1)->validate();
$this->assertEqual($violations->count(), 2);
// Test validating property containers and make sure the NotNull and Null
// constraints work with typed data containers.
$definition = FieldDefinition::create('integer')
->setConstraints(array('NotNull' => array()));
$field_item = $this->typedData->create($definition, array('value' => 10));
$field_item = $this->typedDataManager->create($definition, array('value' => 10));
$violations = $field_item->validate();
$this->assertEqual($violations->count(), 0);
$field_item = $this->typedData->create($definition, array('value' => 'no integer'));
$field_item = $this->typedDataManager->create($definition, array('value' => 'no integer'));
$violations = $field_item->validate();
$this->assertEqual($violations->count(), 1);
$this->assertEqual($violations[0]->getPropertyPath(), '0.value');
// Test that the field item may not be empty.
$field_item = $this->typedData->create($definition);
$field_item = $this->typedDataManager->create($definition);
$violations = $field_item->validate();
$this->assertEqual($violations->count(), 1);
// Test the Null constraint with typed data containers.
$definition = FieldDefinition::create('float')
->setConstraints(array('Null' => array()));
$field_item = $this->typedData->create($definition, array('value' => 11.5));
$field_item = $this->typedDataManager->create($definition, array('value' => 11.5));
$violations = $field_item->validate();
$this->assertEqual($violations->count(), 1);
$field_item = $this->typedData->create($definition);
$field_item = $this->typedDataManager->create($definition);
$violations = $field_item->validate();
$this->assertEqual($violations->count(), 0);
// Test getting constraint definitions by type.
$definitions = $this->typedData->getValidationConstraintManager()->getDefinitionsByType('entity');
$definitions = $this->typedDataManager->getValidationConstraintManager()->getDefinitionsByType('entity');
$this->assertTrue(isset($definitions['EntityType']), 'Constraint plugin found for type entity.');
$this->assertTrue(isset($definitions['Null']), 'Constraint plugin found for type entity.');
$this->assertTrue(isset($definitions['NotNull']), 'Constraint plugin found for type entity.');
$definitions = $this->typedData->getValidationConstraintManager()->getDefinitionsByType('string');
$definitions = $this->typedDataManager->getValidationConstraintManager()->getDefinitionsByType('string');
$this->assertFalse(isset($definitions['EntityType']), 'Constraint plugin not found for type string.');
$this->assertTrue(isset($definitions['Null']), 'Constraint plugin found for type string.');
$this->assertTrue(isset($definitions['NotNull']), 'Constraint plugin found for type string.');
......@@ -583,17 +583,17 @@ public function testTypedDataValidation() {
// Test automatic 'required' validation.
$definition = DataDefinition::create('integer')
->setRequired(TRUE);
$violations = $this->typedData->create($definition)->validate();
$violations = $this->typedDataManager->create($definition)->validate();
$this->assertEqual($violations->count(), 1);
$violations = $this->typedData->create($definition, 0)->validate();
$violations = $this->typedDataManager->create($definition, 0)->validate();
$this->assertEqual($violations->count(), 0);
// Test validating a list of a values and make sure property paths starting
// with "0" are created.
$definition = FieldDefinition::create('integer');
$violations = $this->typedData->create($definition, array(array('value' => 10)))->validate();
$violations = $this->typedDataManager->create($definition, array(array('value' => 10)))->validate();
$this->assertEqual($violations->count(), 0);
$violations = $this->typedData->create($definition, array(array('value' => 'string')))->validate();
$violations = $this->typedDataManager->create($definition, array(array('value' => 'string')))->validate();
$this->assertEqual($violations->count(), 1);
$this->assertEqual($violations[0]->getInvalidValue(), 'string');
......
......@@ -69,7 +69,7 @@ public function isEmpty() {
* {@inheritdoc}
*/
public function getConstraints() {
$constraint_manager = \Drupal::typedData()->getValidationConstraintManager();
$constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
$constraints = parent::getConstraints();
$max_length = 256;
......
......@@ -55,7 +55,7 @@ public static function schema(FieldInterface $field) {
* {@inheritdoc}
*/
public function getConstraints() {
$constraint_manager = \Drupal::typedData()->getValidationConstraintManager();
$constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
$constraints = parent::getConstraints();
if ($max_length = $this->getFieldSetting('max_length')) {
......
......@@ -337,7 +337,7 @@ function user_load_by_name($name) {
function user_validate_name($name) {
$definition = DataDefinition::create('string')
->setConstraints(array('UserName' => array()));
$data = \Drupal::typedData()->create($definition);
$data = \Drupal::typedDataManager()->create($definition);
$data->setValue($name);
$violations = $data->validate();
if (count($violations) > 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment