Skip to content

Commit

Permalink
finalize information page
Browse files Browse the repository at this point in the history
  • Loading branch information
rloos289 committed Feb 12, 2024
1 parent ae771b9 commit b209d41
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,14 @@ public function pushEntity($entity_type, $bundle, $langcode, $entity_id, $option

$node_exists = $this->apiUtilities->getWagtailId($entity_id, $entity_type, $bundle, $langcode);
if ($node_exists && !$options['update']) {
return $this->output()->writeln('Entity already exists, use the --update option to update it.');
$options['update'] = TRUE;
$message = $this->t('@entity_type of type @bundle with ID @entity_id in langcode @langcode already exists. Updating...', [
'@entity_type' => $entity_type,
'@bundle' => $bundle,
'@entity_id' => $entity_id,
'@langcode' => $langcode,
]);
$this->output()->writeln($message);
}

$payload = $this->sfgApiPluginManager->fetchPayload($plugin_label, $langcode, $entity_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ trait ApiFieldHelperTrait {
*
* @param array $entities
* An array of entities.
* @param bool $type_reference
* Whether to return the type of the referenced entity.
*
* @return array
* An array of entity data.
Expand All @@ -37,18 +35,18 @@ public function getReferencedData(array $entities, $type_reference = TRUE) {
'langcode' => $langcode,
'entity_id' => $entity->id(),
]);
if ($type_reference) {
// if ($type_reference) {
$entities_data[] = [
'type' => $plugin->pluginDefinition['wag_bundle'],
'value' => $plugin->getPayload()->getPayloadData(),
];
// Most of the time we need to wrap the data in an array. But if it
// is expecting a streamfield that can have multiple values then
// we need to return only the data.
}
else {
$entities_data[] = $plugin->getPayload()->getPayloadData();
}
// // Most of the time we need to wrap the data in an array. But if it
// // is expecting a streamfield that can have multiple values then
// // we need to return only the data.
// }
// else {
// $entities_data[] = $plugin->getPayload()->getPayloadData();
// }

}
else {
Expand All @@ -62,21 +60,27 @@ public function getReferencedData(array $entities, $type_reference = TRUE) {
foreach ($entities_data as $key => $entity_data) {
if (is_array($entity_data)) {
// Flatten image paragraphs.
if ($plugin_label === 'paragraph_image') {
if ($entity_data['type'] === 'image') {
$entities_data[$key] = [
'type' => $entity_data['type'],
'value' => $entity_data['value']['value'],
];
// Remove empty image paragraphs.
if (empty($entity_data['value']['value'])) {
unset($entities_data[$key]);
}
}
// Remove empty "section" paragraphs.
if ($entity_data['type'] == 'section') {
if ($entity_data["value"]["title"] === NULL && empty($entity_data["value"]["section_content"])) {
if ($entity_data['value']['title'] === NULL && empty($entity_data['value']['section_content'])) {
unset($entities_data[$key]);
}
}

}
}

// re-index the array in case anything got removed.
$entities_data = array_values($entities_data);
return $entities_data;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ class InformationPage extends SfgApiNodeBase {
* {@inheritDoc}
*/
public function setCustomData($entity) {
$data = [
return [
'description' => $entity->get('field_description')->value ?: '',
'part_of' => $this->getReferencedEntity($entity->get('field_transactions')->referencedEntities()),
'partner_agencies' => $this->getReferencedEntity($entity->get('field_departments')->referencedEntities()),
'topics' => $this->getReferencedEntity($entity->get('field_topics')->referencedEntities()),
'related_pages' => $this->getReferencedEntity($entity->get('field_related_content')->referencedEntities(), FALSE, FALSE, TRUE),
'information_section' => $this->getReferencedData($entity->get('field_information_section')->referencedEntities()),
];
$data['information_section'] = $this->getReferencedData($entity->get('field_information_section')->referencedEntities(), TRUE);
return $data;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function setCustomData($entity) {
// @todo finish stubbing out the fields.
'description' => $entity->get('field_about_description')->value,
// 'alert' => '',
'location_address' => $this->getReferencedData($entity->get('field_address')->referencedEntities(), TRUE),
'location_address' => $this->getReferencedData($entity->get('field_address')->referencedEntities()),
// 'contact' => '',
// 'body' => '',
// 'intro' => '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class Image extends SfgApiParagraphBase {
* {@inheritDoc}
*/
public function setCustomData($entity) {
$derp = TRUE;
return [
'value' => $this->getReferencedEntity($entity->get('field_image')->referencedEntities(), TRUE, TRUE),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ abstract class SfgApiParagraphBase extends SfgApiPluginBase {
* {@inheritDoc}
*/
public function setBaseData($paragraph) {
$this->checkNullFields();
$base_data = [];
return $base_data;
}

public function checkNullFields() {
$derp = true;
}

}

0 comments on commit b209d41

Please sign in to comment.