Using Drupal 8 entity query I'm trying to figure how I can fetch values from a specific content type and group them that are associated via a specific taxonomy term.
As seen in the screenshot below I have an entity field called Group Schedule
that is currently binded to a Taxonomy Term. Is there way I could group those entities that are assigned to a specific taxonomy?
Group Schedule Name (field_group_sched)
First Schedule (field_created_date)
Second Schedule (field_created_date)
Group Schedule Name 2 (field_group_sched)
First Schedule (field_created_date)
Second Schedule (field_created_date)
So far I've managed to fetch the values from the Schedule
Content type
// Entity Query for Schedule Node Type
$scheduleType = $query->get('node')
->condition('status', 1, '=')
->condition('type', 'schedule')
->condition('field_associated_programs', $nid_degree, '=')
->sort('created')
->execute();
foreach ($scheduleType as $key => $program) {
$programNode = _nodeLoad($program);
$variables['schedule_content'][$key]['schedule_group'] = $programNode->get('field_group_sched')->value;
$variables['schedule_content'][$key]['schedule_name'] = $programNode->get('field_schedule_name')->value;
$variables['schedule_content'][$key]['schedule_date'] = $programNode->get('field_created_date')->value;
}
{% for program in schedule_content %}
<div class="scheduled-dates">
<h3 class="label">{{ program['schedule_group'] }}</h3>
<span data-label="{{ program['schedule_name'] }}" class="date" >{{ program['schedule_date'] }}</span>
</div>
{% endfor %}
Group Schedule
field as shown in the screenshot. Lets say I have to two nodes that are associated with a specific taxonomy. I want to group those two nodes and output them on the twig using custom code.entity query
that is created on the.theme
file. The second block of code is the markup on how I can display the output on the twig file