From 1747ba5f0dbaf33002be534e696a7b35e217b80a Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Sat, 8 Nov 2014 15:19:30 +0100 Subject: [PATCH] Adding Title for Custom Field --- CustomFields/CustomFieldTitle.php | 70 +++++++++++++++++++ Form/Type/CustomFieldsTitleType.php | 38 ++++++++++ Resources/config/services.yml | 26 +++++-- .../views/Form/form_div_layout.html.twig | 3 + 4 files changed, 130 insertions(+), 7 deletions(-) create mode 100644 CustomFields/CustomFieldTitle.php create mode 100644 Form/Type/CustomFieldsTitleType.php create mode 100644 Resources/views/Form/form_div_layout.html.twig diff --git a/CustomFields/CustomFieldTitle.php b/CustomFields/CustomFieldTitle.php new file mode 100644 index 000000000..df3327134 --- /dev/null +++ b/CustomFields/CustomFieldTitle.php @@ -0,0 +1,70 @@ + + * + * 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 . + */ + +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; + } +} diff --git a/Form/Type/CustomFieldsTitleType.php b/Form/Type/CustomFieldsTitleType.php new file mode 100644 index 000000000..be490a5f3 --- /dev/null +++ b/Form/Type/CustomFieldsTitleType.php @@ -0,0 +1,38 @@ + + * + * 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 . + */ +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'; + } + +} \ No newline at end of file diff --git a/Resources/config/services.yml b/Resources/config/services.yml index b077c3130..29892ae3a 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -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' } diff --git a/Resources/views/Form/form_div_layout.html.twig b/Resources/views/Form/form_div_layout.html.twig new file mode 100644 index 000000000..118397393 --- /dev/null +++ b/Resources/views/Form/form_div_layout.html.twig @@ -0,0 +1,3 @@ +{% block custom_field_title_widget %} +dump(attr) +{% endblock custom_field_title_widget %} \ No newline at end of file