diff --git a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php index 180003c..f91aca6 100644 --- a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php +++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php @@ -122,7 +122,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] = $this->typedDataManager->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 f54f8ed..7e4161a 100644 --- a/core/lib/Drupal/Core/TypedData/TypedData.php +++ b/core/lib/Drupal/Core/TypedData/TypedData.php @@ -8,6 +8,9 @@ namespace Drupal\Core\TypedData; use Drupal\Component\Plugin\PluginInspectionInterface; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\Core\TypedData\TypedDataManager; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * The abstract base class for typed data. @@ -15,7 +18,7 @@ * Classes deriving from this base class have to declare $value * or override getValue() or setValue(). */ -abstract class TypedData implements TypedDataInterface, PluginInspectionInterface { +abstract class TypedData implements TypedDataInterface, PluginInspectionInterface, ContainerFactoryPluginInterface { /** * The data definition. @@ -39,6 +42,13 @@ protected $parent; /** + * The typed data plugin manager. + * + * @var \Drupal\Core\TypedData\TypedDataManager + */ + protected $typedDataManager; + + /** * Constructs a TypedData object given its definition and context. * * @param array $definition @@ -49,13 +59,43 @@ * @param \Drupal\Core\TypedData\TypedDataInterface $parent * (optional) The parent object of the data property, or NULL if it is the * root of a typed data tree. Defaults to NULL. + * @param \Drupal\Core\TypedData\TypedDataManager $typed_data_manager + * The typed data plugin manager. * * @see Drupal\Core\TypedData\TypedDataManager::create() */ - public function __construct(array $definition, $name = NULL, TypedDataInterface $parent = NULL) { + public function __construct(array $definition, $name = NULL, TypedDataInterface $parent = NULL, TypedDataManager $typed_data_manager) { $this->definition = $definition; $this->parent = $parent; $this->name = $name; + $this->typedDataManager = $typed_data_manager; + } + + /** + * Creates an instance of the plugin. + * + * @param \Symfony\Component\DependencyInjection\ContainerInterface $container + * The container to pull out services used in the plugin. + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin ID for the plugin instance. + * @param array $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\TypedData\TypedDataInterface $parent + * (optional) The parent object of the data property, or NULL if it is the + * root of a typed data tree. Defaults to NULL. + * + * @return static + * Returns an instance of this plugin. + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition, TypedDataInterface $parent = NULL) { + return new static( + $configuration, + $plugin_id, + $parent, + $container->get('typed_data') + ); } /** @@ -76,7 +116,7 @@ public function getPluginId() { * {@inheritdoc} */ public function getPluginDefinition() { - return \Drupal::typedData()->getDefinition($this->definition['type']); + return $this->typedDataManager->getDefinition($this->definition['type']); } /** @@ -115,16 +155,14 @@ public function getString() { * Implements \Drupal\Core\TypedData\TypedDataInterface::getConstraints(). */ public function getConstraints() { - // @todo: Add the typed data manager as proper dependency. - return \Drupal::typedData()->getConstraints($this->definition); + return $this->typedDataManager->getConstraints($this->definition); } /** * Implements \Drupal\Core\TypedData\TypedDataInterface::validate(). */ public function validate() { - // @todo: Add the typed data manager as proper dependency. - return \Drupal::typedData()->getValidator()->validate($this); + return $this->typedDataManager()->getValidator()->validate($this); } /** diff --git a/core/modules/text/lib/Drupal/text/TextProcessed.php b/core/modules/text/lib/Drupal/text/TextProcessed.php index 30f9be3..9a1910f 100644 --- a/core/modules/text/lib/Drupal/text/TextProcessed.php +++ b/core/modules/text/lib/Drupal/text/TextProcessed.php @@ -7,14 +7,10 @@ namespace Drupal\text; -use Drupal\Component\Utility\String; -use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\TypedData\TypedDataInterface; use Drupal\Core\TypedData\TypedData; use Drupal\Core\TypedData\ReadOnlyException; -use Drupal\field\FieldInfo; use InvalidArgumentException; -use Symfony\Component\DependencyInjection\ContainerInterface; /** * A computed property for processing text with a format. @@ -22,7 +18,7 @@ * Required settings (below the definition's 'settings' key) are: * - text source: The text property containing the to be processed text. */ -class TextProcessed extends TypedData implements ContainerFactoryPluginInterface { +class TextProcessed extends TypedData { /** * The text property. @@ -39,17 +35,9 @@ class TextProcessed extends TypedData implements ContainerFactoryPluginInterface protected $format; /** - * The FieldInfo service. - * - * @var \Drupal\field\FieldInfo - */ - protected $fieldInfo; - - /** * Overrides TypedData::__construct(). */ - public function __construct(array $definition, $name = NULL, TypedDataInterface $parent = NULL, FieldInfo $field_info = NULL) { - $this->fieldInfo = $field_info; + public function __construct(array $definition, $name = NULL, TypedDataInterface $parent = NULL) { parent::__construct($definition, $name, $parent); if (!isset($definition['settings']['text source'])) { @@ -58,13 +46,6 @@ public function __construct(array $definition, $name = NULL, TypedDataInterface } /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition, TypedDataInterface $parent = NULL) { - return new static($configuration, $plugin_id, $parent, $container->get('field.info')); - } - - /** * Overrides TypedData::setContext(). */ public function setContext($name = NULL, TypedDataInterface $parent = NULL) { @@ -86,16 +67,14 @@ public function getValue($langcode = NULL) { $field = $this->parent->getParent(); $entity = $field->getParent(); - $instance = $this->fieldInfo->getInstance($entity->entityType(), $field->getName(), $entity->bundle()); + $instance = field_info_instance($entity->entityType(), $field->getName(), $entity->bundle()); if (!empty($instance['settings']['text_processing']) && $this->format->getValue()) { - // @todo Replace when check_markup() is a service provided by filter - // module. return check_markup($this->text->getValue(), $this->format->getValue(), $entity->language()->id); } else { // If no format is available, still make sure to sanitize the text. - return String::checkPlain($this->text->getValue()); + return check_plain($this->text->getValue()); } }