Skip to content

Commit

Permalink
Fix event card links for local events
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Aug 2, 2024
1 parent b672311 commit f685ec3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
17 changes: 17 additions & 0 deletions chem_h_subtheme.theme
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* Preprocess functions for chem_h.
*/

use Drupal\ui_patterns\Element\PatternContext;
use Drupal\node\NodeInterface;

/**
* Implements hook_preprocess().
*/
Expand Down Expand Up @@ -198,3 +201,17 @@ function chem_h_subtheme_preprocess_paragraph__stanford_layout(array &$variables
];
$variables['attributes']['class'] = array_merge($existing_classes, $extra_classes);
}

/**
* Implements hook_preprocess_HOOK().
*/
function chem_h_subtheme_preprocess_pattern_events_card(&$variables){
if (isset($variables['context']) && $variables['context'] instanceof PatternContext) {
/** @var \Drupal\ui_patterns\Element\PatternContext $context */
$context = $variables['context'];
$node = $context->getProperty('entity');
if ($node instanceof NodeInterface) {
$variables['page_url'] = $node->toUrl()->toString();
}
}
}
19 changes: 12 additions & 7 deletions templates/components/event-card/pattern-events-card.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
{%- endif -%}
{% set header_tag = variant == 'h3_header' ? 'h3' : 'h2' %}

{% set url = url|render_clean %}
{% if not url %}
{% set url = page_url %}
{% endif %}

<div {{ attributes }}>
<div class="su-event-list-item__date">
<div class="su-date-stacked su-date-stacked--no-background" aria-hidden="true">
Expand Down Expand Up @@ -68,7 +73,7 @@
{%- if url|render_clean is empty -%}
{{- headline -}}
{%- else -%}
<{{ header_tag }}><a {{ link_attributes }} href="{{ url|render_clean }}">{{ headline|render_clean }}</a></{{ header_tag }}>
<{{ header_tag }}><a {{ link_attributes }} href="{{ url }}" data-foo="bar">{{ headline|render_clean }}</a></{{ header_tag }}>
{%- endif -%}

{# Event Subheadline #}
Expand Down Expand Up @@ -149,23 +154,23 @@
{% endif %}
</div>
</div>

<div class="su-event-card__footer">
<a {{ link_attributes }} href="{{ url|render_clean }}" aria-hidden="true">
<a {{ link_attributes }} href="{{ url }}" aria-hidden="true" tabindex="-1">

{%- if not is_external -%}
<span class="su-link--icon" aria-hidden="true">
<span class="su-link--icon">
<i class="fas fa-arrow-right"></i>
</span>
{%- endif -%}

{%- if is_external -%}
<span class="su-link--icon--external" aria-hidden="true">
<span class="su-link--icon--external">
<i class="fas fa-arrow-right" style="rotate: -45deg;"></i>
</span>
{%- endif -%}

</a>
</div>

</div>
</div>

0 comments on commit f685ec3

Please sign in to comment.