Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Function for mass
{
$rteElements = [];
// Hours section.
foreach ($hours as $index => $hour) {
$entity = $hour->entity;
if (!method_exists($entity, 'hasField')) {
return FALSE;
}
// Creates a map of fields that are on the entitiy.
$map = [
'label' => ['field_label','field_hours_group_title'],
'time' => ['field_time_frame','field_hours_structured'],
'hour' => ['field_hours','field_hours_description'],
'description' => ['field_hours_description'],
];
// Determines which fieldnames to use from the map.
$field = Helper::getMappedFields($entity, $map);
$hours_render_array = $entity->field_hours_structured->view('full');
// The first one is styled differently.
// if ($index == 0) {
// $rteElements[] = [
// 'path' => '@molecules/callout-stats.twig',
// 'data' => [
// 'statsCallout' => [
// 'pull' => $align,
// 'stat' => $hours_render_array,
// 'content' => $hours_render_array,
// ],
// ],
// ];
// continue;
// }// }
/*
* "path": "atoms-heading-4",
"data": {
"heading4" : {
"text": "Park"
}
}
*/
$rteElements[] = [
'path' => '@atoms/04-headings/heading-4.twig',
'data' => [
'heading4' => [
'text' => Helper::fieldValue($entity, $field['label']),
]
],
];
$rteElements[] = [
'path' => '@atoms/11-text/paragraph.twig',
'data' => [
'paragraph' => [
'text' => $hours_render_array,
],
],
];
if (Helper::isFieldPopulated($entity, $field['description'])) {
$rteElements[] = [
'path' => '@atoms/11-text/paragraph.twig',
'data' => [
'paragraph' => [
'text' => Helper::fieldValue($entity, $field['description']),
],
],
];
}
}
return [
'path' => '@organisms/by-author/rich-text.twig',
'data' => [
'richText' => [
'property' => '',
'rteElements' => $rteElements,
],
],
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment