Commit 00f98e93 authored by swentel's avatar swentel
Browse files

Issue #2838153: render 'real' value of first filters

parent d1a4a721
......@@ -2,9 +2,13 @@
namespace Drupal\views_filters_summary\Plugin\views\area;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\views\Plugin\views\area\AreaPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Views filters summary.
......@@ -15,6 +19,55 @@ use Drupal\views\Plugin\views\area\AreaPluginBase;
*/
class ViewsFiltersSummary extends AreaPluginBase {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The bundle info service.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $bundleInfoService;
/**
* Constructs a ViewsFiltersSummary object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $bundle_info_service
* The bundle info service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $bundle_info_service) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
$this->bundleInfoService = $bundle_info_service;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('entity_type.manager'),
$container->get('entity_type.bundle.info')
);
}
/**
* {@inheritdoc}
*/
......@@ -104,12 +157,28 @@ class ViewsFiltersSummary extends AreaPluginBase {
}
}
$value = $filter->value[0];
switch ($filter->definition['id']) {
case 'taxonomy_index_tid':
case 'taxonomy_index_tid_depth':
$term = $this->entityTypeManager->getStorage('taxonomy_term')->load($value);
if ($term) {
$value = $term->label();
}
break;
case 'bundle':
$types = $this->bundleInfoService->getBundleInfo($filter->definition['entity_type']);
if (isset($types[$value])) {
$value = $types[$value]['label'];
}
break;
}
$summary[] = [
'id' => $id,
'label' => $label,
'show_label' => $show_label,
// TODO get real value
'value' => $filter->value[0],
'value' => $value,
'url' => $url->toString(),
];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment