diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php index d2db1a6..12a6bbf 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php @@ -97,7 +97,7 @@ function testNodeTokenReplacement() { // Generate and test sanitized token - use full body as expected value. $tests = array(); - $tests['[node:summary]'] = $node->body->summary_processed; + $tests['[node:summary]'] = $node->body->processed; // Test to make sure that we generated something for each token. $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated for node without a summary.'); diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php index ee3b13d..5f28954 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItemBase.php @@ -71,25 +71,37 @@ public function isEmpty() { * {@inheritdoc} */ public function prepareCache() { - // Where possible, generate the sanitized version of each textual property - // (e.g., 'value', 'summary') within this field item early so that it is - // cached in the field cache. This avoids the need to look up the sanitized - // value in the filter cache separately. + // Where possible, generate the processed (sanitized) version of each + // textual property (e.g., 'value', 'summary') within this field item early + // so that it is cached in the field cache. This avoids the need to look up + // the sanitized value in the filter cache separately. $text_processing = $this->getFieldSetting('text_processing'); if (!$text_processing || filter_format_allowcache($this->get('format')->getValue())) { - $itemBC = $this->getValue(); - $langcode = $this->getParent()->getParent()->language()->id; - // The properties that need sanitizing are the ones that are the 'text - // source' of a TextProcessed computed property. - // @todo Clean up this mess by making the TextProcessed property type - // support its own cache integration: https://drupal.org/node/2026339. foreach ($this->getPropertyDefinitions() as $property => $definition) { if (isset($definition['class']) && ($definition['class'] == '\Drupal\text\TextProcessed')) { - // Calculate the processed values, so that it can be cached later on. $this->get($property)->getValue(); } } } } + /** + * @param $property_name + */ + public function onChange($property_name) { + // Notify the parent of changes. + if (isset($this->parent)) { + $this->parent->onChange($this->name); + } + + // Unset processed properties that are affected by the change. + foreach ($this->getPropertyDefinitions() as $property => $definition) { + if (isset($definition['class']) && ($definition['class'] == '\Drupal\text\TextProcessed')) { + if ($property_name == 'format' || (isset($definition['settings']['text source']) && $definition['settings']['text source'] == $property_name)) { + $this->get($property)->setValue(NULL); + } + } + } + } + } diff --git a/core/modules/text/lib/Drupal/text/TextProcessed.php b/core/modules/text/lib/Drupal/text/TextProcessed.php index 192eacd..f570b42 100644 --- a/core/modules/text/lib/Drupal/text/TextProcessed.php +++ b/core/modules/text/lib/Drupal/text/TextProcessed.php @@ -23,9 +23,9 @@ class TextProcessed extends TypedData { /** * Cached processed text. * - * @var string|false + * @var string|null */ - protected $processed = FALSE; + protected $processed = NULL; /** * Overrides TypedData::__construct(). @@ -39,34 +39,20 @@ public function __construct(array $definition, $name = NULL, TypedDataInterface } /** - * Overrides TypedData::setContext(). - */ - public function setContext($name = NULL, TypedDataInterface $parent = NULL) { - parent::setContext($name, $parent); - if (isset($parent)) { - $this->text = $parent->{($this->definition['settings']['text source'])}; - $this->format = $parent->format; - } - } - - /** * Implements \Drupal\Core\TypedData\TypedDataInterface::getValue(). */ public function getValue($langcode = NULL) { - if ($this->processed !== FALSE) { + if ($this->processed !== NULL) { return $this->processed; } - - if (empty($this->definition['settings']['text source'])) { - throw new InvalidArgumentException('Computed properties require context for computation.'); - } $text = $this->parent->{($this->definition['settings']['text source'])}; $field = $this->parent->getParent(); $entity = $field->getParent(); - $instance = field_info_instance($entity->entityType(), $field->getName(), $entity->bundle()); - if (!empty($instance['settings']['text_processing']) && $this->parent->format) { + if ($field->getFieldDefinition()->getFieldSetting('text_processing') && $this->parent->format) { + // @todo: The entity language might not be the correct language to use, + // fix in https://drupal.org/node/2061331. $this->processed = check_markup($text, $this->parent->format, $entity->language()->id); } else { @@ -81,8 +67,10 @@ public function getValue($langcode = NULL) { * Implements \Drupal\Core\TypedData\TypedDataInterface::setValue(). */ public function setValue($value, $notify = TRUE) { - if (isset($value)) { - $this->processed = $value; + $this->processed = $value; + // Notify the parent of any changes. + if ($notify && isset($this->parent)) { + $this->parent->onChange($this->name); } }