Skip to content

Commit

Permalink
TMS-1017: Add image alt-text to imported news
Browse files Browse the repository at this point in the history
  • Loading branch information
eebbi committed Mar 8, 2024
1 parent c5cd0ec commit 0d7e800
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

- TMS-1017: Add image alt-text to imported news

## [1.54.5] - 2024-02-01

- TMS-977: Add 'clear form' button to event-search
Expand Down
4 changes: 3 additions & 1 deletion lib/ACF/DynamicEventGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ protected function get_choices_by_name( string $name, array $field ) : array {

if ( ! empty( $response ) ) {
foreach ( $response as $item ) {
$field['choices'][ $item->_id ] = $item->name;
if ( isset( $item->_id ) ) {
$field['choices'][ $item->_id ] = $item->name;
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion lib/Traits/EnrichPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ public static function enrich_post(
int $excerpt_length = 160
) {
if ( $use_images ) {
$api_image = get_field( 'image_url', $post->ID );
$api_image = get_field( 'image_url', $post->ID );
$api_image_alt = get_field( 'image_alt', $post->ID );

if ( ! empty( $api_image ) ) {
$post->api_image_url = $api_image;
$post->api_image_alt = $api_image_alt;
}
else {
$post->featured_image = has_post_thumbnail( $post->ID )
Expand Down
2 changes: 2 additions & 0 deletions models/single.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public function content() {
: $single->image;

$single->api_image_url = empty( $single->image ) ? get_field( 'image_url' ) : false;
$single->api_image_alt = empty( $single->image ) ? get_field( 'image_alt' ) : false;
$single->has_image = ! empty( $single->image ) || ! empty( $single->api_image_url );

if ( 'blog-article' === $single->post_type ) {
Expand Down Expand Up @@ -141,6 +142,7 @@ public function related() : ?array {
}

$item->api_image_url = get_field( 'image_url', $item->ID );
$item->api_image_alt = get_field( 'image_alt', $item->ID );
$has_image = $item->image_id !== 0 || ! empty( $item->api_image_url );

if ( ! $has_image ) {
Expand Down
4 changes: 3 additions & 1 deletion partials/single.dust
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@

{?content.api_image_url}
<div class="entry__figure pt-2">
<img src="{content.api_image_url|url}" loading="lazy" />
<img src="{content.api_image_url|url}"
{?content.api_image_alt}alt="{content.api_image_alt|attr}"{/content.api_image_alt}
loading="lazy" />
</div>

{>"views/single/single-meta" spacing_class="pt-5 pt-4-desktop pb-5 p-5-tablet" /}
Expand Down

0 comments on commit 0d7e800

Please sign in to comment.