-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1755 from open-orchestra/1-2_multilanguagetype
Add MultiLanguagesTextType
- Loading branch information
Showing
6 changed files
with
192 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace OpenOrchestra\Backoffice\Form\Type\Component; | ||
|
||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
/** | ||
* Class MultiLanguagesTextType | ||
*/ | ||
class MultiLanguagesTextType extends AbstractType | ||
{ | ||
/** | ||
* @param OptionsResolver $resolver | ||
*/ | ||
public function configureOptions(OptionsResolver $resolver) | ||
{ | ||
$resolver->setDefaults(array( | ||
'label_attr' => array('class' => 'translated-value'), | ||
'languages' => array('en'), | ||
'type' => 'text' | ||
)); | ||
} | ||
|
||
/** | ||
* @param FormBuilderInterface $builder | ||
* @param array $options | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
foreach ($this->getModelTransformers() as $transformer) { | ||
$builder->addModelTransformer($transformer); | ||
} | ||
|
||
foreach ($this->getViewTransformers() as $transformer) { | ||
$builder->addViewTransformer($transformer); | ||
} | ||
|
||
foreach ($options['languages'] as $language) { | ||
$builder->add($language, $options['type'], array('label' => $language)); | ||
} | ||
} | ||
|
||
/** | ||
* Return array<Symfony\Component\Form\DataTransformerInterface> | ||
*/ | ||
protected function getModelTransformers() | ||
{ | ||
return array(); | ||
} | ||
|
||
/** | ||
* Return array<Symfony\Component\Form\DataTransformerInterface> | ||
*/ | ||
protected function getViewTransformers() | ||
{ | ||
return array(); | ||
} | ||
|
||
/** | ||
* Returns the name of this type. | ||
* | ||
* @return string The name of this type | ||
*/ | ||
public function getName() | ||
{ | ||
return 'oo_multi_languages_text'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace OpenOrchestra\Backoffice\Tests\Form\Type; | ||
|
||
use OpenOrchestra\BaseBundle\Tests\AbstractTest\AbstractBaseTestCase; | ||
use Phake; | ||
use OpenOrchestra\Backoffice\Form\Type\Component\MultiLanguagesTextType; | ||
|
||
/** | ||
* Class MultiLanguagesTextTypeTest | ||
*/ | ||
class MultiLanguagesTextTypeTest extends AbstractBaseTestCase | ||
{ | ||
/** | ||
* @var MultiLanguagesTextType | ||
*/ | ||
protected $form; | ||
|
||
/** | ||
* Set up the test | ||
*/ | ||
public function setUp() | ||
{ | ||
$this->form = new MultiLanguagesTextType(); | ||
} | ||
|
||
/** | ||
* Test instance | ||
*/ | ||
public function testInstance() | ||
{ | ||
$this->assertInstanceOf('Symfony\Component\Form\AbstractType', $this->form); | ||
} | ||
|
||
/** | ||
* Test name | ||
*/ | ||
public function testName() | ||
{ | ||
$this->assertSame('oo_multi_languages_text', $this->form->getName()); | ||
} | ||
|
||
/** | ||
* Test builder | ||
* | ||
* @dataProvider provideLanguages | ||
*/ | ||
public function testBuilder($languages, $expectedBuildCount) | ||
{ | ||
$builder = Phake::mock('Symfony\Component\Form\FormBuilder'); | ||
Phake::when($builder)->add(Phake::anyParameters())->thenReturn($builder); | ||
Phake::when($builder)->addEventSubscriber(Phake::anyParameters())->thenReturn($builder); | ||
|
||
$this->form->buildForm($builder, array('type' => 'text', 'languages' => $languages)); | ||
|
||
Phake::verify($builder, Phake::times($expectedBuildCount))->add(Phake::anyParameters()); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function provideLanguages() | ||
{ | ||
return array( | ||
array(array(), 0), | ||
array(array('fr', 'ch'), 2), | ||
array(array('fr', 'de', 'en'), 3), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters