From 5ffe32ef589b9fb910ca75999a22680f060e09a6 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 1 Mar 2018 15:30:51 -0600 Subject: [PATCH] Fix alt tag issue #1883 --- CHANGELOG.md | 3 ++- system/src/Grav/Common/Helpers/Excerpts.php | 9 +++++---- system/src/Grav/Common/Page/Medium/Medium.php | 4 +++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69c4388e8a..03e3ec0bbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,8 @@ * Vendor library updated to latest * Improved `Session` initialization 1. [](#bugfix) - * Fixed issue with remote PHP version determination for Grav updates + * Fixed issue with image alt tag always getting empted out unless set in markdown + * Fixed issue with remote PHP version determination for Grav updates [#1883](https://github.com/getgrav/grav/issues/1883) # v1.4.0-rc.2 ## 02/15/2018 diff --git a/system/src/Grav/Common/Helpers/Excerpts.php b/system/src/Grav/Common/Helpers/Excerpts.php index b294bd9551..d774bcf463 100644 --- a/system/src/Grav/Common/Helpers/Excerpts.php +++ b/system/src/Grav/Common/Helpers/Excerpts.php @@ -246,11 +246,12 @@ public static function processImageExcerpt(array $excerpt, Page $page) // Process operations $medium = static::processMediaActions($medium, $url_parts); + $element_excerpt = $excerpt['element']['attributes']; - $alt = isset($excerpt['element']['attributes']['alt']) ? $excerpt['element']['attributes']['alt'] : ''; - $title = isset($excerpt['element']['attributes']['title']) ? $excerpt['element']['attributes']['title'] : ''; - $class = isset($excerpt['element']['attributes']['class']) ? $excerpt['element']['attributes']['class'] : ''; - $id = isset($excerpt['element']['attributes']['id']) ? $excerpt['element']['attributes']['id'] : ''; + $alt = isset($element_excerpt['alt']) ? $element_excerpt['alt'] : ''; + $title = isset($element_excerpt['title']) ? $element_excerpt['title'] : ''; + $class = isset($element_excerpt['class']) ? $element_excerpt['class'] : ''; + $id = isset($element_excerpt['id']) ? $element_excerpt['id'] : ''; $excerpt['element'] = $medium->parsedownElement($title, $alt, $class, $id, true); diff --git a/system/src/Grav/Common/Page/Medium/Medium.php b/system/src/Grav/Common/Page/Medium/Medium.php index c8473efbe9..4811c8d542 100644 --- a/system/src/Grav/Common/Page/Medium/Medium.php +++ b/system/src/Grav/Common/Page/Medium/Medium.php @@ -284,12 +284,14 @@ public function parsedownElement($title = null, $alt = null, $class = null, $id } if (empty($attributes['alt'])) { - if (!empty($alt) || $alt === '') { + if (!empty($alt)) { $attributes['alt'] = $alt; } elseif (!empty($this->items['alt'])) { $attributes['alt'] = $this->items['alt']; } elseif (!empty($this->items['alt_text'])) { $attributes['alt'] = $this->items['alt_text']; + } else { + $attributes['alt'] = ''; } }