diff --git a/core/lib/Drupal/Component/Render/FormattableMarkup.php b/core/lib/Drupal/Component/Render/FormattableMarkup.php index cde8e86..261de41 100644 --- a/core/lib/Drupal/Component/Render/FormattableMarkup.php +++ b/core/lib/Drupal/Component/Render/FormattableMarkup.php @@ -65,7 +65,7 @@ * @see \Drupal\Core\StringTranslation\PluralTranslatableMarkup * @see \Drupal\Component\Render\FormattableMarkup::placeholderFormat() */ -class FormattableMarkup implements MarkupInterface { +class FormattableMarkup implements MarkupInterface, \Countable { /** * The arguments to replace placeholders with. diff --git a/core/lib/Drupal/Component/Render/HtmlEscapedText.php b/core/lib/Drupal/Component/Render/HtmlEscapedText.php index fd1e69d..f12e4e9 100644 --- a/core/lib/Drupal/Component/Render/HtmlEscapedText.php +++ b/core/lib/Drupal/Component/Render/HtmlEscapedText.php @@ -18,7 +18,7 @@ * * @ingroup sanitization */ -class HtmlEscapedText implements MarkupInterface { +class HtmlEscapedText implements MarkupInterface, \Countable { /** * The string to escape. diff --git a/core/lib/Drupal/Component/Render/MarkupInterface.php b/core/lib/Drupal/Component/Render/MarkupInterface.php index 9559437..65ab29a 100644 --- a/core/lib/Drupal/Component/Render/MarkupInterface.php +++ b/core/lib/Drupal/Component/Render/MarkupInterface.php @@ -35,7 +35,7 @@ * @see sanitization * @see theme_render */ -interface MarkupInterface extends \JsonSerializable, \Countable { +interface MarkupInterface extends \JsonSerializable { /** * Returns markup. diff --git a/core/lib/Drupal/Core/Field/FieldFilteredMarkup.php b/core/lib/Drupal/Core/Field/FieldFilteredMarkup.php index 4c164c4..8dcadca 100644 --- a/core/lib/Drupal/Core/Field/FieldFilteredMarkup.php +++ b/core/lib/Drupal/Core/Field/FieldFilteredMarkup.php @@ -24,7 +24,7 @@ * * @see \Drupal\Core\Render\Markup */ -final class FieldFilteredMarkup implements MarkupInterface { +final class FieldFilteredMarkup implements MarkupInterface, \Countable { use MarkupTrait; /** diff --git a/core/lib/Drupal/Core/GeneratedLink.php b/core/lib/Drupal/Core/GeneratedLink.php index 21d8b35..a612f66 100644 --- a/core/lib/Drupal/Core/GeneratedLink.php +++ b/core/lib/Drupal/Core/GeneratedLink.php @@ -17,7 +17,7 @@ * Note: not to be confused with \Drupal\Core\Link, which is for passing around * ungenerated links (typically link text + route name + route parameters). */ -class GeneratedLink extends BubbleableMetadata implements MarkupInterface { +class GeneratedLink extends BubbleableMetadata implements MarkupInterface, \Countable { /** * The HTML string value containing a link. diff --git a/core/lib/Drupal/Core/Render/Markup.php b/core/lib/Drupal/Core/Render/Markup.php index b649b1a..c36d29f 100644 --- a/core/lib/Drupal/Core/Render/Markup.php +++ b/core/lib/Drupal/Core/Render/Markup.php @@ -25,6 +25,6 @@ * @see \Twig_Markup * @see \Drupal\Component\Utility\SafeMarkup */ -final class Markup implements MarkupInterface { +final class Markup implements MarkupInterface, \Countable { use MarkupTrait; } diff --git a/core/lib/Drupal/Core/Template/Attribute.php b/core/lib/Drupal/Core/Template/Attribute.php index d4f2b58..26a1793 100644 --- a/core/lib/Drupal/Core/Template/Attribute.php +++ b/core/lib/Drupal/Core/Template/Attribute.php @@ -347,11 +347,4 @@ public function jsonSerialize() { return (string) $this; } - /** - * {@inheritdoc} - */ - public function count() { - return count($this->storage); - } - } diff --git a/core/modules/filter/src/Render/FilteredMarkup.php b/core/modules/filter/src/Render/FilteredMarkup.php index d7fe196..2abfac3 100644 --- a/core/modules/filter/src/Render/FilteredMarkup.php +++ b/core/modules/filter/src/Render/FilteredMarkup.php @@ -24,6 +24,6 @@ * * @see \Drupal\Core\Render\Markup */ -final class FilteredMarkup implements MarkupInterface { +final class FilteredMarkup implements MarkupInterface, \Countable { use MarkupTrait; } diff --git a/core/modules/views/src/Render/ViewsRenderPipelineMarkup.php b/core/modules/views/src/Render/ViewsRenderPipelineMarkup.php index 70d60dc..4532b9c 100644 --- a/core/modules/views/src/Render/ViewsRenderPipelineMarkup.php +++ b/core/modules/views/src/Render/ViewsRenderPipelineMarkup.php @@ -23,6 +23,6 @@ * * @see \Drupal\Core\Render\Markup */ -final class ViewsRenderPipelineMarkup implements MarkupInterface { +final class ViewsRenderPipelineMarkup implements MarkupInterface, \Countable { use MarkupTrait; } diff --git a/core/tests/Drupal/KernelTests/Core/Theme/TwigMarkupInterfaceTest.php b/core/tests/Drupal/KernelTests/Core/Theme/TwigMarkupInterfaceTest.php index 9150cba..551c658 100644 --- a/core/tests/Drupal/KernelTests/Core/Theme/TwigMarkupInterfaceTest.php +++ b/core/tests/Drupal/KernelTests/Core/Theme/TwigMarkupInterfaceTest.php @@ -8,12 +8,13 @@ namespace Drupal\KernelTests\Core\Theme; use Drupal\Component\Render\FormattableMarkup; +use Drupal\Component\Render\MarkupInterface; +use Drupal\Component\Render\MarkupTrait; use Drupal\Core\GeneratedLink; use Drupal\Core\Render\RenderContext; use Drupal\Core\Render\Markup; use Drupal\Core\Site\Settings; use Drupal\Core\StringTranslation\TranslatableMarkup; -use Drupal\Core\Template\Attribute; use Drupal\KernelTests\KernelTestBase; /** @@ -49,10 +50,11 @@ public function providerTestMarkupInterfaceEmpty() { 'empty FormattableMarkup' => ['', new FormattableMarkup('', ['@foo' => 'bar'])], 'non-empty FormattableMarkup' => ['bar', new FormattableMarkup('@foo', ['@foo' => 'bar'])], 'non-empty Markup' => ['test', Markup::create('test')], - 'empty Attribute' => ['', new Attribute()], - 'non-empty Attribute' => [' id="test"', new Attribute(['id' => 'test'])], 'empty GeneratedLink' => ['', new GeneratedLink()], - 'non-empty Attribute' => ['test', (new GeneratedLink())->setGeneratedLink('test')], + 'non-empty GeneratedLink' => ['test', (new GeneratedLink())->setGeneratedLink('test')], + // Test objects that do not implement \Countable. + 'empty SafeMarkupTestMarkup' => ['', SafeMarkupTestMarkup::create('')], + 'non-empty SafeMarkupTestMarkup' => ['test', SafeMarkupTestMarkup::create('test')], ]; } @@ -91,3 +93,20 @@ protected function renderObjectWithTwig($variable) { } } + +/** + * Implements MarkupInterface without implementing \Countable + */ +class SafeMarkupTestMarkup implements MarkupInterface { + use MarkupTrait; + + /** + * Overrides MarkupTrait::create() to allow creation with empty strings. + */ + public static function create($string) { + $object = new static(); + $object->string = $string; + return $object; + } + +} \ No newline at end of file