Loading custom_elements.module +5 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ * Custom elements hooks. */ use Drupal\Component\Render\MarkupInterface; use Drupal\Core\Render\Markup; use Drupal\custom_elements\CustomElement; use Drupal\Core\Entity\EntityInterface; Loading Loading @@ -49,6 +50,10 @@ function template_preprocess_custom_element(&$variables) { $key = ":$key"; } } // Attributes with html markup get html stripped, so we convert to string. if ($value instanceof MarkupInterface) { $value = (string) $value; } $variables['attributes'][$key] = $value; } $variables['tag_prefix'] = $custom_element->getTagPrefix() ? $custom_element->getTagPrefix() . '-' : ''; Loading tests/src/Functional/CustomElementsRenderMarkupTest.php +2 −2 Original line number Diff line number Diff line Loading @@ -258,9 +258,9 @@ EOF; ->generate($paragraph, 'full'); $markup = $this->renderCustomElement($custom_element); $expected_markup = <<<EOF <pg-image caption="<strong>Custom Elements</strong> <p>image</p> description" copyright="custom elements copyright" src="{$this->image->uri->url}" type="image" view-mode="full"/> <pg-image type="image" view-mode="full" src="{$this->image->uri->url}" copyright="custom elements copyright" caption="<p>&lt;strong&gt;Custom Elements&lt;/strong&gt; &lt;p&gt;image&lt;/p&gt; description</p>"></pg-image> EOF; Assert::assertXmlStringEqualsXmlString($this->trim($expected_markup), $this->trim($markup)); Assert::assertEquals($this->trim($expected_markup), $this->trim($markup)); } /** Loading tests/src/Functional/CustomElementsRenderMarkupVue3Test.php +1 −1 Original line number Diff line number Diff line Loading @@ -257,7 +257,7 @@ EOF; ->generate($paragraph, 'full'); $markup = $this->renderCustomElement($custom_element); $expected_markup = <<<EOF <pg-image type="image" view-mode="full" src="{$this->image->uri->url}" copyright="custom elements copyright" caption="<strong>Custom Elements</strong> <p>image</p> description"></pg-image> <pg-image type="image" view-mode="full" src="{$this->image->uri->url}" copyright="custom elements copyright" caption="<p>&lt;strong&gt;Custom Elements&lt;/strong&gt; &lt;p&gt;image&lt;/p&gt; description</p>"></pg-image> EOF; Assert::assertEquals($this->trim($expected_markup), $this->trim($markup)); } Loading Loading
custom_elements.module +5 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ * Custom elements hooks. */ use Drupal\Component\Render\MarkupInterface; use Drupal\Core\Render\Markup; use Drupal\custom_elements\CustomElement; use Drupal\Core\Entity\EntityInterface; Loading Loading @@ -49,6 +50,10 @@ function template_preprocess_custom_element(&$variables) { $key = ":$key"; } } // Attributes with html markup get html stripped, so we convert to string. if ($value instanceof MarkupInterface) { $value = (string) $value; } $variables['attributes'][$key] = $value; } $variables['tag_prefix'] = $custom_element->getTagPrefix() ? $custom_element->getTagPrefix() . '-' : ''; Loading
tests/src/Functional/CustomElementsRenderMarkupTest.php +2 −2 Original line number Diff line number Diff line Loading @@ -258,9 +258,9 @@ EOF; ->generate($paragraph, 'full'); $markup = $this->renderCustomElement($custom_element); $expected_markup = <<<EOF <pg-image caption="<strong>Custom Elements</strong> <p>image</p> description" copyright="custom elements copyright" src="{$this->image->uri->url}" type="image" view-mode="full"/> <pg-image type="image" view-mode="full" src="{$this->image->uri->url}" copyright="custom elements copyright" caption="<p>&lt;strong&gt;Custom Elements&lt;/strong&gt; &lt;p&gt;image&lt;/p&gt; description</p>"></pg-image> EOF; Assert::assertXmlStringEqualsXmlString($this->trim($expected_markup), $this->trim($markup)); Assert::assertEquals($this->trim($expected_markup), $this->trim($markup)); } /** Loading
tests/src/Functional/CustomElementsRenderMarkupVue3Test.php +1 −1 Original line number Diff line number Diff line Loading @@ -257,7 +257,7 @@ EOF; ->generate($paragraph, 'full'); $markup = $this->renderCustomElement($custom_element); $expected_markup = <<<EOF <pg-image type="image" view-mode="full" src="{$this->image->uri->url}" copyright="custom elements copyright" caption="<strong>Custom Elements</strong> <p>image</p> description"></pg-image> <pg-image type="image" view-mode="full" src="{$this->image->uri->url}" copyright="custom elements copyright" caption="<p>&lt;strong&gt;Custom Elements&lt;/strong&gt; &lt;p&gt;image&lt;/p&gt; description</p>"></pg-image> EOF; Assert::assertEquals($this->trim($expected_markup), $this->trim($markup)); } Loading