Skip to content

Commit

Permalink
bug #921 Allow checkboxes to define a custom label in forms (javiereg…
Browse files Browse the repository at this point in the history
…uiluz)

This PR was merged into the master branch.

Discussion
----------

Allow checkboxes to define a custom label in forms

The solution was provided by @ rubengc in https://github.com/javiereguiluz/EasyAdminBundle/issues/868#issuecomment-188319211

Commits
-------

82054b6 Allow checkbox to define a custom label in forms
  • Loading branch information
javiereguiluz committed Feb 25, 2016
2 parents d862a6a + 82054b6 commit 8478e31
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Form/Type/Configurator/CheckboxTypeConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public function configure($name, array $options, array $metadata, FormConfigInte
$options['required'] = false;
}

$options['label'] = $metadata['label'];

return $options;
}

Expand Down
24 changes: 19 additions & 5 deletions Tests/Controller/CustomizedBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,13 @@ public function testEditViewListActionReferer()
$this->assertEquals($parameters, $refererParameters);
}

public function testEditViewCheckboxLabel()
{
$crawler = $this->requestEditView('Product', '1');

$this->assertContains('Custom Label', trim($crawler->filter('#product_enabled')->parents()->filter('label')->text()));
}

public function testNewViewPageTitle()
{
$crawler = $this->requestNewView();
Expand Down Expand Up @@ -428,6 +435,13 @@ public function testNewCustomFormOptions()
}
}

public function testNewViewCheckboxLabel()
{
$crawler = $this->requestNewView('Product');

$this->assertContains('Custom Label', trim($crawler->filter('#product_enabled')->parents()->filter('label')->text()));
}

public function testSearchViewPageTitle()
{
$crawler = $this->requestSearchView();
Expand Down Expand Up @@ -582,23 +596,23 @@ private function requestShowView()
/**
* @return Crawler
*/
private function requestEditView()
private function requestEditView($entityName = 'Category', $entityId = '200')
{
return $this->getBackendPage(array(
'action' => 'edit',
'entity' => 'Category',
'id' => '200',
'entity' => $entityName,
'id' => $entityId,
));
}

/**
* @return Crawler
*/
private function requestNewView()
private function requestNewView($entityName = 'Category')
{
return $this->getBackendPage(array(
'action' => 'new',
'entity' => 'Category',
'entity' => $entityName,
));
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/Fixtures/App/config/config_customized_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,5 @@ easy_admin:
- 'name'
- { property: price, type: 'number', help: 'Prices are always in euros' }
- { property: 'ean', label: 'EAN', help: 'EAN 13 valid code. Leave empty if unknown.' }
- 'enabled'
- { property: 'enabled', label: 'Custom Label' }
- 'description'

0 comments on commit 8478e31

Please sign in to comment.