-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1243 from weather-gov/lmm/1200-alt-text-help-text
adds a new module weather_cms and adds a hook for changing alt text on images
- Loading branch information
Showing
5 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.