diff --git a/flag.module b/flag.module index 28fc32b..60b8435 100644 --- a/flag.module +++ b/flag.module @@ -145,6 +145,20 @@ function flag_entity_extra_field_info() { } /** + * Implements hook_theme(). + */ +function flag_theme($existing, $type, $theme, $path) { + return [ + 'flag' => [ + 'variables' => [ + 'attributes' => [], + 'title' => NULL, + ], + ], + ]; +} + +/** * Implements hook_node_links_alter(). */ function flag_node_links_alter(array &$links, NodeInterface $entity, array &$context) { diff --git a/src/ActionLinkTypeBase.php b/src/ActionLinkTypeBase.php index 2c86a1e..c606730 100644 --- a/src/ActionLinkTypeBase.php +++ b/src/ActionLinkTypeBase.php @@ -84,18 +84,21 @@ abstract class ActionLinkTypeBase extends PluginBase implements ActionLinkTypePl $url = $this->getLinkURL($action, $flag, $entity); $url->setRouteParameter('destination', $this->getDestination()); + + // Get the Flag URL. + $render = []; + $render['#attributes']['href'] = $url->toString(); - $render = $url->toRenderArray(); - $render['#type'] = 'link'; + $render['#theme'] = 'flag'; $render['#attributes']['id'] = 'flag-' . $flag->id() . '-id-' . $entity->id(); if ($action === 'unflag') { $render['#title'] = $flag->getUnflagShortText(); - $render['#alt'] = $flag->getUnflagLongText(); + $render['#attributes']['#alt'] = $flag->getUnflagLongText(); } else { $render['#title'] = $flag->getFlagShortText(); - $render['#alt'] = $flag->getFlagLongText(); + $render['#attributes']['alt'] = $flag->getFlagLongText(); } return $render; diff --git a/templates/flag.html.twig b/templates/flag.html.twig new file mode 100644 index 0000000..132168f --- /dev/null +++ b/templates/flag.html.twig @@ -0,0 +1,11 @@ +{# +/** + * @file + * Default theme implementation for flag links. + * + * Available variables: + * - attributes: HTML attributes for the containing element. + * - title: The flag link title. + */ +#} +{{ title }} \ No newline at end of file