Issue #1957158 by abghosh82, JacobSanford: Replace typed_data() with Drupal::typedData().
parent
b0f09bb623
commit
521e1e5946
|
@ -2288,27 +2288,6 @@ function state() {
|
|||
return drupal_container()->get('keyvalue')->get('state');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the typed data manager service.
|
||||
*
|
||||
* Use the typed data manager service for creating typed data objects.
|
||||
*
|
||||
* @see Drupal\Core\TypedData\TypedDataManager::create()
|
||||
*
|
||||
* @return Drupal\Core\TypedData\TypedDataManager
|
||||
*/
|
||||
function typed_data() {
|
||||
// Use the advanced drupal_static() pattern, since this is called very often.
|
||||
static $drupal_static_fast;
|
||||
if (!isset($drupal_static_fast)) {
|
||||
$drupal_static_fast['manager'] = &drupal_static(__FUNCTION__);
|
||||
}
|
||||
if (!isset($drupal_static_fast['manager'])) {
|
||||
$drupal_static_fast['manager'] = drupal_container()->get('typed_data');
|
||||
}
|
||||
return $drupal_static_fast['manager'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the test prefix if this is an internal request from SimpleTest.
|
||||
*
|
||||
|
|
|
@ -170,8 +170,7 @@ class EntityNG extends Entity {
|
|||
if (isset($this->values[$property_name][$langcode])) {
|
||||
$value = $this->values[$property_name][$langcode];
|
||||
}
|
||||
// @todo: Make entities implement the TypedDataInterface.
|
||||
$this->fields[$property_name][$langcode] = typed_data()->getPropertyInstance($this, $property_name, $value);
|
||||
$this->fields[$property_name][$langcode] = \Drupal::typedData()->getPropertyInstance($this, $property_name, $value);
|
||||
}
|
||||
}
|
||||
return $this->fields[$property_name][$langcode];
|
||||
|
@ -317,7 +316,7 @@ class EntityNG extends Entity {
|
|||
'bundle' => $this->bundle(),
|
||||
),
|
||||
);
|
||||
$translation = typed_data()->create($translation_definition, $fields);
|
||||
$translation = \Drupal::typedData()->create($translation_definition, $fields);
|
||||
$translation->setStrictMode($strict);
|
||||
$translation->setContext('@' . $langcode, $this);
|
||||
return $translation;
|
||||
|
|
|
@ -147,7 +147,7 @@ interface EntityStorageControllerInterface {
|
|||
* @return array
|
||||
* An array of field definitions of entity fields, keyed by field
|
||||
* name. In addition to the typed data definition keys as described at
|
||||
* typed_data()->create() the follow keys are supported:
|
||||
* \Drupal::typedData()->create() the follow keys are supported:
|
||||
* - queryable: Whether the field is queryable via QueryInterface.
|
||||
* Defaults to TRUE if 'computed' is FALSE or not set, to FALSE otherwise.
|
||||
* - translatable: Whether the field is translatable. Defaults to FALSE.
|
||||
|
@ -155,7 +155,7 @@ interface EntityStorageControllerInterface {
|
|||
* via field.module. Defaults to FALSE.
|
||||
*
|
||||
* @see Drupal\Core\TypedData\TypedDataManager::create()
|
||||
* @see typed_data()
|
||||
* @see \Drupal::typedData()
|
||||
*/
|
||||
public function getFieldDefinitions(array $constraints);
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ abstract class FieldItemBase extends Map implements FieldItemInterface {
|
|||
// with the whole item.
|
||||
foreach ($this->getPropertyDefinitions() as $name => $definition) {
|
||||
if (!empty($definition['computed'])) {
|
||||
$this->properties[$name] = typed_data()->getPropertyInstance($this, $name);
|
||||
$this->properties[$name] = \Drupal::typedData()->getPropertyInstance($this, $name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ abstract class ExecutablePluginBase extends ContextAwarePluginBase implements Ex
|
|||
*/
|
||||
public function setConfig($key, $value) {
|
||||
if ($definition = $this->getConfigDefinition($key)) {
|
||||
$typed_data = typed_data()->create($definition, $value);
|
||||
$typed_data = \Drupal::typedData()->create($definition, $value);
|
||||
|
||||
if ($typed_data->validate()->count() > 0) {
|
||||
throw new PluginException("The provided configuration value does not pass validation.");
|
||||
|
|
|
@ -49,7 +49,7 @@ class Context extends ComponentContext {
|
|||
public function setContextValue($value) {
|
||||
// Make sure the value set is a typed data object.
|
||||
if (!empty($this->contextDefinition['type']) && !$value instanceof TypedDataInterface) {
|
||||
$value = typed_data()->create($this->contextDefinition, $value);
|
||||
$value = \Drupal::typedData()->create($this->contextDefinition, $value);
|
||||
}
|
||||
parent::setContextValue($value);
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ class ItemList extends TypedData implements \IteratorAggregate, ListInterface {
|
|||
* @return \Drupal\Core\TypedData\TypedDataInterface
|
||||
*/
|
||||
protected function createItem($offset = 0, $value = NULL) {
|
||||
return typed_data()->getPropertyInstance($this, $offset, $value);
|
||||
return \Drupal::typedData()->getPropertyInstance($this, $offset, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -116,7 +116,7 @@ class Map extends TypedData implements \IteratorAggregate, ComplexDataInterface
|
|||
$value = $this->values[$property_name];
|
||||
}
|
||||
// If the property is unknown, this will throw an exception.
|
||||
$this->properties[$property_name] = typed_data()->getPropertyInstance($this, $property_name, $value);
|
||||
$this->properties[$property_name] = \Drupal::typedData()->getPropertyInstance($this, $property_name, $value);
|
||||
}
|
||||
return $this->properties[$property_name];
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ abstract class TypedData implements TypedDataInterface {
|
|||
*/
|
||||
public function getConstraints() {
|
||||
// @todo: Add the typed data manager as proper dependency.
|
||||
return typed_data()->getConstraints($this->definition);
|
||||
return \Drupal::typedData()->getConstraints($this->definition);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -108,7 +108,7 @@ abstract class TypedData implements TypedDataInterface {
|
|||
*/
|
||||
public function validate() {
|
||||
// @todo: Add the typed data manager as proper dependency.
|
||||
return typed_data()->getValidator()->validate($this);
|
||||
return \Drupal::typedData()->getValidator()->validate($this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -130,7 +130,7 @@ class TypedDataManager extends PluginManagerBase {
|
|||
* @return \Drupal\Core\TypedData\TypedDataInterface
|
||||
* The instantiated typed data object.
|
||||
*
|
||||
* @see typed_data()
|
||||
* @see \Drupal::typedData()
|
||||
* @see \Drupal\Core\TypedData\TypedDataManager::getPropertyInstance()
|
||||
* @see \Drupal\Core\TypedData\Type\Integer
|
||||
* @see \Drupal\Core\TypedData\Type\Float
|
||||
|
|
|
@ -358,7 +358,7 @@ class EntityFieldTest extends EntityUnitTestBase {
|
|||
),
|
||||
'label' => 'Test entity',
|
||||
);
|
||||
$wrapped_entity = typed_data()->create($definition);
|
||||
$wrapped_entity = $this->container->get('typed_data')->create($definition);
|
||||
$definitions = $wrapped_entity->getPropertyDefinitions($definition);
|
||||
$this->assertEqual($definitions['name']['type'], 'string_field', $entity_type .': Name field found.');
|
||||
$this->assertEqual($definitions['user_id']['type'], 'entity_reference_field', $entity_type .': User field found.');
|
||||
|
@ -478,7 +478,7 @@ class EntityFieldTest extends EntityUnitTestBase {
|
|||
),
|
||||
'label' => 'Test entity',
|
||||
);
|
||||
$wrapped_entity = typed_data()->create($entity_definition, $entity);
|
||||
$wrapped_entity = $this->container->get('typed_data')->create($entity_definition, $entity);
|
||||
|
||||
// Test using the whole tree of typed data by navigating through the tree of
|
||||
// contained properties and getting all contained strings, limited by a
|
||||
|
@ -539,7 +539,7 @@ class EntityFieldTest extends EntityUnitTestBase {
|
|||
),
|
||||
'label' => 'Test entity',
|
||||
);
|
||||
$wrapped_entity = typed_data()->create($entity_definition, $entity);
|
||||
$wrapped_entity = $this->container->get('typed_data')->create($entity_definition, $entity);
|
||||
|
||||
// Test validation the typed data object.
|
||||
$violations = $wrapped_entity->validate();
|
||||
|
@ -567,7 +567,7 @@ class EntityFieldTest extends EntityUnitTestBase {
|
|||
),
|
||||
'label' => 'Test node',
|
||||
);
|
||||
$wrapped_entity = typed_data()->create($entity_definition, $node);
|
||||
$wrapped_entity = $this->container->get('typed_data')->create($entity_definition, $node);
|
||||
|
||||
$violations = $wrapped_entity->validate();
|
||||
$this->assertEqual($violations->count(), 1);
|
||||
|
|
|
@ -42,7 +42,7 @@ class TypedDataTest extends DrupalUnitTestBase {
|
|||
parent::setup();
|
||||
|
||||
$this->installSchema('file', array('file_managed', "file_usage"));
|
||||
$this->typedData = typed_data();
|
||||
$this->typedData = $this->container->get('typed_data');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,7 +54,7 @@ class TypedDataTest extends DrupalUnitTestBase {
|
|||
// Save the type that was passed in so we can compare with it later.
|
||||
$type = $definition['type'];
|
||||
// Construct the object.
|
||||
$data = typed_data()->create($definition, $value, $name);
|
||||
$data = $this->typedData->create($definition, $value, $name);
|
||||
// Assert the definition of the wrapper.
|
||||
$this->assertTrue($data instanceof \Drupal\Core\TypedData\TypedDataInterface, 'Typed data object is an instance of the typed data interface.');
|
||||
$definition = $data->getDefinition();
|
||||
|
|
|
@ -167,7 +167,7 @@ function hook_cron() {
|
|||
* - constraints: An array of validation constraints for this type. See
|
||||
* \Drupal\Core\TypedData\TypedDataManager::getConstraints() for details.
|
||||
*
|
||||
* @see typed_data()
|
||||
* @see \Drupal::typedData()
|
||||
* @see Drupal\Core\TypedData\TypedDataManager::create()
|
||||
* @see hook_data_type_info_alter()
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue