Added Help button functionality.
Signed-off-by: Gergely POLONKAI <polesz@w00d5t0ck.info>master
parent
aed588e5e2
commit
528c373ad9
@ -0,0 +1,5 @@
|
||||
<p>
|
||||
A könyvek részletes adatait a szerzőre, címre vagy a kiadás évére kattintva
|
||||
tudhatod meg. Az ekkor felbukkanó ablakban tudod bejelölni, ha neked is van
|
||||
egy példányod, vagy ha pl. szeretnél kölcsönkérni egyet.
|
||||
<p>
|
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace KekRozsak\FrontBundle\Twig;
|
||||
|
||||
use JMS\DiExtraBundle\Annotation as DI;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Routing\Exception\RouteNotFoundException;
|
||||
|
||||
/**
|
||||
* Description of HelpUrlExtension
|
||||
*
|
||||
* @author Gergely Polonkai
|
||||
*
|
||||
* @DI\Service
|
||||
* @DI\Tag("twig.extension")
|
||||
*/
|
||||
class HelpUrlExtension extends \Twig_Extension
|
||||
{
|
||||
/**
|
||||
* @var Symfony\Component\DependencyInjection\ContainerInterface $container
|
||||
*/
|
||||
private $container;
|
||||
|
||||
/**
|
||||
* @DI\InjectParams({
|
||||
* "container" = @DI\Inject("service_container")
|
||||
* })
|
||||
*/
|
||||
public function __construct(ContainerInterface $container) {
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function getGlobals() {
|
||||
parent::getGlobals();
|
||||
|
||||
$request = $this->container->get('request');
|
||||
$router = $this->container->get('router');
|
||||
|
||||
$currentRoute = $request->get('_route');
|
||||
$m = array();
|
||||
$helpRoutes = array($currentRoute . 'Help');
|
||||
$helpUrl = null;
|
||||
|
||||
if (preg_match('/^([^_]+)_([a-z]+)/', $currentRoute, $m)) {
|
||||
$helpRoutes[] = $m[1] . '_' . $m[2] . 'Help';
|
||||
}
|
||||
|
||||
foreach ($helpRoutes as $helpRoute) {
|
||||
try {
|
||||
$helpUrl = $router->generate($helpRoute);
|
||||
} catch (RouteNotFoundException $e) {
|
||||
$helpUrl = null;
|
||||
}
|
||||
if ($helpUrl !== null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'helpUrl' => $helpUrl,
|
||||
);
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'HelpUrl';
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue