Skip to content

Commit

Permalink
pathprocessor added
Browse files Browse the repository at this point in the history
  • Loading branch information
nczirjak-acdh committed Jun 17, 2020
1 parent 5ae46f8 commit 071ae24
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
6 changes: 6 additions & 0 deletions arche_dashboard.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
arche_dashboard.path_processor:
class: 'Drupal\arche_dashboard\PathProcessor\ArcheDashboardPathProcessor'
tags:
- { name: path_processor_inbound, priority: 350 }

29 changes: 26 additions & 3 deletions src/Controller/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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',
Expand All @@ -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 {
Expand Down
28 changes: 28 additions & 0 deletions src/PathProcessor/ArcheDashboardPathProcessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Drupal\arche_dashboard\PathProcessor;

use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
use Symfony\Component\HttpFoundation\Request;

class ArcheDashboardPathProcessor implements InboundPathProcessorInterface
{
public function processInbound($path, Request $request)
{

if (strpos($path, '/dashboard-property/') === 0) {
$names = preg_replace('|^\/dashboard-property\/|', '', $path);
if (strpos($names, 'https:/') === 0) {
$names = str_replace('https:/', 'https://', $names);
} else if (strpos($names, 'http:/') === 0) {
$names = str_replace('http:/', 'http://', $names);
}

$names = strtr(base64_encode($names), '+/=', '._-');
return "/dashboard-property/$names";
}

return $path;
}

}
2 changes: 1 addition & 1 deletion templates/arche-dashboard-table.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{% for kc,kv in cols %}
<td>
{% if kc == 'property' %}
<a href="./dashboard-property/{{ attribute(value, kc) }}" >
<a href="/browser/dashboard-property/{{ attribute(value, kc) }}" >
{{ attribute(value, kc) }}
</a>
{% elseif kc == 'id' %}
Expand Down

0 comments on commit 071ae24

Please sign in to comment.