Skip to content

Commit e84e382

Browse files
author
jmsche
committed
Fixed Wysiwyg browser
1 parent 595715e commit e84e382

File tree

8 files changed

+48
-25
lines changed

8 files changed

+48
-25
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: php
22

33
php:
4-
- 5.4
4+
- 5.5
55

66
before_script:
77
- curl -s http://getcomposer.org/installer | php

Controller/WysiwygController.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
use Leapt\CoreBundle\Datalist\Datalist;
88
use Leapt\CoreBundle\Datalist\DatalistFactory;
99
use Leapt\CoreBundle\Datalist\Datasource\DoctrineORMDatasource;
10+
use Leapt\CoreBundle\Datalist\Field\Type\ImageFieldType;
11+
use Leapt\CoreBundle\Datalist\Field\Type\TextFieldType;
12+
use Leapt\CoreBundle\Datalist\Filter\Type\SearchFilterType;
13+
use Leapt\CoreBundle\Datalist\Type\DatalistType;
1014
use Symfony\Component\HttpFoundation\Request;
1115

1216
/**
@@ -29,29 +33,32 @@ public function browserAction(Request $request)
2933

3034
/** @var $datalistBuilder \Leapt\CoreBundle\Datalist\DatalistBuilder */
3135
$datalistBuilder = $this->get(DatalistFactory::class)
32-
->createBuilder('datalist', [
33-
'translation_domain' => 'admin',
34-
'data_class' => 'Leapt\AdminBundle\Entity\File'
36+
->createBuilder(DatalistType::class, [
37+
'translation_domain' => 'LeaptAdminBundle',
38+
'data_class' => File::class,
3539
]);
3640

3741
/** @var $datalist Datalist */
3842
$datalist = $datalistBuilder
39-
->addField('path', 'image')
40-
->addField('name', 'text')
41-
->addField('tags', 'text')
42-
->addFilter('name', 'search', ['search_fields' => ['f.name', 'f.tags'], 'label' => 'search'])
43+
->addField('path', ImageFieldType::class, ['label' => 'wysiwyg.browse.image'])
44+
->addField('name', TextFieldType::class)
45+
->addField('tags', TextFieldType::class)
46+
->addFilter('name', SearchFilterType::class, [
47+
'search_fields' => ['f.name', 'f.tags'],
48+
'label' => 'wysiwyg.browse.search',
49+
])
4350
->getDatalist();
4451

4552
/** @var $em \Doctrine\ORM\EntityManager */
4653
$em = $this->getDoctrine()->getManager();
4754
$queryBuilder = $em->createQueryBuilder();
48-
$queryBuilder->select('f')->from('LeaptAdminBundle:File', 'f');
55+
$queryBuilder->select('f')->from(File::class, 'f');
4956

5057
$datasource = new DoctrineORMDatasource($queryBuilder);
5158
$datalist->setDatasource($datasource);
5259
$datalist->bind($request);
5360

54-
if ('POST' === $request->getMethod()) {
61+
if ($request->isMethod('POST')) {
5562
// Manage upload post
5663
if ($request->get('admin_leapt_file') !== null) {
5764
$uploadForm->handleRequest($request);
@@ -64,7 +71,7 @@ public function browserAction(Request $request)
6471
}
6572
}
6673

67-
return $this->render('LeaptAdminBundle:Wysiwyg:browser.html.twig', array_merge(
74+
return $this->render('@LeaptAdmin/Wysiwyg/browser.html.twig', array_merge(
6875
['uploadForm' => $uploadForm->createView(), 'datalist' => $datalist, 'arguments' => $arguments],
6976
$extraParameters
7077
));

DependencyInjection/Compiler/ImCompilerPass.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@
22

33
namespace Leapt\AdminBundle\DependencyInjection\Compiler;
44

5+
use Leapt\ImBundle\Manager as LeaptImManager;
56
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
67
use Symfony\Component\DependencyInjection\ContainerBuilder;
78

8-
class ImCompilerPass implements CompilerPassInterface {
9+
class ImCompilerPass implements CompilerPassInterface
10+
{
911
/**
1012
* Add admin thumb formats to LeaptImBundle if applicable
1113
*
1214
* @param ContainerBuilder $container
1315
*/
1416
public function process(ContainerBuilder $container)
1517
{
16-
if ($container->hasDefinition('leapt_im.manager')) {
18+
if ($container->hasDefinition(LeaptImManager::class)) {
1719
$imFormats = $container->getParameter('leapt_admin.im_formats');
1820
foreach ($imFormats as $name => $config) {
19-
$container->getDefinition('leapt_im.manager')->addMethodCall('addFormat', [$name, $config]);
21+
$container->getDefinition(LeaptImManager::class)->addMethodCall('addFormat', [$name, $config]);
2022
}
2123
}
2224
}
23-
}
25+
}

Form/Type/FileType.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Leapt\AdminBundle\Form\Type;
44

5+
use Leapt\AdminBundle\Entity\File;
56
use Symfony\Component\Form\AbstractType;
67
use Symfony\Component\Form\Extension\Core\Type\TextType;
78
use Symfony\Component\Form\FormBuilderInterface;
@@ -32,8 +33,12 @@ public function buildForm(FormBuilderInterface $builder, array $options)
3233
{
3334
$builder
3435
->add('file', \Symfony\Component\Form\Extension\Core\Type\FileType::class)
35-
->add('name', TextType::class)
36-
->add('tags', TextType::class)
36+
->add('name', TextType::class, [
37+
'attr' => ['placeholder' => 'wysiwyg.upload.placeholder.name'],
38+
])
39+
->add('tags', TextType::class, [
40+
'attr' => ['placeholder' => 'wysiwyg.upload.placeholder.tags'],
41+
])
3742
;
3843
}
3944

@@ -43,7 +48,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
4348
public function configureOptions(OptionsResolver $resolver)
4449
{
4550
$resolver->setDefaults([
46-
'data_class' => 'Leapt\AdminBundle\Entity\File'
51+
'data_class' => File::class,
52+
'translation_domain' => 'LeaptAdminBundle',
4753
]);
4854
}
49-
}
55+
}

Resources/translations/LeaptAdminBundle.en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ wysiwyg:
6363
browse:
6464
title: Browse images
6565
empty: No image yet
66+
image: Image
67+
search: Search
6668
upload:
6769
title: Upload
6870
placeholder:

Resources/translations/LeaptAdminBundle.fr.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ wysiwyg:
6363
browse:
6464
title: Parcourir les images
6565
empty: Pas encore d'image
66+
image: Image
67+
search: Rechercher
6668
upload:
6769
title: Upload
6870
placeholder:

Resources/views/Wysiwyg/upload.html.twig

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@
44
{{ form_start(form, { 'attr': {
55
'method': 'POST',
66
'action': path('leapt_admin_wysiwyg_browser', arguments),
7-
'class': 'well form-inline',
7+
'class': 'well',
88
'novalidate': 'novalidate'
99
} }) }}
10-
{{ form_widget(form.name, { 'attr': { 'placeholder': 'wysiwyg.upload.placeholder.name'|trans({}, 'LeaptAdminBundle') } }) }}
11-
{{ form_widget(form.tags, { 'attr': { 'placeholder': 'wysiwyg.upload.placeholder.tags'|trans({}, 'LeaptAdminBundle') } }) }}
12-
{{ form_widget(form.file) }}
13-
<button type="submit" class="btn">{{ 'wysiwyg.upload.submit'|trans({}, 'LeaptAdminBundle') }}</button>
10+
<div class="row">
11+
<div class="col-xs-6 col-md-3">{{ form_widget(form.name, { 'attr': { 'class': 'form-control' } }) }}</div>
12+
<div class="col-xs-6 col-md-3">{{ form_widget(form.tags, { 'attr': { 'class': 'form-control' } }) }}</div>
13+
<div class="col-md-6">
14+
{{ form_widget(form.file, { 'attr': { 'style': 'display: inline;' } }) }}
15+
<button type="submit" class="btn btn-primary">{{ 'wysiwyg.upload.submit'|trans({}, 'LeaptAdminBundle') }}</button>
16+
</div>
17+
</div>
1418
{{ form_rest(form) }}
1519
{{ form_end(form) }}
1620
{% endif %}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
],
2626
"minimum-stability": "dev",
2727
"require": {
28-
"php": ">=5.4",
28+
"php": ">=5.5",
2929
"symfony/framework-bundle": ">=2.7",
3030
"leapt/core-bundle": "^2.0",
3131
"leapt/bootstrap-bundle": "~2.0.0-alpha",

0 commit comments

Comments
 (0)