Added the UserDataSpan Twig extension
This Twig extension can filter User entities, creating a HTML <span> element from them with the class userdata, which can later be converted to an AJAX tooltip with jquery.cluetip Signed-off-by: Gergely Polonkai <polesz@w00d5t0ck.info>
This commit is contained in:
@@ -4,7 +4,9 @@ namespace KekRozsak\SecurityBundle\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Symfony\Component\Security\Core\SecurityContext;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
@@ -121,4 +123,17 @@ class DefaultController extends Controller
|
||||
return array(
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/profil/{id}/ajax-felhasznalo-info.{_format}", name="KekRozsakSecurityBundle_ajaxUserdata", requirements={"_format": "html"})
|
||||
* @Method({"GET"})
|
||||
* @Template()
|
||||
* @ParamConverter("user")
|
||||
*/
|
||||
public function ajaxUserdataAction(User $user)
|
||||
{
|
||||
return array(
|
||||
'user' => $user,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -8,5 +8,10 @@
|
||||
<argument type="service" id="doctrine" />
|
||||
<tag name="kernel.event_listener" event="security.authentication.success" />
|
||||
</service>
|
||||
<service id="kek_rozsak_security.twig_extension.userdataspan" class="KekRozsak\SecurityBundle\Twig\UserDataSpanExtension">
|
||||
<argument type="service" id="service_container" />
|
||||
<argument type="service" id="security.context" />
|
||||
<tag name="twig.extension" />
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
@@ -0,0 +1,10 @@
|
||||
{# vim: ft=htmljinja
|
||||
#}
|
||||
<html>
|
||||
<head>
|
||||
<title>{{ user.displayName }}</title>
|
||||
</head>
|
||||
<body>
|
||||
Tagság kezdete: {{ user.registeredAt|date('Y-m-d') }}
|
||||
</body>
|
||||
</html>
|
41
src/KekRozsak/SecurityBundle/Twig/UserDataSpanExtension.php
Normal file
41
src/KekRozsak/SecurityBundle/Twig/UserDataSpanExtension.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace KekRozsak\SecurityBundle\Twig;
|
||||
|
||||
use Symfony\Component\Security\Core\SecurityContextInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
use KekRozsak\SecurityBundle\Entity\User;
|
||||
|
||||
class UserDataSpanExtension extends \Twig_Extension
|
||||
{
|
||||
protected $_securityContext;
|
||||
protected $_serviceContainer;
|
||||
|
||||
public function __construct(ContainerInterface $container, SecurityContextInterface $security)
|
||||
{
|
||||
$this->_serviceContainer = $container;
|
||||
$this->_securityContext = $security;
|
||||
}
|
||||
|
||||
public function getFilters()
|
||||
{
|
||||
return array(
|
||||
'userdataspan' => new \Twig_Filter_Method($this, 'getUserDataSpan', array('is_safe' => array('html'))),
|
||||
);
|
||||
}
|
||||
|
||||
public function getUserDataSpan(User $user)
|
||||
{
|
||||
if (!is_object($this->_securityContext->getToken()) || !is_object($this->_securityContext->getToken()->getUser()))
|
||||
return '<span class="userdata-secret" title="|Felhasználó|A felhasználóink kiléte szigorúan bizalmas, csak a tagok számára elérhető.">[nem jelenhet meg]</span>';
|
||||
|
||||
return '<span class="userdata" rel="' . $this->_serviceContainer->get('router')->generate('KekRozsakSecurityBundle_ajaxUserdata', array('id' => $user->getId(), '_format' => 'html')) . '">' . $user->getDisplayName() . '</span>';
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'twig_userdataspan';
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user