-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
74 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\laszlo\Hook\Theme; | ||
|
||
final readonly class PreprocessLinks { | ||
|
||
public function __invoke(array &$variables): void { | ||
match ($variables['theme_hook_original']) { | ||
default => NULL, | ||
'links__comment' => $this->preprocessComment($variables), | ||
}; | ||
} | ||
|
||
private function preprocessComment(array &$variables): void { | ||
$links_to_simplify = ['comment-delete', 'comment-edit', 'comment-reply']; | ||
|
||
foreach ($links_to_simplify as $link_to_simplify) { | ||
if (array_key_exists($link_to_simplify, $variables['links'])) { | ||
$key = \str_replace('-', '_', $link_to_simplify); | ||
$variables[$key] = [ | ||
'label' => $variables['links'][$link_to_simplify]['text'], | ||
'url' => $variables['links'][$link_to_simplify]['link']['#url']->toString(), | ||
]; | ||
} | ||
} | ||
} | ||
|
||
} |
43 changes: 30 additions & 13 deletions
43
app/Drupal/laszlo/templates/content/comment/links--comment.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,30 @@ | ||
<ul{{ attributes }}> | ||
{%- for item in links -%} | ||
<li{{ item.attributes }}> | ||
{%- if item.link -%} | ||
{{ item.link }} | ||
{%- elseif item.text_attributes -%} | ||
<span{{ item.text_attributes }}>{{ item.text }}</span> | ||
{%- else -%} | ||
{{ item.text }} | ||
{%- endif -%} | ||
</li> | ||
{%- endfor -%} | ||
</ul> | ||
{% if comment_reply %} | ||
{{ _self.action(comment_reply.label, comment_reply.url, 'reply') }} | ||
{% endif %} | ||
{% if comment_edit %} | ||
{{ _self.action(comment_edit.label, comment_edit.url, 'edit') }} | ||
{% endif %} | ||
{% if comment_delete %} | ||
{{ _self.action(comment_delete.label, comment_delete.url, 'trash', 'danger') }} | ||
{% endif %} | ||
|
||
{% macro action(label, href, icon, color = 'primary') %} | ||
{% embed 'laszlo:button' with { | ||
attributes: create_attribute({ | ||
'class': ['comment-action'], | ||
}), | ||
variant: 'text', | ||
color, | ||
href, | ||
label, | ||
icon, | ||
size: 'small', | ||
} only %} | ||
{% block start_icon %} | ||
{% include 'laszlo:icon' with { icon } only %} | ||
{% endblock %} | ||
{% block children %} | ||
{{ label }} | ||
{% endblock %} | ||
{% endembed %} | ||
{% endmacro %} |