Skip to content

Commit

Permalink
Merge pull request #172 from cwhartl/feature/sf3-compatibility
Browse files Browse the repository at this point in the history
fixed sf3-incompatibility
  • Loading branch information
AliHichem committed Apr 25, 2017
2 parents 9c2393c + f74be5b commit 5386669
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 18 deletions.
8 changes: 4 additions & 4 deletions Tests/TestBundle/Resources/config/routing.yml
@@ -1,15 +1,15 @@
alidatatable_test_homepage:
pattern: /
path: /
defaults: { _controller: TestBundle:Default:index }

alidatatable_test_grid:
pattern: /grid
path: /grid
defaults: { _controller: TestBundle:Default:grid }

alidatatable_test_delete:
pattern: /
path: /
defaults: { _controller: TestBundle:Default:delete }

alidatatable_test_edit:
pattern: /
path: /
defaults: { _controller: TestBundle:Default:edit }
22 changes: 18 additions & 4 deletions Twig/Extension/AliDatatableExtension.php
Expand Up @@ -3,6 +3,8 @@
namespace Ali\DatatableBundle\Twig\Extension;

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Ali\DatatableBundle\Util\Datatable;

class AliDatatableExtension extends \Twig_Extension
Expand Down Expand Up @@ -109,9 +111,16 @@ public function datatable($options)
*/
private function createDeleteForm($id)
{
return $this->createFormBuilder(array('id' => $id))
->add('id', 'hidden')
->getForm();
if (version_compare(phpversion(), '5.5', '<')) {
return $this->createFormBuilder(array('id' => $id))
->add('id', 'hidden')
->getForm();
}
else {
return $this->createFormBuilder(array('id' => $id))
->add('id', 'Symfony\Component\Form\Extension\Core\Type\HiddenType')
->getForm();
}
}

/**
Expand All @@ -123,7 +132,12 @@ private function createDeleteForm($id)
*/
public function createFormBuilder($data = null, array $options = array())
{
return $this->_container->get('form.factory')->createBuilder('form', $data, $options);
if (version_compare(phpversion(), '5.5', '<')) {
return $this->_container->get('form.factory')->createBuilder('form', $data, $options);
}
else {
return $this->_container->get('form.factory')->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', $data, $options);
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion Util/Datatable.php
Expand Up @@ -4,6 +4,7 @@

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\EntityManager;
Expand Down Expand Up @@ -69,7 +70,7 @@ public function __construct(ContainerInterface $container)
{
$this->_container = $container;
$this->_config = $this->_container->getParameter('ali_datatable');
$this->_request = $this->_container->get('request');
$this->_request = Request::createFromGlobals();
self::$_current_instance = $this;
$this->_applyDefaults();
}
Expand Down
31 changes: 23 additions & 8 deletions Util/Factory/Prototype/PrototypeBuilder.php
Expand Up @@ -3,6 +3,8 @@
namespace Ali\DatatableBundle\Util\Factory\Prototype;

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;

class PrototypeBuilder
{
Expand Down Expand Up @@ -51,14 +53,27 @@ public function __toString()
*/
protected function _delete_form()
{
return $this->container
->get('templating.helper.form')
->widget(
$this->container->get('form.factory')->createBuilder('form', array('id' => '@id'), array())
->add('id', 'hidden')
->getForm()
->createView()
);

if (version_compare(phpversion(), '5.5', '<')) {
return $this->container
->get('templating.helper.form')
->widget(
$this->container->get('form.factory')->createBuilder('form', array('id' => '@id'), array())
->add('id', 'hidden')
->getForm()
->createView()
);
}
else {
return $this->container
->get('templating.helper.form')
->widget(
$this->container->get('form.factory')->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', array('id' => '@id'), array())
->add('id', 'Symfony\Component\Form\Extension\Core\Type\HiddenType')
->getForm()
->createView()
);
}
}

}
3 changes: 2 additions & 1 deletion Util/Factory/Query/DoctrineBuilder.php
Expand Up @@ -5,6 +5,7 @@
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\Expr\Join;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;

class DoctrineBuilder implements QueryInterface
{
Expand Down Expand Up @@ -63,7 +64,7 @@ public function __construct(ContainerInterface $container, $em)
{
$this->container = $container;
$this->em = $em;
$this->request = $this->container->get('request');
$this->request = Request::createFromGlobals();
$this->queryBuilder = $this->em->createQueryBuilder();
}

Expand Down

0 comments on commit 5386669

Please sign in to comment.