Commit 855f3b9f authored by catch's avatar catch

Issue #2809237 by dmitryl, alexpott, iampuma, muschpusch, louisnagtegaal,...

Issue #2809237 by dmitryl, alexpott, iampuma, muschpusch, louisnagtegaal, twfahey, aburrows, Mike Lewis, nickmans, borisson_, jcnventura: Properly deprecate AllowedTagsXssTrait

(cherry picked from commit 3791e77a71ccd14e61e1e2d10c9a1e306abee629)
parent a068f00e
......@@ -30,6 +30,7 @@ trait AllowedTagsXssTrait {
* valid UTF-8.
*/
public function fieldFilterXss($string) {
@trigger_error(__METHOD__ . ' is deprecated in drupal:8.0.0 and is removed in drupal:9.0.0. Use \Drupal\Core\Field\FieldFilteredMarkup::create() instead.', E_USER_DEPRECATED);
return FieldFilteredMarkup::create($string);
}
......@@ -37,6 +38,7 @@ public function fieldFilterXss($string) {
* Returns a list of tags allowed by AllowedTagsXssTrait::fieldFilterXss().
*/
public function allowedTags() {
@trigger_error(__METHOD__ . ' is deprecated in drupal:8.0.0 and is removed in drupal:9.0.0. Use \Drupal\Core\Field\FieldFilteredMarkup::allowedTags() instead.', E_USER_DEPRECATED);
return FieldFilteredMarkup::allowedTags();
}
......@@ -44,6 +46,7 @@ public function allowedTags() {
* Returns a human-readable list of allowed tags for display in help texts.
*/
public function displayAllowedTags() {
@trigger_error(__METHOD__ . ' is deprecated in drupal:8.0.0 and is removed in drupal:9.0.0. Use \Drupal\Core\Field\FieldFilteredMarkup::displayAllowedTags() instead.', E_USER_DEPRECATED);
return FieldFilteredMarkup::displayAllowedTags();
}
......
......@@ -2,6 +2,7 @@
namespace Drupal\options\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldFilteredMarkup;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition;
......@@ -55,7 +56,7 @@ protected function allowedValuesDescription() {
$description .= '<br/>' . t('The label is optional: if a line contains a single number, it will be used as key and label.');
$description .= '<br/>' . t('Lists of labels are also accepted (one label per line), only if the field does not hold any values yet. Numeric keys will be automatically generated from the positions in the list.');
$description .= '</p>';
$description .= '<p>' . t('Allowed HTML tags in labels: @tags', ['@tags' => $this->displayAllowedTags()]) . '</p>';
$description .= '<p>' . t('Allowed HTML tags in labels: @tags', ['@tags' => FieldFilteredMarkup::displayAllowedTags()]) . '</p>';
return $description;
}
......
......@@ -2,6 +2,7 @@
namespace Drupal\options\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldFilteredMarkup;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition;
......@@ -55,7 +56,7 @@ protected function allowedValuesDescription() {
$description .= '<br/>' . t('The label is optional: if a line contains a single number, it will be used as key and label.');
$description .= '<br/>' . t('Lists of labels are also accepted (one label per line), only if the field does not hold any values yet. Numeric keys will be automatically generated from the positions in the list.');
$description .= '</p>';
$description .= '<p>' . t('Allowed HTML tags in labels: @tags', ['@tags' => $this->displayAllowedTags()]) . '</p>';
$description .= '<p>' . t('Allowed HTML tags in labels: @tags', ['@tags' => FieldFilteredMarkup::displayAllowedTags()]) . '</p>';
return $description;
}
......
......@@ -2,6 +2,7 @@
namespace Drupal\options\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldFilteredMarkup;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition;
......@@ -56,7 +57,7 @@ protected function allowedValuesDescription() {
$description .= '<br/>' . t('The key is the stored value. The label will be used in displayed values and edit forms.');
$description .= '<br/>' . t('The label is optional: if a line contains a single string, it will be used as key and label.');
$description .= '</p>';
$description .= '<p>' . t('Allowed HTML tags in labels: @tags', ['@tags' => $this->displayAllowedTags()]) . '</p>';
$description .= '<p>' . t('Allowed HTML tags in labels: @tags', ['@tags' => FieldFilteredMarkup::displayAllowedTags()]) . '</p>';
return $description;
}
......
<?php
namespace Drupal\Tests\Core\Field;
use Drupal\Core\Field\AllowedTagsXssTrait;
use Drupal\Core\Field\FieldFilteredMarkup;
use Drupal\Tests\UnitTestCase;
/**
* Tests AllowedTagsXssTrait.
*
* @group field
* @group legacy
*/
class AllowedTagsXssTraitDeprecateTest extends UnitTestCase {
/**
* @expectedDeprecation Drupal\Core\Field\AllowedTagsXssTrait::fieldFilterXss is deprecated in drupal:8.0.0 and is removed in drupal:9.0.0. Use \Drupal\Core\Field\FieldFilteredMarkup::create() instead.
* @expectedDeprecation Drupal\Core\Field\AllowedTagsXssTrait::allowedTags is deprecated in drupal:8.0.0 and is removed in drupal:9.0.0. Use \Drupal\Core\Field\FieldFilteredMarkup::allowedTags() instead.
* @expectedDeprecation Drupal\Core\Field\AllowedTagsXssTrait::displayAllowedTags is deprecated in drupal:8.0.0 and is removed in drupal:9.0.0. Use \Drupal\Core\Field\FieldFilteredMarkup::displayAllowedTags() instead.
*/
public function testDeprecation() {
$deprecated = new FieldDeprecateAllowedTagsXssTraitClass();
$this->assertSame('Test string', (string) $deprecated->fieldFilterXss('<object>Test string</object>'));
$this->assertSame(FieldFilteredMarkup::allowedTags(), $deprecated->allowedTags());
$this->assertSame(FieldFilteredMarkup::displayAllowedTags(), $deprecated->displayAllowedTags());
}
}
/**
* Class FieldDeprecateAllowedTagsXssTraitClass
*/
class FieldDeprecateAllowedTagsXssTraitClass {
use AllowedTagsXssTrait;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment