diff --git a/src/Controller/MainController.php b/src/Controller/MainController.php index 0d96851..39804da 100644 --- a/src/Controller/MainController.php +++ b/src/Controller/MainController.php @@ -104,9 +104,6 @@ class MainController extends AbstractController ], $request->get('part') > 1 ? ((int) $request->get('part') - 1) * (int) $this->getParameter('app.main.index.limit') : 0, $this->getParameter('app.main.index.limit') - ), - 'title' => $this->_title( - $request->get('namespace') ) ], $response @@ -153,40 +150,8 @@ class MainController extends AbstractController 'default/main/transaction.html.twig', [ 'request' => $request, - 'record' => $record, - 'title' => $this->_title( - $record['namespace'] - ) - ] - ); - } - - private function _title(string $namespace): ?string - { - $index = new \Kvazar\Index\Manticore(); - - $results = $index->get( - '_KEVA_NS_', - [ - 'crc32_namespace' => crc32( - $namespace - ) + 'record' => $record ] ); - - if ($results) - { - foreach ($results as $result) - { - if ($result['key'] == '_KEVA_NS_') - { - return trim( - $result['value'] - ); - } - } - } - - return null; } } \ No newline at end of file diff --git a/src/Twig/AppExtension.php b/src/Twig/AppExtension.php index dc1d6bc..9682fdf 100644 --- a/src/Twig/AppExtension.php +++ b/src/Twig/AppExtension.php @@ -24,6 +24,13 @@ class AppExtension extends AbstractExtension $this, 'formatType' ] + ), + new TwigFilter( + 'namespace_title', + [ + $this, + 'namespaceTitle' + ] ) ]; } @@ -122,4 +129,35 @@ class AppExtension extends AbstractExtension return '[undefined]'; } } + + public function namespaceTitle( + string $namespace + ): string + { + $index = new \Kvazar\Index\Manticore(); + + $results = $index->get( + '_KEVA_NS_', + [ + 'crc32_namespace' => crc32( + $namespace + ) + ] + ); + + if ($results) + { + foreach ($results as $result) + { + if ($result['key'] == '_KEVA_NS_') + { + return trim( + $result['value'] + ); + } + } + } + + return $namespace; + } } \ No newline at end of file diff --git a/templates/default/main/namespace.html.twig b/templates/default/main/namespace.html.twig index 07e3a61..14e5163 100644 --- a/templates/default/main/namespace.html.twig +++ b/templates/default/main/namespace.html.twig @@ -1,5 +1,5 @@ {% extends 'default/layout.html.twig' %} -{% block title %}{% if title %}{{ title }} - {% endif %}{% if request.get('part') > 1 %}{{ 'Part' | trans | upper }} {{ request.get('part') }} - {% endif %}{{ app.name }}{% endblock %} +{% block title %}{{ request.get('namespace') | namespace_title }} - {% if request.get('part') > 1 %}{{ 'Part' | trans | upper }} {{ request.get('part') }} - {% endif %}{{ app.name }}{% endblock %} {% block favicon %}{% endblock %} {% block body %}