Skip to content

Commit

Permalink
Ugrade to Sf4
Browse files Browse the repository at this point in the history
  • Loading branch information
gzumba committed Jul 12, 2019
1 parent e8381a8 commit d367188
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
3 changes: 1 addition & 2 deletions Resources/config/service.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

<services>
<!-- T W I G H E L P E R S -->
<service id="twig.extension.stfalcon_tinymce" class="%stfalcon_tinymce.twig.extension.class%">
<argument type="service" id="service_container" />
<service id="twig.extension.stfalcon_tinymce" class="%stfalcon_tinymce.twig.extension.class%" autowire="true">
<tag name="twig.extension" alias="stfalcon_tinymce" />
</service>
</services>
Expand Down
53 changes: 28 additions & 25 deletions Twig/Extension/StfalconTinymceExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
namespace Stfalcon\Bundle\TinymceBundle\Twig\Extension;

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

/**
* Twig Extension for TinyMce support.
*
* @author naydav <[email protected]>
*/
class StfalconTinymceExtension extends \Twig_Extension
class StfalconTinymceExtension extends AbstractExtension
{
/**
* @var ContainerInterface $container Container interface
Expand All @@ -24,27 +29,31 @@ class StfalconTinymceExtension extends \Twig_Extension
* @var String
*/
protected $baseUrl;
/**
* @var Packages
*/
private $assetPackages;
/**
* @var RequestStack
*/
private $requestStack;
/**
* @var Environment
*/
private $twig;

/**
* Initialize tinymce helper
*
* @param ContainerInterface $container
* @param Packages $assetPackages
*/
public function __construct(ContainerInterface $container)
public function __construct(ContainerInterface $container, Packages $assetPackages, RequestStack $requestStack, Environment $twig)
{
$this->container = $container;
}

/**
* Gets a service.
*
* @param string $id The service identifier
*
* @return object The associated service
*/
public function getService($id)
{
return $this->container->get($id);
$this->assetPackages = $assetPackages;
$this->requestStack = $requestStack;
$this->twig = $twig;
}

/**
Expand All @@ -67,7 +76,7 @@ public function getParameter($name)
public function getFunctions()
{
return array(
'tinymce_init' => new \Twig_SimpleFunction(
'tinymce_init' => new TwigFunction(
'tinymce_init',
array($this, 'tinymceInit'),
array('is_safe' => array('html'))
Expand All @@ -93,12 +102,9 @@ public function tinymceInit($options = array())
$assetPackageName = (!isset($config['asset_package_name']) ? null : $config['asset_package_name']);
unset($config['asset_package_name']);

/** @var $assets \Symfony\Component\Templating\Helper\CoreAssetsHelper */
$assets = $this->getService('assets.packages');

// Get path to tinymce script for the jQuery version of the editor
if ($config['tinymce_jquery']) {
$config['jquery_script_url'] = $assets->getUrl(
$config['jquery_script_url'] = $this->assetPackages->getUrl(
$this->baseUrl.'bundles/stfalcontinymce/vendor/tinymce/tinymce.jquery.min.js',
$assetPackageName
);
Expand Down Expand Up @@ -127,7 +133,7 @@ public function tinymceInit($options = array())
// If the language is not set in the config...
if (!isset($config['language']) || empty($config['language'])) {
// get it from the request, if available
$currentRequest = $this->container->get('request_stack')
$currentRequest = $this->requestStack
->getCurrentRequest()
;

Expand Down Expand Up @@ -186,7 +192,7 @@ public function tinymceInit($options = array())
json_encode($config)
);

return $this->getService('templating')->render('StfalconTinymceBundle:Script:init.html.twig', array(
return $this->twig->render('StfalconTinymceBundle:Script:init.html.twig', array(
'tinymce_config' => $tinymceConfiguration,
'include_jquery' => $config['include_jquery'],
'tinymce_jquery' => $config['tinymce_jquery'],
Expand Down Expand Up @@ -214,13 +220,10 @@ public function getName()
*/
protected function getAssetsUrl($inputUrl)
{
/** @var $assets \Symfony\Component\Templating\Helper\CoreAssetsHelper */
$assets = $this->getService('assets.packages');

$url = preg_replace('/^asset\[(.+)\]$/i', '$1', $inputUrl);

if ($inputUrl !== $url) {
return $assets->getUrl($this->baseUrl.$url);
return $this->assetPackages->getUrl($this->baseUrl.$url);
}

return $inputUrl;
Expand Down

0 comments on commit d367188

Please sign in to comment.