Skip to content
This repository was archived by the owner on Apr 14, 2026. It is now read-only.

Commit 77d34a3

Browse files
blumpdbu
authored andcommitted
Fix sf3 (#155)
Add Symfony 3.0 support
1 parent d0fca73 commit 77d34a3

File tree

10 files changed

+80
-22
lines changed

10 files changed

+80
-22
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ matrix:
2828
env: SYMFONY_VERSION=2.3.*
2929
- php: 5.6
3030
env: SYMFONY_VERSION=2.8.*
31+
- php: 5.6
32+
env: SYMFONY_VERSION=3.0.*
3133
fast_finish: true
3234

3335
before_install:

Form/Type/FileType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Cmf\Bundle\MediaBundle\File\UploadFileHelperInterface;
1515
use Symfony\Cmf\Bundle\MediaBundle\Form\DataTransformer\ModelToFileTransformer;
16+
use Symfony\Cmf\Bundle\MediaBundle\Util\LegacyFormHelper;
1617
use Symfony\Component\Form\AbstractType;
1718
use Symfony\Component\Form\FormBuilderInterface;
1819
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -56,7 +57,7 @@ public function __construct($class, UploadFileHelperInterface $uploadFileHelper)
5657
*/
5758
public function getParent()
5859
{
59-
return 'file';
60+
return LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\FileType');
6061
}
6162

6263
/**

Tests/Resources/Controller/PhpcrFileTestController.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@
1616
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
1717
use Symfony\Cmf\Bundle\MediaBundle\File\UploadFileHelperInterface;
1818
use Symfony\Cmf\Bundle\MediaBundle\Tests\Resources\Document\Content;
19+
use Symfony\Cmf\Bundle\MediaBundle\Util\LegacyFormHelper;
1920
use Symfony\Component\HttpFoundation\Request;
2021
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
2122

2223
class PhpcrFileTestController extends Controller
2324
{
2425
public function getUploadForm()
2526
{
26-
$type = method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') ? 'Symfony\Component\Form\Extension\Core\Type\FileType' : 'file';
27-
28-
return $this->container->get('form.factory')->createNamedBuilder(null, 'form')
29-
->add('file', $type)
27+
return $this->container->get('form.factory')->createNamedBuilder(null, LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\FormType'))
28+
->add('file', LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\FileType'))
3029
->getForm()
3130
;
3231
}
@@ -38,12 +37,10 @@ protected function getContentForm(Content $contentObject = null)
3837
$contentObject = new Content();
3938
}
4039

41-
$type = method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') ? 'Symfony\Cmf\Bundle\MediaBundle\Form\Type\FileType' : 'cmf_media_file';
42-
4340
return $this->createFormBuilder($contentObject)
4441
->add('name')
4542
->add('title')
46-
->add('file', $type, array('required' => $is_new))
43+
->add('file', LegacyFormHelper::getType('Symfony\Cmf\Bundle\MediaBundle\Form\Type\FileType'), array('required' => $is_new))
4744
->getForm()
4845
;
4946
}

Tests/Resources/Controller/PhpcrImageTestController.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@
1717
use Symfony\Cmf\Bundle\MediaBundle\Doctrine\Phpcr\Image;
1818
use Symfony\Cmf\Bundle\MediaBundle\File\UploadFileHelperInterface;
1919
use Symfony\Cmf\Bundle\MediaBundle\Tests\Resources\Document\Content;
20+
use Symfony\Cmf\Bundle\MediaBundle\Util\LegacyFormHelper;
2021
use Symfony\Component\HttpFoundation\Request;
2122
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
2223

2324
class PhpcrImageTestController extends Controller
2425
{
2526
protected function getUploadForm()
2627
{
27-
$type = method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') ? 'Symfony\Component\Form\Extension\Core\Type\FileType' : 'file';
28-
29-
return $this->container->get('form.factory')->createNamedBuilder(null, 'form')
30-
->add('image', $type)
28+
return $this->container->get('form.factory')->createNamedBuilder(null, LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\FormType'))
29+
->add('image', LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\FileType'))
3130
->getForm()
3231
;
3332
}
@@ -37,12 +36,11 @@ protected function getContentForm(Content $contentObject = null, array $imageOpt
3736
if (is_null($contentObject)) {
3837
$contentObject = new Content();
3938
}
40-
$type = method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix') ? 'Symfony\Cmf\Bundle\MediaBundle\Form\Type\ImageType' : 'cmf_media_image';
4139

4240
return $this->createFormBuilder($contentObject)
4341
->add('name')
4442
->add('title')
45-
->add('file', $type, array_merge(array('required' => false, 'label' => 'Image'), $imageOptions))
43+
->add('file', LegacyFormHelper::getType('Symfony\Cmf\Bundle\MediaBundle\Form\Type\ImageType'), array_merge(array('required' => false, 'label' => 'Image'), $imageOptions))
4644
->getForm()
4745
;
4846
}

Tests/Resources/app/config/cmf_media.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
twig:
2-
form:
3-
resources:
4-
- 'CmfMediaBundle:Form:fields.html.twig'
5-
61
cmf_media:
72
persistence:
83
phpcr:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
imports:
2+
- { resource: cmf_media.yml }
3+
4+
twig:
5+
form:
6+
resources:
7+
- 'CmfMediaBundle:Form:fields.html.twig'
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
imports:
2+
- { resource: cmf_media.yml }
3+
4+
twig:
5+
form_themes:
6+
- 'CmfMediaBundle:Form:fields.html.twig'

Tests/Resources/app/config/config.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@
1212
$container->setParameter('cmf_testing.bundle_fqn', 'Symfony\Cmf\Bundle\MediaBundle');
1313
$loader->import(CMF_TEST_CONFIG_DIR.'/default.php');
1414
$loader->import(CMF_TEST_CONFIG_DIR.'/phpcr_odm.php');
15-
$loader->import(__DIR__.'/cmf_media.yml');
15+
if (version_compare(strtolower(\Symfony\Component\HttpKernel\Kernel::VERSION), '3.0', '<')) {
16+
$loader->import(__DIR__.'/cmf_media_2.yml');
17+
} else {
18+
$loader->import(__DIR__.'/cmf_media_3.yml');
19+
}
1620
$loader->import(__DIR__.'/security.yml');

Util/LegacyFormHelper.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony CMF package.
5+
*
6+
* (c) 2011-2015 Symfony CMF
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Cmf\Bundle\MediaBundle\Util;
13+
14+
final class LegacyFormHelper
15+
{
16+
private static $map = array(
17+
'Symfony\Cmf\Bundle\MediaBundle\Form\Type\FileType' => 'cmf_media_file',
18+
'Symfony\Cmf\Bundle\MediaBundle\Form\Type\ImageType' => 'cmf_media_image',
19+
'Symfony\Component\Form\Extension\Core\Type\FileType' => 'file',
20+
'Symfony\Component\Form\Extension\Core\Type\FormType' => 'form',
21+
);
22+
23+
public static function getType($class)
24+
{
25+
if (!self::isLegacy()) {
26+
return $class;
27+
}
28+
29+
if (!isset(self::$map[$class])) {
30+
throw new \InvalidArgumentException(sprintf('Form type with class "%s" can not be found. Please check for typos or add it to the map in LegacyFormHelper', $class));
31+
}
32+
33+
return self::$map[$class];
34+
}
35+
36+
public static function isLegacy()
37+
{
38+
return !method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix');
39+
}
40+
41+
private function __construct()
42+
{
43+
}
44+
45+
private function __clone()
46+
{
47+
}
48+
}

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
],
1414
"require": {
1515
"php": "^5.3.9|^7.0",
16-
"symfony/framework-bundle": "~2.3"
16+
"symfony/framework-bundle": "~2.3|~3.0"
1717
},
1818
"require-dev": {
1919
"twig/twig": "^1.12|^2.0",
2020
"symfony-cmf/testing": "^1.3",
2121
"doctrine/phpcr-odm": "^1.3",
2222
"doctrine/annotations": "^1.1.2",
2323
"jms/serializer-bundle": "^0.12|^1.0",
24-
"liip/imagine-bundle": "~1.0.4",
24+
"liip/imagine-bundle": "^1.0.4",
2525
"mikey179/vfsStream": "^1.2"
2626
},
2727
"suggest": {

0 commit comments

Comments
 (0)