From 071ae24254e85e2b88e8014c9c2ef57b7d59459a Mon Sep 17 00:00:00 2001 From: Norbert Czirjak Date: Wed, 17 Jun 2020 10:17:06 +0200 Subject: [PATCH] pathprocessor added --- arche_dashboard.services.yml | 6 ++++ src/Controller/DashboardController.php | 29 +++++++++++++++++-- .../ArcheDashboardPathProcessor.php | 28 ++++++++++++++++++ templates/arche-dashboard-table.html.twig | 2 +- 4 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 src/PathProcessor/ArcheDashboardPathProcessor.php diff --git a/arche_dashboard.services.yml b/arche_dashboard.services.yml index e69de29..bca05d9 100644 --- a/arche_dashboard.services.yml +++ b/arche_dashboard.services.yml @@ -0,0 +1,6 @@ +services: + arche_dashboard.path_processor: + class: 'Drupal\arche_dashboard\PathProcessor\ArcheDashboardPathProcessor' + tags: + - { name: path_processor_inbound, priority: 350 } + diff --git a/src/Controller/DashboardController.php b/src/Controller/DashboardController.php index 7abbe0f..d3354bb 100644 --- a/src/Controller/DashboardController.php +++ b/src/Controller/DashboardController.php @@ -17,6 +17,23 @@ public function __construct() { $this->model = new \Drupal\arche_dashboard\Model\DashboardModel(); } + /** + * This function handle the # removing problem in the browser + * + * @param array $data + * @return array + */ + private function generatePropertyUrl(array $data): array { + foreach($data as $k => $v) { + if(isset($v->property)) { + if (strpos($v->property, "#") !== false) { + $data[$k]->property = str_replace("#", "%23", $v->property); + } + } + } + return $data; + } + /** * Dashboard property count view * @@ -31,6 +48,11 @@ public function dashboard_detail(string $key="properties"): array { } else { $cols = array(); } + /* if the key is the properties then we need to change the # in the url */ + if($key == 'properties') { + $data = $this->generatePropertyUrl($data); + } + // print_r ($cols); return [ '#theme' => 'arche-dashboard-table', @@ -41,16 +63,17 @@ public function dashboard_detail(string $key="properties"): array { ]; } - /** * Dashboard property count distinct values view * * @return array */ public function dashboard_property_detail(string $property): array { - //generate the view - $data = $this->model->getFacet($property); + $property = base64_decode($property); + echo $property; + $data = $this->model->getFacet($property); + if (count($data) > 0 ) { $cols = get_object_vars($data[0]); } else { diff --git a/src/PathProcessor/ArcheDashboardPathProcessor.php b/src/PathProcessor/ArcheDashboardPathProcessor.php new file mode 100644 index 0000000..a9a7763 --- /dev/null +++ b/src/PathProcessor/ArcheDashboardPathProcessor.php @@ -0,0 +1,28 @@ + {% if kc == 'property' %} - + {{ attribute(value, kc) }} {% elseif kc == 'id' %}