Skip to content

Commit 35a6f90

Browse files
committed
Initial commit
1 parent bf2984c commit 35a6f90

File tree

90 files changed

+10462
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+10462
-0
lines changed

AvocodeFormExtensionsBundle.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Avocode\FormExtensionsBundle;
4+
5+
use Symfony\Component\HttpKernel\Bundle\Bundle;
6+
7+
/**
8+
* Form extensions for Symfony2 Admingenerator project
9+
*
10+
* @author Piotr Gołębiewski <[email protected]>
11+
*/
12+
class AvocodeFormExtensionsBundle extends Bundle
13+
{
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Avocode\FormExtensionsBundle\DependencyInjection;
4+
5+
use Symfony\Component\Config\FileLocator;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
use Symfony\Component\DependencyInjection\Loader;
8+
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
9+
10+
/**
11+
* Loads FormExtensions configuration
12+
*/
13+
class AvocodeFormExtensionsExtension extends Extension
14+
{
15+
/**
16+
* {@inheritDoc}
17+
*/
18+
public function load(array $configs, ContainerBuilder $container)
19+
{
20+
$configuration = new Configuration();
21+
$config = $this->processConfiguration($configuration, $configs);
22+
23+
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
24+
$loader->load('services.xml');
25+
}
26+
}

DependencyInjection/Configuration.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Avocode\FormExtensionsBundle\DependencyInjection;
4+
5+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6+
use Symfony\Component\Config\Definition\ConfigurationInterface;
7+
8+
/**
9+
* Validates and merges configuration
10+
*/
11+
class Configuration implements ConfigurationInterface
12+
{
13+
/**
14+
* {@inheritDoc}
15+
*/
16+
public function getConfigTreeBuilder()
17+
{
18+
$treeBuilder = new TreeBuilder();
19+
$rootNode = $treeBuilder->root('avocode_form_extensions');
20+
21+
return $treeBuilder;
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Avocode\FormExtensionsBundle\Form\DataTransformer;
4+
5+
use Symfony\Component\Form\DataTransformerInterface;
6+
use Symfony\Component\Form\Exception\UnexpectedTypeException;
7+
8+
/**
9+
* {@inheritdoc}
10+
*
11+
* @author Bilal Amarni <[email protected]>
12+
*/
13+
class ArrayToStringTransformer implements DataTransformerInterface
14+
{
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
public function transform($array)
19+
{
20+
if (null === $array || !is_array($array)) {
21+
return '';
22+
}
23+
24+
return implode(',', $array);
25+
}
26+
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
public function reverseTransform($string)
31+
{
32+
if (is_array($string)) {
33+
return $string;
34+
}
35+
36+
return explode(',', $string);
37+
}
38+
}

Form/Type/ColorType.php

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace Avocode\FormExtensionsBundle\Form\Type;
4+
5+
use Symfony\Component\Form\AbstractType;
6+
use Symfony\Component\Form\FormBuilderInterface;
7+
use Symfony\Component\Form\FormView;
8+
use Symfony\Component\Form\FormInterface;
9+
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
10+
11+
/**
12+
* ColorType
13+
*
14+
* @author Olivier Chauvel <[email protected]>
15+
*/
16+
class ColorType extends AbstractType
17+
{
18+
/**
19+
* {@inheritdoc}
20+
*/
21+
public function buildView(FormView $view, FormInterface $form, array $options)
22+
{
23+
$view->vars['widget'] = $options['widget'];
24+
$view->vars['configs'] = $options['configs'];
25+
}
26+
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
public function setDefaultOptions(OptionsResolverInterface $resolver)
31+
{
32+
$resolver
33+
->setDefaults(array(
34+
'widget' => 'text',
35+
'configs' => array(),
36+
))
37+
->setAllowedValues(array(
38+
'widget' => array(
39+
'text',
40+
'image',
41+
)
42+
))
43+
;
44+
}
45+
46+
/**
47+
* {@inheritdoc}
48+
*/
49+
public function getParent()
50+
{
51+
return 'text';
52+
}
53+
54+
/**
55+
* {@inheritdoc}
56+
*/
57+
public function getName()
58+
{
59+
return 'color';
60+
}
61+
}

Form/Type/Select2Type.php

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
3+
namespace Avocode\FormExtensionsBundle\Form\Type;
4+
5+
use Avocode\FormExtensionsBundle\Form\DataTransformer\ArrayToStringTransformer;
6+
use Symfony\Component\Form\AbstractType;
7+
use Symfony\Component\Form\FormBuilderInterface;
8+
use Symfony\Component\Form\FormView;
9+
use Symfony\Component\Form\FormInterface;
10+
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
11+
use Symfony\Component\OptionsResolver\Options;
12+
13+
/**
14+
* Select2Type to JQueryLib
15+
*
16+
* @author Bilal Amarni <[email protected]>
17+
* @author Chris Tickner <[email protected]>
18+
*/
19+
class Select2Type extends AbstractType
20+
{
21+
private $widget;
22+
23+
public function __construct($widget)
24+
{
25+
$this->widget = $widget;
26+
}
27+
28+
/**
29+
* {@inheritdoc}
30+
*/
31+
public function buildForm(FormBuilderInterface $builder, array $options)
32+
{
33+
if ('hidden' === $this->widget && !empty($options['configs']['multiple'])) {
34+
$builder->addViewTransformer(new ArrayToStringTransformer());
35+
} elseif ('hidden' === $this->widget && empty($options['configs']['multiple']) && null !== $options['transformer']) {
36+
$builder->addModelTransformer($options['transformer']);
37+
}
38+
}
39+
40+
/**
41+
* {@inheritdoc}
42+
*/
43+
public function buildView(FormView $view, FormInterface $form, array $options)
44+
{
45+
$view->vars['configs'] = $options['configs'];
46+
47+
// Adds a custom block prefix
48+
array_splice(
49+
$view->vars['block_prefixes'],
50+
array_search($this->getName(), $view->vars['block_prefixes']),
51+
0,
52+
'select2'
53+
);
54+
}
55+
56+
/**
57+
* {@inheritdoc}
58+
*/
59+
public function setDefaultOptions(OptionsResolverInterface $resolver)
60+
{
61+
$defaults = array(
62+
'placeholder' => 'Select a value',
63+
'allowClear' => false,
64+
'minimumInputLength' => 0,
65+
'width' => 'element',
66+
);
67+
$resolver
68+
->setDefaults(array(
69+
'configs' => $defaults,
70+
'transformer' => null,
71+
))
72+
->setNormalizers(array(
73+
'configs' => function (Options $options, $configs) use ($defaults) {
74+
return array_merge($defaults, $configs);
75+
},
76+
))
77+
;
78+
}
79+
80+
/**
81+
* {@inheritdoc}
82+
*/
83+
public function getParent()
84+
{
85+
return $this->widget;
86+
}
87+
88+
/**
89+
* {@inheritdoc}
90+
*/
91+
public function getName()
92+
{
93+
return 'select2_' . $this->widget;
94+
}
95+
}

LICENSE

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Avocode FormExtensions Bundle
2+
-------------------------------------------------
3+
This bundle includes various third-party software assets each distributed
4+
under it's own license. Bundle files which are not subject to any of these
5+
licenses are released under MIT license included in file:
6+
/Resources/meta/MIT-LICENSE
7+
8+
List of third-party software and their licenses
9+
=================================================
10+
11+
Note: all files in Location directory are subject to corresonding License.
12+
13+
Select2
14+
---------------------
15+
Version: 3.4.0
16+
Location: /Resources/public/select2
17+
License: /Resources/public/select2/LICENSE
18+
19+
Select2 is licensed under the Apache Software Foundation License Version 2.0
20+
and GPL Version 2.0.
21+
22+
Colorpicker
23+
-----------
24+
Location: /Resources/public/colorpicker
25+
License: /Resources/public/colorpicker/LICENSE
26+
27+
Dual licensed under the MIT and GPL licenses.

Resources/config/services.xml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
6+
7+
<parameters>
8+
<parameter key="avocode.form.extensions.color.options" type="collection" />
9+
</parameters>
10+
11+
<services>
12+
<service id="avocode.form.extensions.type.select2" class="Avocode\FormExtensionsBundle\Form\Type\Select2Type" abstract="true" />
13+
14+
<service id="avocode.form.extensions.type.color" class="Genemu\Bundle\FormBundle\Form\JQuery\Type\ColorType">
15+
<tag name="form.type" alias="color" />
16+
<argument>%avocode.form.extensions.color.options%</argument>
17+
</service>
18+
</services>
19+
20+
</container>

Resources/meta/MIT-LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Note: this license does not apply to all files contained in this bundle!
2+
For more info please read the LICENSE file in top bundle directory.
3+
4+
Copyright (c) 2012-2013 Piotr Gołębiewski
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.

Resources/public/colorpicker/LICENSE

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Copyright (c) 2001 - 2011 Stefan Petre
2+
3+
Dual licensed under the MIT and GPL licenses.
4+
5+
You may read the MIT license in file:
6+
/Resources/public/colorpicker/meta/MIT-LICENSE
7+
8+
You may obtain a copy of GPL License at:
9+
http://www.gnu.org/licenses/gpl.html

0 commit comments

Comments
 (0)