Adding Title for Custom Field

This commit is contained in:
Marc Ducobu 2014-11-08 15:19:30 +01:00
parent a6ae6ca5a9
commit 1747ba5f0d
4 changed files with 130 additions and 7 deletions

View File

@ -0,0 +1,70 @@
<?php
/*
* Chill is a software for social workers
*
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\CustomFieldsBundle\CustomFields;
use Chill\CustomFieldsBundle\CustomFields\CustomFieldInterface;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\RequestStack;
class CustomFieldTitle implements CustomFieldInterface
{
private $requestStack;
public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}
public function buildForm(FormBuilderInterface $builder, CustomField $customField)
{
$builder->add($customField->getSlug(), 'custom_field_title', array(
'label' => $customField->getLabel(
$this->requestStack->getCurrentRequest()->getLocale())
));
}
public function render($value, CustomField $customField)
{
return $value;
}
public function serialize($value, CustomField $customField)
{
return $value;
}
public function deserialize($serialized, CustomField $customField)
{
return $serialized;
}
public function getName()
{
return 'title';
}
public function buildOptionsForm(FormBuilderInterface $builder)
{
return $builder;
}
}

View File

@ -0,0 +1,38 @@
<?php
/*
* Chill is a software for social workers
*
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\CustomFieldsBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class CustomFieldsTitleType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
}
public function getName()
{
return 'custom_field_title';
}
}

View File

@ -6,20 +6,20 @@ services:
class: Chill\CustomFieldsBundle\Routing\RoutesLoader
tags:
- { name: routing.loader }
chill.custom_field.provider:
class: Chill\CustomFieldsBundle\Service\CustomFieldProvider
call:
- [setContainer, ["@service_container"]]
chill.custom_field.custom_field_choice_type:
class: Chill\CustomFieldsBundle\Form\CustomFieldType
arguments:
- "@chill.custom_field.provider"
tags:
- { name: 'form.type', alias: 'custom_field_choice' }
chill.custom_field.custom_fields_group_type:
class: Chill\CustomFieldsBundle\Form\CustomFieldsGroupType
arguments:
@ -27,7 +27,7 @@ services:
- "@translator"
tags:
- { name: 'form.type', alias: 'custom_fields_group' }
chill.custom_field.custom_field_type:
class: Chill\CustomFieldsBundle\Form\Type\CustomFieldType
arguments:
@ -35,15 +35,27 @@ services:
- "@chill.custom_field.provider"
tags:
- { name: 'form.type', alias: 'custom_field' }
chill.custom_field.text:
class: Chill\CustomFieldsBundle\CustomFields\CustomFieldText
tags:
- { name: 'chill.custom_field', type: 'text' }
chill.custom_field.address:
class: Chill\CustomFieldsBundle\CustomFields\CustomFieldAddress
arguments:
- "@doctrine.orm.entity_manager"
tags:
- { name: 'chill.custom_field', type: 'address' }
chill.custom_field.custom_fields_title_type:
class: Chill\CustomFieldsBundle\Form\Type\CustomFieldsTitleType
tags:
- { name: 'form.type', alias: 'custom_field_title' }
chill.custom_field.title:
class: Chill\CustomFieldsBundle\CustomFields\CustomFieldTitle
arguments:
- "@request_stack"
tags:
- { name: 'chill.custom_field', type: 'title' }

View File

@ -0,0 +1,3 @@
{% block custom_field_title_widget %}
dump(attr)
{% endblock custom_field_title_widget %}