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

Update to sf7 #263

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Resources/config/service.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
</parameters>

<services>
<!-- T W I G H E L P E R S -->
<!-- T W I G H E L P E R S -->
<defaults autowire="true" autoconfigure="true"/>
<service id="twig.extension.stfalcon_tinymce" class="%stfalcon_tinymce.twig.extension.class%">
<argument type="service" id="service_container" />
<argument type="service" id="assets.packages" />
<tag name="twig.extension" alias="stfalcon_tinymce" />
</service>
</services>
</container>
</container>
54 changes: 18 additions & 36 deletions Twig/Extension/StfalconTinymceExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use Stfalcon\Bundle\TinymceBundle\Helper\LocaleHelper;
use Symfony\Component\Asset\Packages;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Twig\Environment;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

Expand All @@ -15,10 +17,9 @@
*/
class StfalconTinymceExtension extends AbstractExtension
{
/**
* @var ContainerInterface $container
*/
protected $container;
private Environment $twig;
private ParameterBagInterface $parameterBag;
private RequestStack $requestStack;

/**
* Asset Base Url.
Expand All @@ -27,43 +28,24 @@ class StfalconTinymceExtension extends AbstractExtension
*
* @var string
*/
protected $baseUrl;
protected ?string $baseUrl = null;

/**
* @var Packages
*/
private $packages;
private Packages $packages;

/**
* @param ContainerInterface $container
* @param Packages $packages
* @param ParameterBagInterface $parameterBag
* @param Environment $twig
* @param Packages $packages
*/
public function __construct(ContainerInterface $container, Packages $packages)
public function __construct(ParameterBagInterface $parameterBag, Environment $twig, Packages $packages, RequestStack $requestStack)
{
$this->container = $container;
$this->twig = $twig;
$this->packages = $packages;
}

/**
* @param string $id The service identifier
*
* @return object The associated service
*/
public function getService($id)
{
return $this->container->get($id);
}

/**
* Get parameters from the service container.
*
* @param string $name
*
* @return mixed
*/
public function getParameter($name)
{
return $this->container->getParameter($name);
$this->parameterBag = $parameterBag;
$this->requestStack = $requestStack;
}

/**
Expand Down Expand Up @@ -91,7 +73,7 @@ public function getFunctions(): array
*/
public function tinymceInit($options = []): string
{
$config = $this->getParameter('stfalcon_tinymce.config');
$config = $this->parameterBag->get('stfalcon_tinymce.config');
$config = array_merge_recursive($config, $options);

$this->baseUrl = $config['base_url'] ?? null;
Expand Down Expand Up @@ -134,7 +116,7 @@ public function tinymceInit($options = []): string
// If the language is not set in the config...
if (!isset($config['language']) || empty($config['language'])) {
// get it from the request
$config['language'] = $this->container->get('request_stack')->getCurrentRequest()->getLocale();
$config['language'] = $this->requestStack->getCurrentRequest()->getLocale();
}

$config['language'] = LocaleHelper::getLanguage($config['language']);
Expand Down Expand Up @@ -187,7 +169,7 @@ public function tinymceInit($options = []): string
\json_encode($config)
);

return $this->getService('twig')->render(
return $this->twig->render(
'@StfalconTinymce/Script/init.html.twig',
[
'tinymce_config' => $tinymceConfiguration,
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
"issues": "https://github.com/stfalcon/TinymceBundle/issues"
},
"require": {
"php": "^7.2.5|^8.0",
"symfony/framework-bundle": "^5.0|^6.0",
"twig/twig": "^2.12|^3.0"
"php": "^7.2.5 || >=8.0",
"symfony/framework-bundle": "^5.0 || ^6.0 || ^7.0",
"twig/twig": "^2.12 || ^3.0"
},
"autoload": {
"psr-0": {
Expand Down