WidgetResultsController.php in Rate 8.2
File
src/Controller/WidgetResultsController.php
View source
<?php
namespace Drupal\rate\Controller;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\node\NodeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class WidgetResultsController extends ControllerBase {
protected $entity_type_manager;
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager'));
}
public function nodeResults(NodeInterface $node) {
$entity_type_id = $node
->getEntityTypeId();
$bundle = $node
->bundle();
$cache_bins = Cache::getBins();
$cache_bins['data']
->deleteAll();
$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) {
$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;
}
}