Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement isallowed twig function #1058

Merged
merged 1 commit into from Feb 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/Twig/UserExtension.php
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Bolt\Twig;

use Symfony\Component\Security\Core\Security;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class UserExtension extends AbstractExtension
{
/** @var Security */
private $security;

public function __construct(Security $security)
{
$this->security = $security;
}

/**
* {@inheritdoc}
*/
public function getFunctions(): array
{
return [
new TwigFunction('isallowed', [$this, 'isAllowed']),
];
}

/**
* @todo Replace with better method, once we've implemented https://github.com/bolt/core/issues/186
*/
public function isAllowed(): bool
{
if ($this->security->getUser()) {
return true;
}

return false;
}
}