Skip to content

Commit

Permalink
Merge pull request #1243 from weather-gov/lmm/1200-alt-text-help-text
Browse files Browse the repository at this point in the history
adds a new module weather_cms and adds a hook for changing alt text on images
  • Loading branch information
loganmcdonald-noaa authored May 23, 2024
2 parents d6fa9eb + 41588e3 commit 86e3ec2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/modules-updated-pr-comment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
run: |
# Use GitHub API to create a comment on the PR
PR_NUMBER=${{ github.event.pull_request.number }}
COMMENT="It looks like our enabled modules has changed in this PR. Please ensure any documentation in https://github.com/weather-gov/weather.gov/tree/main/docs/contributed-modules.md has been updated!"
COMMENT="It looks like our enabled modules has changed in this PR. Please ensure any documentation in https://github.com/weather-gov/weather.gov/tree/main/docs/dev/contributed-modules.md has been updated!"
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
COMMENT_URL="https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments"
Expand Down
1 change: 1 addition & 0 deletions web/config/sync/core.extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module:
user: 0
views_ui: 0
weather_blocks: 0
weather_cms: 0
weather_data: 0
weather_login: 0
weather_routes: 0
Expand Down
6 changes: 6 additions & 0 deletions web/modules/weather_cms/weather_cms.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: Weather cms
type: module
description: Various customizations used for the weather.gov CMS
package: weather.gov

core_version_requirement: ^10
19 changes: 19 additions & 0 deletions web/modules/weather_cms/weather_cms.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

use Drupal\Core\Form\FormStateInterface;

// This hook allows us to alter single elements of a widget, which we want to do for alt text on uploaded images
function weather_cms_field_widget_single_element_form_alter(array &$element, FormStateInterface $form_state, array $context) // phpcs:ignore
{
if ($context["widget"] instanceof \Drupal\image\Plugin\Field\FieldWidget\ImageWidget) {
$element["#process"][] = "weather_cms_image_field_widget_process";
}
}

function weather_cms_image_field_widget_process($element, &$form_state, $form)
{
if (isset($element["alt"])) {
$element["alt"]["#description"] = "Alt text should provide the same information as the image, not serve as a description of the image itself. If you have included text on your image, it should be in the alt text along with whatever additional context is needed to provide the same information to users who cannot view the image."; // phpcs:ignore
}
return $element;
}
Empty file.

0 comments on commit 86e3ec2

Please sign in to comment.