fix creation of custom field without cfgroup id

This commit is contained in:
Julien Fastré 2015-11-30 21:31:58 +01:00
parent 2401270754
commit c9ca7c1e1b
4 changed files with 19 additions and 7 deletions

2
.gitignore vendored
View File

@ -28,3 +28,5 @@ src/Chill/CustomFieldsBundle/vendor/*
bootstrap.php.cache
#the file created by composer to store creds
auth.json
Tests/Fixtures/App/app/config/parameters.yml

View File

@ -76,14 +76,17 @@ class CustomFieldController extends Controller
//add the custom field group if defined in URL
$cfGroupId = $request->query->get('customFieldsGroup', null);
$cfGroup = $this->getDoctrine()->getManager()
->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')
->find($cfGroupId);
if (!$cfGroup) {
throw $this->createNotFoundException('CustomFieldsGroup with id '
. $cfGroupId.' is not found !');
if ($cfGroupId !== null) {
$cfGroup = $this->getDoctrine()->getManager()
->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')
->find($cfGroupId);
if (!$cfGroup) {
throw $this->createNotFoundException('CustomFieldsGroup with id '
. $cfGroupId.' is not found !');
}
$entity->setCustomFieldsGroup($cfGroup);
}
$entity->setCustomFieldsGroup($cfGroup);
$form = $this->createCreateForm($entity, $request->query->get('type'));

View File

@ -41,9 +41,15 @@
<ul class="record_actions">
<li>
{% if entity.customFieldsGroup is not null %}
<a href="{{ path('customfieldsgroup_show', { 'id': entity.customFieldsGroup.id }) }}" class="sc-button btn-reset">
{{ 'Back to the group'|trans }}
</a>
{% else %}
<a href="{{ path('customfieldsgroup') }}" class="sc-button btn-reset">
{{ 'Back to the list'|trans }}
</a>
{% endif %}
</li>
</ul>
{% endblock %}

View File

@ -100,4 +100,5 @@ class CustomFieldsTextTest extends WebTestCase
$form = $crawler->selectButton('custom_field_choice_submit')->form();
$this->assertTrue($form->has('custom_field_choice[options][maxLength]'));
}
}