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

(cherry picked from commit 3791e77a71ccd14e61e1e2d10c9a1e306abee629)
merge-requests/64/head
catch 2020-02-10 11:59:30 +00:00
parent ec37742ffb
commit 2bbee7027e
5 changed files with 46 additions and 3 deletions

View File

@ -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 @@ trait AllowedTagsXssTrait {
* 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 @@ trait AllowedTagsXssTrait {
* 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();
}

View File

@ -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 @@ class ListFloatItem extends ListItemBase {
$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;
}

View File

@ -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 @@ class ListIntegerItem extends ListItemBase {
$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;
}

View File

@ -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 @@ class ListStringItem extends ListItemBase {
$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;
}

View File

@ -0,0 +1,37 @@
<?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;
}