diff --git a/core/lib/Drupal/Core/TypedData/TypedDataManager.php b/core/lib/Drupal/Core/TypedData/TypedDataManager.php index f217fa5..671e0b3 100644 --- a/core/lib/Drupal/Core/TypedData/TypedDataManager.php +++ b/core/lib/Drupal/Core/TypedData/TypedDataManager.php @@ -93,7 +93,12 @@ public function createInstance($plugin_id, array $configuration, $name = NULL, $ if (!isset($class)) { throw new PluginException(sprintf('The plugin (%s) did not specify an instance class.', $plugin_id)); } - return new $class($configuration, $name, $parent); + if (class_implements($class, '\Drupal\Core\Plugin\ContainerFactoryPluginInterface')) { + return $class::create(\Drupal::getContainer(), $configuration, $name, $type_definition, $parent); + } + else { + return new $class($configuration, $name, $parent); + } } /** diff --git a/core/modules/text/lib/Drupal/text/TextProcessed.php b/core/modules/text/lib/Drupal/text/TextProcessed.php index 9a1910f..30f9be3 100644 --- a/core/modules/text/lib/Drupal/text/TextProcessed.php +++ b/core/modules/text/lib/Drupal/text/TextProcessed.php @@ -7,10 +7,14 @@ 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. @@ -18,7 +22,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 { +class TextProcessed extends TypedData implements ContainerFactoryPluginInterface { /** * The text property. @@ -35,9 +39,17 @@ class TextProcessed extends TypedData { protected $format; /** + * The FieldInfo service. + * + * @var \Drupal\field\FieldInfo + */ + protected $fieldInfo; + + /** * Overrides TypedData::__construct(). */ - public function __construct(array $definition, $name = NULL, TypedDataInterface $parent = NULL) { + public function __construct(array $definition, $name = NULL, TypedDataInterface $parent = NULL, FieldInfo $field_info = NULL) { + $this->fieldInfo = $field_info; parent::__construct($definition, $name, $parent); if (!isset($definition['settings']['text source'])) { @@ -46,6 +58,13 @@ 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) { @@ -67,14 +86,16 @@ public function getValue($langcode = NULL) { $field = $this->parent->getParent(); $entity = $field->getParent(); - $instance = field_info_instance($entity->entityType(), $field->getName(), $entity->bundle()); + $instance = $this->fieldInfo->getInstance($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 check_plain($this->text->getValue()); + return String::checkPlain($this->text->getValue()); } }