public function WidgetResultsController::nodeResults in Rate 8.2
Display rate voting results views on nodes.
Parameters
\Drupal\node\NodeInterface $node: The node for which to display results.
Return value
array The render array.
1 string reference to 'WidgetResultsController::nodeResults'
File
- src/
Controller/ WidgetResultsController.php, line 51
Class
- WidgetResultsController
- Returns responses for Rate routes.
Namespace
Drupal\rate\ControllerCode
public function nodeResults(NodeInterface $node) {
$entity_type_id = $node
->getEntityTypeId();
$bundle = $node
->bundle();
// First, make sure the data is fresh.
$cache_bins = Cache::getBins();
$cache_bins['data']
->deleteAll();
// Check if the node has widgets enabled.
$widgets = $this->entityTypeManager
->getStorage('rate_widget')
->loadMultiple();
if (!empty($widgets)) {
foreach ($widgets as $widget => $widget_variables) {
$entities = $widget_variables
->get('entity_types');
if ($entities && count($entities) > 0) {
foreach ($entities as $entity) {
if ($entity == $entity_type_id . '.' . $bundle) {
// Get and return the rate results views.
$page[] = [
'#type' => '#markup',
'#markup' => '<strong>' . $widget_variables
->label() . '</strong>',
];
$page[] = views_embed_view('rate_widgets_results', 'node_summary_block', $node
->id(), $node
->getEntityTypeId(), $widget);
$page[] = views_embed_view('rate_widgets_results', 'node_results_block', $node
->id(), $node
->getEntityTypeId(), $widget);
}
}
}
}
}
return $page;
}