Skip to content

Commit

Permalink
Article List: global and per-node date functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbrown-io committed Nov 21, 2024
1 parent 02d03ca commit c645625
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 10 additions & 6 deletions js/ucb-article-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
this.pageCount = pageCount;
this._categoryTerms = null;
this._tagTerms = null;

// Build the endpoint path, now in JS
this.endpoint = this.buildEndpointPath();
}
Expand Down Expand Up @@ -189,6 +188,8 @@
this._filterFormElement.style.alignItems = 'center';
this._contentElement.setAttribute('aria-live', 'polite');
}
// Date format
this.globalDateSetting = this.getAttribute('global-date-format');
this.appendChild(this._contentElement);
// Loader
this._loadingElement = document.createElement('div');
Expand Down Expand Up @@ -531,11 +532,14 @@
}

// Format
const date = item.attributes.field_ucb_article_date_override == "7" ? null : new Date(item.attributes.created).toLocaleDateString('en-us', {
year: 'numeric',
month: 'short',
day: 'numeric',
});
const date = (item.attributes.field_ucb_article_date_override != "7" &&
(this.globalDateSetting != 6 || item.attributes.field_ucb_article_date_override != "0"))
? new Date(item.attributes.created).toLocaleDateString('en-us', {
year: 'numeric',
month: 'short',
day: 'numeric',
})
: null;
const title = item.attributes.title;
// If no path alias set, use defaults
const path = item.attributes.path.alias ? item.attributes.path.alias : `/node/${item.attributes.drupal_internal__nid}`;
Expand Down
4 changes: 4 additions & 0 deletions templates/content/node--ucb-article-list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
{# Base Url #}
{% set baseurlJSON = url('<front>')|render|trim('/') %}

{# Show/Hide Date #}
{% set global_date_format = drupal_config('ucb_site_configuration.settings', 'article_date_format') %}

{# include and exclude options set by the user #}
{% set includeCategories = '' %}
{% set myCategories = content.field_ucb_filter_by_category|render|striptags|trim|split(' ') %}
Expand Down Expand Up @@ -149,6 +152,7 @@
'exclude-tags': excludeTags,
'expose-categories' : exposeCategory,
'expose-tags': exposeTag,
'global-date-format': global_date_format,
}) }}
>
</article-list>
Expand Down

0 comments on commit c645625

Please sign in to comment.