Skip to content

Commit

Permalink
Add support for Symfony and Sonata 3.x (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
Webonaute authored and meyerbaptiste committed Aug 22, 2017
1 parent 1336ea5 commit 92473c7
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 21 deletions.
8 changes: 5 additions & 3 deletions Admin/MediaAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@

namespace CoopTilleuls\Bundle\CKEditorSonataMediaBundle\Admin;

use Sonata\AdminBundle\Admin\AdminExtension;
use Sonata\AdminBundle\Admin\AbstractAdminExtension;
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Route\RouteCollection;

/**
* Adds browser and upload routes to the Admin
*
* @author Kévin Dunglas <[email protected]>
*/
class MediaAdminExtension extends AdminExtension
class MediaAdminExtension extends AbstractAdminExtension
{
/**
* {@inheritDoc}
*/
public function configureRoutes(\Sonata\AdminBundle\Admin\AdminInterface $admin, \Sonata\AdminBundle\Route\RouteCollection $collection)
public function configureRoutes(AdminInterface $admin, RouteCollection $collection)
{
$collection->add('browser', 'browser');
$collection->add('upload', 'upload');
Expand Down
21 changes: 20 additions & 1 deletion Controller/MediaAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace CoopTilleuls\Bundle\CKEditorSonataMediaBundle\Controller;

use Sonata\MediaBundle\Controller\MediaAdminController as BaseMediaAdminController;
use Symfony\Component\Form\FormView;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;

/**
Expand Down Expand Up @@ -64,7 +65,7 @@ public function browserAction()
$formView = $datagrid->getForm()->createView();

// set the theme for the current Admin Form
$this->get('twig')->getExtension('form')->renderer->setTheme($formView, $this->admin->getFilterTheme());
$this->setFormTheme($formView, $this->admin->getFilterTheme());

return $this->render($this->getTemplate('browser'), array(
'action' => 'browser',
Expand Down Expand Up @@ -111,4 +112,22 @@ public function uploadAction()
));
}

/**
* Sets the admin form theme to form view. Used for compatibility between Symfony versions.
*
* @param FormView $formView
* @param string $theme
*/
private function setFormTheme(FormView $formView, $theme)
{
$twig = $this->get('twig');
// BC for Symfony < 3.2 where this runtime does not exists
if (!method_exists('Symfony\Bridge\Twig\AppVariable', 'getToken')) {
$twig->getExtension('Symfony\Bridge\Twig\Extension\FormExtension')
->renderer->setTheme($formView, $theme);
return;
}
$twig->getRuntime('Symfony\Bridge\Twig\Form\TwigRenderer')->setTheme($formView, $theme);
}

}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Sonata Media CKEditor Integration

The bundle provides [SonataMediaBundle](https://sonata-project.org/bundles/media/master/doc/index.html) integration into [CKEditor](http://ckeditor.com/) for Symfony 2 projects.
The bundle provides [SonataMediaBundle](https://sonata-project.org/bundles/media/master/doc/index.html) integration into [CKEditor](http://ckeditor.com/) for Symfony projects.

[![Build Status](https://travis-ci.org/coopTilleuls/CoopTilleulsCKEditorSonataMediaBundle.png?branch=master)](https://travis-ci.org/coopTilleuls/CoopTilleulsCKEditorSonataMediaBundle)

Expand Down
32 changes: 17 additions & 15 deletions Resources/views/layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
#}
{% set _preview = block('preview') %}
{% set _form = block('form') %}
{% set _show = block('show') %}
{% set _list_table = block('list_table') %}
{% set _list_filters = block('list_filters') %}
{% set _side_menu = block('side_menu') %}
{% set _content = block('content') %}
{% set _title = block('title') %}
{% set _breadcrumb = block('breadcrumb') %}
{% set _preview = block('preview') is defined ? block('preview') : '' %}
{% set _form = block('form') is defined ? block('form') : '' %}
{% set _show = block('show') is defined ? block('show') : '' %}
{% set _list_table = block('list_table') is defined ? block('list_table') : '' %}
{% set _list_filters = block('list_filters') is defined ? block('list_filters') : '' %}
{% set _side_menu = block('side_menu') is defined ? block('side_menu') : '' %}
{% set _content = block('content') is defined ? block('content') : '' %}
{% set _title = block('title') is defined ? block('title') : '' %}
{% set _breadcrumb = block('breadcrumb') is defined ? block('breadcrumb') : '' %}
<!DOCTYPE html>
<html {% block html_attributes %}class="no-js"{% endblock %}>
<head>
Expand Down Expand Up @@ -59,12 +59,14 @@ file that was distributed with this source code.
{% else %}
{% if action is defined %}
-
{% for menu in admin.breadcrumbs(action) %}
{% if not loop.first %}
&gt;
{% endif %}
{{ menu.label }}
{% endfor %}
{% if admin.breadcrumbs is defined %}
{% for menu in admin.breadcrumbs(action) %}
{% if not loop.first %}
&gt;
{% endif %}
{{ menu.label }}
{% endfor %}
{% endif %}
{% endif %}
{% endif%}
</title>
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
}
],
"require": {
"sonata-project/media-bundle": "~2.3|~3.0"
"sonata-project/media-bundle": "~3.0",
"sonata-project/admin-bundle": "~3.1"
},
"require-dev": {
"symfony/phpunit-bridge": "~2.7|~3.0",
Expand Down

0 comments on commit 92473c7

Please sign in to comment.