diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 7dc75f5..6ccbe55 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2373,27 +2373,6 @@ function 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. * * @param string $new_prefix diff --git a/core/lib/Drupal/Core/Entity/EntityNG.php b/core/lib/Drupal/Core/Entity/EntityNG.php index d9d17c2..c8d60ae 100644 --- a/core/lib/Drupal/Core/Entity/EntityNG.php +++ b/core/lib/Drupal/Core/Entity/EntityNG.php @@ -169,8 +169,7 @@ protected function getTranslatedField($property_name, $langcode) { 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]; @@ -316,7 +315,7 @@ public function getTranslation($langcode, $strict = TRUE) { '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; diff --git a/core/lib/Drupal/Core/Entity/EntityStorageControllerInterface.php b/core/lib/Drupal/Core/Entity/EntityStorageControllerInterface.php index 377a002..365212a 100644 --- a/core/lib/Drupal/Core/Entity/EntityStorageControllerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityStorageControllerInterface.php @@ -147,7 +147,7 @@ public function save(EntityInterface $entity); * @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 @@ public function save(EntityInterface $entity); * via field.module. Defaults to FALSE. * * @see Drupal\Core\TypedData\TypedDataManager::create() - * @see typed_data() + * @see \Drupal::typedData() */ public function getFieldDefinitions(array $constraints); diff --git a/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php b/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php index 2c3feef..cb25ab3 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldItemBase.php @@ -31,7 +31,7 @@ public function __construct(array $definition, $name = NULL, TypedDataInterface // 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); } } } diff --git a/core/lib/Drupal/Core/Executable/ExecutablePluginBase.php b/core/lib/Drupal/Core/Executable/ExecutablePluginBase.php index 426e8b8..b13aca0 100644 --- a/core/lib/Drupal/Core/Executable/ExecutablePluginBase.php +++ b/core/lib/Drupal/Core/Executable/ExecutablePluginBase.php @@ -95,7 +95,7 @@ public function getConfig() { */ 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."); diff --git a/core/lib/Drupal/Core/Plugin/Context/Context.php b/core/lib/Drupal/Core/Plugin/Context/Context.php index 9055d12..cc9f355 100644 --- a/core/lib/Drupal/Core/Plugin/Context/Context.php +++ b/core/lib/Drupal/Core/Plugin/Context/Context.php @@ -49,7 +49,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 = typed_data()->create($this->contextDefinition, $value); + $value = \Drupal::typedData()->create($this->contextDefinition, $value); } parent::setContextValue($value); } diff --git a/core/lib/Drupal/Core/TypedData/ItemList.php b/core/lib/Drupal/Core/TypedData/ItemList.php index 88af366..ee69432 100644 --- a/core/lib/Drupal/Core/TypedData/ItemList.php +++ b/core/lib/Drupal/Core/TypedData/ItemList.php @@ -133,7 +133,7 @@ public function offsetGet($offset) { * @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); } /** diff --git a/core/lib/Drupal/Core/TypedData/Type/Map.php b/core/lib/Drupal/Core/TypedData/Type/Map.php index da20e96..43e3790 100644 --- a/core/lib/Drupal/Core/TypedData/Type/Map.php +++ b/core/lib/Drupal/Core/TypedData/Type/Map.php @@ -116,7 +116,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] = typed_data()->getPropertyInstance($this, $property_name, $value); + $this->properties[$property_name] = \Drupal::typedData()->getPropertyInstance($this, $property_name, $value); } return $this->properties[$property_name]; } diff --git a/core/lib/Drupal/Core/TypedData/TypedData.php b/core/lib/Drupal/Core/TypedData/TypedData.php index e9558f3..7ea33f0 100644 --- a/core/lib/Drupal/Core/TypedData/TypedData.php +++ b/core/lib/Drupal/Core/TypedData/TypedData.php @@ -100,7 +100,7 @@ public function getString() { */ 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 @@ public function getConstraints() { */ public function validate() { // @todo: Add the typed data manager as proper dependency. - return typed_data()->getValidator()->validate($this); + return \Drupal::typedData()->getValidator()->validate($this); } /** diff --git a/core/lib/Drupal/Core/TypedData/TypedDataManager.php b/core/lib/Drupal/Core/TypedData/TypedDataManager.php index 195e32d..6e6d001 100644 --- a/core/lib/Drupal/Core/TypedData/TypedDataManager.php +++ b/core/lib/Drupal/Core/TypedData/TypedDataManager.php @@ -130,7 +130,7 @@ public function createInstance($plugin_id, array $configuration, $name = NULL, $ * @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 diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php index 29e1462..df9aa40 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php @@ -357,7 +357,7 @@ protected function assertIntrospection($entity_type) { ), '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.'); @@ -477,7 +477,7 @@ protected function assertDataStructureInterfaces($entity_type) { ), '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 @@ -538,7 +538,7 @@ public function testEntityConstraintValidation() { ), '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(); @@ -566,7 +566,7 @@ public function testEntityConstraintValidation() { ), '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); diff --git a/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php b/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php index f23dde7..28c5d5a 100644 --- a/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php @@ -42,7 +42,7 @@ public function setUp() { 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 @@ protected function createTypedData($definition, $value = NULL, $name = NULL) { // 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(); diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index aa79df9..df034d2 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -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() */