Skip to content

Instantly share code, notes, and snippets.

@labbydev
Created May 18, 2017 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save labbydev/69bfb4ab32c44686e29425df746cd9ac to your computer and use it in GitHub Desktop.
Save labbydev/69bfb4ab32c44686e29425df746cd9ac to your computer and use it in GitHub Desktop.
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