improved form handling

improved profile editing
added activity editing
This commit is contained in:
Kevin Papst
2016-11-12 23:22:47 +01:00
parent 8401797728
commit cc269d3142
17 changed files with 425 additions and 34 deletions

View File

@@ -0,0 +1,46 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace AppBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Intl\Intl;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Custom form field type to select the language.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class LanguageType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'choices' => array(
Intl::getLocaleBundle()->getLocaleName('de', 'de') => 'de'
)
]);
}
/**
* {@inheritdoc}
*/
public function getParent()
{
return ChoiceType::class;
}
}

View File

@@ -0,0 +1,43 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace AppBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Custom form field type to select between Yes and No.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class YesNoType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'choices' => ['yes' => true, 'no' => false],
]);
}
/**
* {@inheritdoc}
*/
public function getParent()
{
return ChoiceType::class;
}
}

View File

@@ -12,8 +12,9 @@
namespace AppBundle\Form;
use AppBundle\Entity\User;
use AppBundle\Form\Type\LanguageType;
use AppBundle\Form\Type\YesNoType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\LanguageType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -47,8 +48,13 @@ class UserEditType extends AbstractType
// string - length 5
->add('language', LanguageType::class, [
'label' => 'label.language',
'choices' => array('Deutsch' => 'de') // FIXME translation
])
// boolean
->add('active', YesNoType::class, [
'label' => 'label.active',
])
// TODO avatar
// TODO roles - see ProfileController::getRoles()
;
}