Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: Testing

on:
push:
branches:
- main
- feature/*

env:
SIMPLETEST_DB: sqlite://localhost/sites/default/files/.ht.sqlite
Expand All @@ -31,7 +28,7 @@ jobs:
composer config prefer-stable true
composer config repositories.0 '{"type": "path", "url": "'$GITHUB_WORKSPACE'/packages/uebertool-companion", "options": {"symlink": false}}'
composer config repositories.1 '{"type": "composer", "url": "https://asset-packagist.org"}'
composer require drupal/core-dev:^11.1.1 \
composer require -W drupal/core-dev:^11.1.1 \
drush/drush \
ueberbit/uebertool_companion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function getFilters(): array {
/**
* {@inheritdoc}
*/
public function getFunctions() {
public function getFunctions(): array {
return [
new TwigFunction('button', [$this, 'getButton']),
new TwigFunction('buttons', [$this, 'getButtons']),
Expand Down Expand Up @@ -218,6 +218,12 @@ public function linkText(?array $build): string {
*/
public function linkAttributes(?array $build): Attribute {
if ($this->isLink($build)) {
$linkAttributes = new Attribute();
$linkAttributes->addClass($build['#url']->getOption('attributes')['class'] ?? []);
if ((string) $linkAttributes) {
@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);
}

$element = $this->renderer->renderInIsolation($build);
$dom = Html::load($element);
$xpath = new \DOMXPath($dom);
Expand All @@ -228,6 +234,7 @@ public function linkAttributes(?array $build): Attribute {
return $item->nodeValue;
}, iterator_to_array($element->attributes->getIterator())));
$attribute->removeAttribute('href');
$attribute->merge($linkAttributes);
return $attribute;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,24 @@ public function testLinkAttributes(): void {
'class' => 'foo',
],
]));
}

#[IgnoreDeprecations]
public function testLinkAttributesWithUrlOptions(): void {
// Collect attributes from link options.
$url = Url::fromUri('https://example.com');
$url->setOption('attributes', [
'class' => 'foo',
'data-foo' => 'bar',
]);

$this->expectDeprecation('Handling the class attribute from the Url object is deprecated. Use $element["#attributes"] instead. See https://www.drupal.org/node/3494015');
$this->assertEquals(new Attribute([
'data-foo' => 'bar',
'target' => '_blank',
'class' => [
'foo',
],
'data-foo' => 'bar',
'target' => '_blank',
]), $this->twigExtension->linkAttributes([
'#type' => 'link',
'#title' => 'Link text',
Expand Down