Skip to content

Commit 3d09262

Browse files
webflowoldtwerk
authored andcommitted
Add depreaction for test
1 parent fee138f commit 3d09262

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

packages/uebertool-companion/modules/uebertool_twig/src/Twig/Extension/TwigExtrasExtension.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function getFilters(): array {
4040
/**
4141
* {@inheritdoc}
4242
*/
43-
public function getFunctions() {
43+
public function getFunctions(): array {
4444
return [
4545
new TwigFunction('button', [$this, 'getButton']),
4646
new TwigFunction('buttons', [$this, 'getButtons']),
@@ -218,6 +218,12 @@ public function linkText(?array $build): string {
218218
*/
219219
public function linkAttributes(?array $build): Attribute {
220220
if ($this->isLink($build)) {
221+
$linkAttributes = new Attribute();
222+
$linkAttributes->addClass($build['#url']->getOption('attributes')['class'] ?? []);
223+
if ((string) $linkAttributes) {
224+
@trigger_error('Handling the class attribute from the Url object is deprecated. Use $element["#attributes"] instead. See https://www.drupal.org/node/3494015', E_USER_DEPRECATED);
225+
}
226+
221227
$element = $this->renderer->renderInIsolation($build);
222228
$dom = Html::load($element);
223229
$xpath = new \DOMXPath($dom);
@@ -228,6 +234,7 @@ public function linkAttributes(?array $build): Attribute {
228234
return $item->nodeValue;
229235
}, iterator_to_array($element->attributes->getIterator())));
230236
$attribute->removeAttribute('href');
237+
$attribute->merge($linkAttributes);
231238
return $attribute;
232239
}
233240

packages/uebertool-companion/modules/uebertool_twig/tests/src/Kernel/TwigExtrasExtensionTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,24 @@ public function testLinkAttributes(): void {
109109
'class' => 'foo',
110110
],
111111
]));
112+
}
112113

114+
#[IgnoreDeprecations]
115+
public function testLinkAttributesWithUrlOptions(): void {
113116
// Collect attributes from link options.
114117
$url = Url::fromUri('https://example.com');
115118
$url->setOption('attributes', [
116119
'class' => 'foo',
117120
'data-foo' => 'bar',
118121
]);
122+
123+
$this->expectDeprecation('Handling the class attribute from the Url object is deprecated. Use $element["#attributes"] instead. See https://www.drupal.org/node/3494015');
119124
$this->assertEquals(new Attribute([
125+
'data-foo' => 'bar',
126+
'target' => '_blank',
120127
'class' => [
121128
'foo',
122129
],
123-
'data-foo' => 'bar',
124-
'target' => '_blank',
125130
]), $this->twigExtension->linkAttributes([
126131
'#type' => 'link',
127132
'#title' => 'Link text',

0 commit comments

Comments
 (0)