Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- TMS-996: Change bold image-caption text to normal
- TMS-1009: Fix error when fetching Eventz response with languages other than fi & en
- TMS-1015: Header accessibility fixes
- TMS-1017: Add image alt-text to imported news

## [1.54.5] - 2024-02-01

Expand Down
4 changes: 3 additions & 1 deletion lib/ACF/DynamicEventGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,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
Loading