Skip to content

Commit

Permalink
update data story plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
rloos289 committed Jan 29, 2024
1 parent 9e274d2 commit 9304086
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,24 @@ public function getReferencedData(array $entities) {
}
}

// For some reason Wagtail needs streamfields with a single entry to be
// flattened. Currently this is only in place to make the paragraph_image
// plugin work but there are probably other paragraphs that will need this.
// There are some paragraphs that, if not filled out properly, will
// cause errors in wagtail. These are miscellaneous pieces of code
// to remove or edit certain paragraphs.
foreach ($entities_data as $key => $entity_data) {
if (is_array($entity_data)) {
// flatten image paragraphs.
if (count($entity_data['value']) == 1) {
$entities_data[$key] = [
'type' => $entity_data['type'],
'value' => $entity_data['value']['value'],
'value' => reset($entity_data['value']),
];
}
// remove empty "section" paragraphs.
if ($entity_data['type'] == 'section') {
if ($entity_data["value"]["title"] === NULL && empty($entity_data["value"]["section_content"])) {
unset($entities_data[$key]);
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* id = "node_data_story",
* title = @Translation("Node data_story"),
* bundle = "data_story",
* wag_bundle = "dataStory",
* wag_bundle = "DataStory",
* entity_id = {},
* langcode = {},
* )
Expand All @@ -25,9 +25,9 @@ class DataStory extends SfgApiNodeBase {
*/
public function setCustomData($entity) {
return [
'description' => $entity->get('field_description')->value,
'description' => $entity->get('field_description')->value ?: '',
'content' => $this->getReferencedData($entity->get('field_content')->referencedEntities()),
'field_departments' => $entity->get('field_departments')->value,
'partner_agencies' => $this->getReferencedEntity($entity->get('field_departments')->referencedEntities()),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public function setBaseData($node) {
$path_alias_manager = \Drupal::service('path_alias.manager');
$alias = $path_alias_manager->getAliasByPath('/node/' . $node_id);
$wag_api_settings = \Drupal::config('sfgov_api.settings');
$slug = $node->bundle() . '__' . basename($alias);
$alias_slug = ltrim($alias, '/');
$base_data = [
'parent_id' => (int) $wag_api_settings->get('wag_parent_' . $this->configuration['langcode']),
'title' => $node->getTitle(),
'slug' => $slug,
'slug' => str_replace('/', '--', $alias_slug),
'aliases' => [],
'formsubmission_set' => [],
'redirect_set' => [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Callout extends SfgApiParagraphBase {
*/
public function setCustomData($entity) {
return [
'field_text' => $entity->get('field_text')->value,
'value' => $entity->get('field_text')->value,
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class DataStorySection extends SfgApiParagraphBase {
*/
public function setCustomData($entity) {
return [
'title' => $entity->get('field_title')->value,
'field_content' => $this->getReferencedData($entity->get('field_content')->referencedEntities()),
'title' => $entity->get('field_title')->value ?: 'Section Title',
'section_content' => $this->getReferencedData($entity->get('field_content')->referencedEntities()),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class PowerbiEmbed extends SfgApiParagraphBase {
*/
public function setCustomData($entity) {
return [
'alt_text' => $entity->get('field_title')->value,
'data_notes' => $entity->get('field_data_notes')->value,
'source_data' => $entity->get('field_source_data')->value,
'aspect_ratios' => [
Expand All @@ -39,7 +40,6 @@ public function setCustomData($entity) {
],
'desktop_embed_url' => $entity->get('field_desktop_embed_url')->value,
'mobile_embed_url' => $entity->get('field_mobile_embed_url')->value,
// 'field_title' => $entity->get('field_title')->value,
];
}

Expand Down

0 comments on commit 9304086

Please sign in to comment.