summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2013-05-27 23:00:35 (GMT)
committerAlex Pott2013-05-27 23:00:35 (GMT)
commit521e1e5946950b2a91498a1be7453fb8e69eff21 (patch)
tree92a35478fdfc8d98f9f1e27a0de1de93efcbd7e6
parentb0f09bb623610e35dd2594dcd0300e8bc9c71d2b (diff)
Issue #1957158 by abghosh82, JacobSanford: Replace typed_data() with Drupal::typedData().
-rw-r--r--core/includes/bootstrap.inc21
-rw-r--r--core/lib/Drupal/Core/Entity/EntityNG.php5
-rw-r--r--core/lib/Drupal/Core/Entity/EntityStorageControllerInterface.php4
-rw-r--r--core/lib/Drupal/Core/Entity/Field/FieldItemBase.php2
-rw-r--r--core/lib/Drupal/Core/Executable/ExecutablePluginBase.php2
-rw-r--r--core/lib/Drupal/Core/Plugin/Context/Context.php2
-rw-r--r--core/lib/Drupal/Core/TypedData/ItemList.php2
-rw-r--r--core/lib/Drupal/Core/TypedData/Type/Map.php2
-rw-r--r--core/lib/Drupal/Core/TypedData/TypedData.php4
-rw-r--r--core/lib/Drupal/Core/TypedData/TypedDataManager.php2
-rw-r--r--core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php8
-rw-r--r--core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php4
-rw-r--r--core/modules/system/system.api.php2
13 files changed, 19 insertions, 41 deletions
diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index 6541350..4c9df06 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -2289,27 +2289,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 1f1d3c6..2ccbfa8 100644
--- a/core/lib/Drupal/Core/Entity/EntityNG.php
+++ b/core/lib/Drupal/Core/Entity/EntityNG.php
@@ -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;
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 @@ 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);
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 @@ 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);
}
}
}
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 @@ 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.");
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 @@ 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);
}
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 @@ 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);
}
/**
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 @@ 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];
}
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 @@ 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);
}
/**
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 @@ 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
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 0b1f337..6b74ce3 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php
@@ -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);
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 @@ 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();
diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php
index 308cef1..d4e72c0 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()
*/