Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GeolocationType.php #379

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Form/Core/EventListener/FileListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@ private function stripQueryString($file)
*/
public static function getSubscribedEvents()
{
return array(FormEvents::BIND => 'onBind');
return array(FormEvents::SUBMIT => 'onBind');
}
}
2 changes: 1 addition & 1 deletion Form/Core/EventListener/GeolocationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ public function onBind(FormEvent $event)
*/
public static function getSubscribedEvents()
{
return array(FormEvents::BIND => 'onBind');
return array(FormEvents::SUBMIT => 'onBind');
}
}
23 changes: 10 additions & 13 deletions Form/Core/Type/TinymceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

/**
Expand Down Expand Up @@ -44,31 +45,27 @@ public function buildView(FormView $view, FormInterface $form, array $options)
$view->vars['configs'] = $options['configs'];
}

/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
public function configureOptions(OptionsResolver $resolver)
{
$configs = array_merge(array(
'language' => \Locale::getDefault(),
),
$this->options);
$this->options);

$resolver
->setDefaults(array(
'configs' => array(),
'required' => false,
'theme' => 'default',
))
->setAllowedTypes(array(
'configs' => 'array',
'theme' => 'string',
))
->setNormalizers(array(
'configs' => function (Options $options, $value) use ($configs) {
->setAllowedTypes('configs','array')
->setAllowedTypes('theme','string')

->setNormalizer(
'configs', function (Options $options, $value) use ($configs) {
return array_merge($configs, $value);
},
))
}
)
;
}

Expand Down
17 changes: 11 additions & 6 deletions Form/JQuery/Type/FileType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

use Genemu\Bundle\FormBundle\Form\Core\EventListener\FileListener;
Expand Down Expand Up @@ -75,7 +76,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
public function configureOptions(OptionsResolver $resolver)
{
$configs = $this->options;

Expand All @@ -86,24 +87,28 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
'multiple' => false,
'configs' => array(),
))
->setNormalizers(array(
'configs' => function (Options $options, $value) use ($configs) {
->setNormalizer('configs', function (Options $options, $value) use ($configs) {
if (!$options['multiple']) {
$value['multi'] = false;
}

return array_merge($configs, $value);
}
))
)
;
}

/**
* {@inheritdoc}
*/
public function getParent()
public function getParent()
{
return 'file';
return \Symfony\Component\Form\Extension\Core\Type\FileType::class;
}


public function getBlockPrefix(){
return 'genumu_' . parent::getBlockPrefix();
}

/**
Expand Down
16 changes: 9 additions & 7 deletions Form/JQuery/Type/GeolocationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

use Genemu\Bundle\FormBundle\Form\Core\EventListener\GeolocationListener;

/**
* GeolocationType to JQueryLib
* GeolocationType to JQueryLib.
*
* @author Olivier Chauvel <[email protected]>
*/
Expand All @@ -31,7 +31,7 @@ class GeolocationType extends AbstractType
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('address', 'text');
$builder->add('address', 'text', array('required' => false));

foreach (array('latitude', 'longitude', 'locality', 'country') as $field) {
$option = $options[$field];
Expand All @@ -56,18 +56,20 @@ public function buildForm(FormBuilderInterface $builder, array $options)
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars = array_replace($view->vars, array(
'configs' => array(),
'elements' => array(),
'map' => $options['map']
'configs' => $options['configs'],
'elements' => array(),
'map' => $options['map'],
));
}

/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'configs' => array(),
//'data_class' => 'Genemu\Bundle\FormBundle\Geolocation\AddressGeolocation',
'map' => false,
'latitude' => array(
'enabled' => false,
Expand Down
57 changes: 51 additions & 6 deletions Geolocation/AddressGeolocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* @author Olivier Chauvel <[email protected]>
*/
class AddressGeolocation implements \Serializable
class AddressGeolocation implements \Serializable, \ArrayAccess
{
private $address;
private $latitude;
Expand All @@ -36,21 +36,46 @@ public function getAddress()
return $this->address;
}

public function setAddress($a = null)
{
$this->address = $a;
}

public function getLatitude()
{
return $this->latitude;
}

public function setLatitude($latitude)
{
$this->latitude = $latitude;
}

public function getLongitude()
{
return $this->longitude;
}

public function setLongitude($long)
{
$this->longitude = $long;
}

public function getLocality()
{
return $this->locality;
}

public function setLocality($locality)
{
$this->locality = $locality;
}

public function setCountry($country)
{
$this->country = $country;
}

public function getCountry()
{
return $this->country;
Expand All @@ -59,22 +84,42 @@ public function getCountry()
public function serialize()
{
return serialize(array(
'address' => $this->address,
'latitude' => $this->latitude,
'address' => $this->address,
'latitude' => $this->latitude,
'longitude' => $this->longitude,
'locality' => $this->locality,
'country' => $this->country
'locality' => $this->locality,
'country' => $this->country,
));
}

public function unserialize($serialized)
{
$data = unserialize($serialized);

$this->address = $data['address'] ?: null;
$this->address = $data['address'] ?: null;
$this->latitude = $data['latitude'] ?: null;
$this->longitude = $data['longitude'] ?: null;
$this->locality = $data['locality'] ?: null;
$this->country = $data['country'] ?: null;
}

public function offsetExists($offset)
{
return isset($this->$offset);
}

public function offsetSet($offset, $value)
{
$this->$offset = $value;
}

public function offsetGet($offset)
{
return $this->$offset;
}

public function offsetUnset($offset)
{
$this->$offset = null;
}
}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#How to update from orginal repo

git pull genemu master
git push origin

#FormBundle

[![Build Status](https://secure.travis-ci.org/genemu/GenemuFormBundle.png)](https://travis-ci.org/genemu/GenemuFormBundle)
Expand Down
8 changes: 4 additions & 4 deletions Resources/views/Form/jquery_layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -416,12 +416,12 @@
var $queue = $('#{{ id }}_queue');
var $nbQueue = 0;

var $configs = $.extend({{ configs|merge({
var $configs = $.extend({{ {
'swf': asset(configs.swf),
'cancelImg': asset(configs.cancelImg),
'uploader': path(configs.script),
'queueID': id ~ '_queue'
})|json_encode|raw }}, {
}|merge(configs)|json_encode|raw }}, {
onUploadSuccess: function(file, data, response) {
data = jQuery.parseJSON(data);

Expand Down Expand Up @@ -501,12 +501,12 @@
var $crop = null;
var $ratio = 1;

var $configs = $.extend({{ configs|merge({
var $configs = $.extend({{ {
'swf': asset(configs.swf),
'cancelImg': asset(configs.cancelImg),
'uploader': path(configs.script),
'queueID': id ~ '_queue'
})|json_encode|raw }}, {
}|merge(configs)|json_encode|raw }}, {
onUploadSuccess: function(file, data, response) {
data = jQuery.parseJSON(data);

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "genemu/form-bundle",
"name": "finchen/genemu-form-bundle",
"type": "symfony-bundle",
"description": "Extra form types for your Symfony2 projects",
"keywords": ["form", "extra form"],
Expand Down