Skip to content

Commit c2db5bf

Browse files
bugfix(CMS-349): Add missing field to API and make API more resilliant (#1722)
- Add in screen reader field for text buttons to API so the field can be migrated - Add in a check for the isPublished flag as not all nodes seem to have that information
1 parent bad2d66 commit c2db5bf

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

web/modules/custom/sfgov_api/src/Payload/PayloadBase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function setMetadata() {
143143
'title' => $entity->label(),
144144
'translations' => array_keys($entity->getTranslationLanguages()),
145145
'wag_bundle' => $this->wagBundle,
146-
'published' => $entity->isPublished(),
146+
'published' => method_exists($entity, 'isPublished') ? $entity->isPublished() : null,
147147
'created' => $this->convertTimestampToFormat($entity->getCreatedTime(), 'Y-m-d\TH:i:s'),
148148
];
149149
}

web/modules/custom/sfgov_api/src/Plugin/SfgApi/Paragraph/Button.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,24 @@ class Button extends SfgApiParagraphBase {
2525
* {@inheritDoc}
2626
*/
2727
public function setCustomData($entity) {
28+
$link_data = $entity->get('field_link')->getvalue();
29+
$link_label = $link_data ? $link_data[0]['options']['attributes']['aria-label'] : '';
30+
2831
// This is the shape wagtail expects when the button is empty.
29-
$empty_button = [
32+
$button_value = [
3033
'url' => '',
3134
'page' => NULL,
3235
'link_to' => '',
3336
'link_text' => '',
37+
'screenreader_label' => '',
3438
];
35-
$button_data = $this->generateLinks($entity->get('field_link')->getvalue());
36-
$button_value = $button_data ? $button_data[0] : $empty_button;
39+
$button_data = $this->generateLinks($link_data);
40+
41+
if ($button_data) {
42+
$button_value = $button_data[0];
43+
$button_value['value']['screenreader_label'] = $link_label;
44+
}
45+
3746
return [
3847
'alter' => 'flatten_link',
3948
'link' => $button_value,

0 commit comments

Comments
 (0)