Permalink
Browse files

Another maajor refacor befor generating own git

  • Loading branch information...
1 parent 4e5635e commit 3fe77b82f2f83d85faf9047cdf46ca3607a15506 @phiamo committed Oct 9, 2011
@@ -19,7 +19,20 @@ public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('mopa_bootstrap');
-
+ $rootNode
+ ->children()
+ ->arrayNode('form')
+ ->children()
+ ->booleanNode('show_legend')
+ ->defaultValue(true)
+ ->end()
+ ->booleanNode('show_child_legend')
+ ->defaultValue(false)
+ ->end()
+ ->end()
+ ->end()
+ ->end()
+ ->end();
return $treeBuilder;
}
}
@@ -25,5 +25,20 @@ public function load(array $configs, ContainerBuilder $container)
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load("services.yml");
+
+ if(isset($config['form'])){
+ if(isset($config['form']['show_legend'])){
+ $container->setParameter(
+ 'mopa_bootstrap.form.show_legend',
+ $config['form']['show_legend']
+ );
+ }
+ if(isset($config['form']['show_child_legend'])){
+ $container->setParameter(
+ 'mopa_bootstrap.form.show_child_legend',
+ $config['form']['show_child_legend']
+ );
+ }
+ }
}
}
@@ -9,19 +9,29 @@
class LegendFormTypeExtension extends AbstractTypeExtension
{
+ private $show_legend;
+ private $show_child_legend;
+
+ public function __construct(array $options){
+ $this->show_legend = $options['show_legend'];
+ $this->show_child_legend = $options['show_child_legend'];
+ }
public function buildForm(FormBuilder $builder, array $options)
{
$builder->setAttribute('show_legend', $options['show_legend']);
+ $builder->setAttribute('show_child_legend', $options['show_child_legend']);
}
public function buildView(FormView $view, FormInterface $form)
{
$view->set('show_legend', $form->getAttribute('show_legend'));
+ $view->set('show_child_legend', $form->getAttribute('show_child_legend'));
}
public function getDefaultOptions(array $options)
{
return array(
- 'show_legend' => false,
+ 'show_legend' => $this->show_legend,
+ 'show_child_legend' => $this->show_child_legend,
);
}
public function getExtendedType()
View
@@ -0,0 +1,20 @@
+Copyright (c) 2011 Mohrenweiser & Partner, Philipp A. Mohrenweiser
+ - http://www.mohrenweiserpartner.de
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
@@ -6,8 +6,4 @@
class MopaBootstrapBundle extends Bundle
{
- public function getParent()
- {
- return 'KnpPaginatorBundle';
- }
}
View
@@ -0,0 +1,171 @@
+# README
+
+
+## Introduction
+
+MopaBootstrapBundle is a small collection of useful code to integrate twitter's bootstrap
+(http://twitter.github.com/bootstrap/) as easy as possible into your symfony2 (http://www.symfony.com) Project.
+
+It includes various form template blocks for use with symfony2 Form Component
+as well as twig templates for KnpPaginatorBundle (https://github.com/knplabs/KnpPaginatorBundle)
+and CraueFormFlowBundle (https://github.com/craue/CraueFormFlowBundle)
+
+
+## Installation
+
+ 1.1 Add this bundle to your project as via deps:
+
+ [MopaBootstrapBundle]
+ git=http://github.com/schmittjoh/JMSPaymentCoreBundle.git
+ target=/bundles/Mopa/BootstrapBundle
+
+ 1.2 Or add this bundle to your project as a Git submodule:
+
+ $ git submodule add git@github.com:phiamo/MopaBootstrapBundle.git vendor/bundles/Mopa/BootstrapBundle
+
+ 2. Add this bundle to your application's kernel:
+
+ // application/ApplicationKernel.php
+ public function registerBundles()
+ {
+ return array(
+ // ...
+ new Mopa\BootstrapBundle\MopaBootstrapBundle(),
+ // ...
+ );
+ }
+
+ 3. Update your config.yml to activate forms integration (currently mandatory to make it work)
+
+ mopa_bootstrap:
+ form: ~
+
+
+## Initialize Bootstrap submodule
+
+If you do not have bootstrap in your project yet
+Just run
+
+ cd vendor/bundles/
+
+
+## Including Bootstrap in your Layout
+
+
+Have a look at the provided layout.html.twig its a fully working bootstrap layout and
+might explain howto use it by itself.
+
+
+## Use Bootstrap for Theming
+
+You can either activate it for you whole project:
+
+ twig:
+ form:
+ resources:
+ - 'MopaBootstrapBundle:Form:fields.html.twig'
+
+
+Or include the fields.html.twig in your template for a special form:
+
+ {% form_theme myform 'MopaBootstrapBundle:Form:field.html.twig' %}
+
+
+For FormFlow you can just use MopaBootstrap's templates instead of the ones given by the Bundles:
+
+ {% include 'CraueFormFlowBundle:FormFlow:stepField.html.twig' %}
+
+And to use the Paginator templates copy them to
+
+ app/Resources/Knp/Bundle/PaginatorBundle/views/Pagination/
+
+
+## Make use of FormExtensions
+
+This bundle extends the Form Componen via its native way to achieve having
+several more attributes on several form components
+
+
+### Form Legends
+
+Every Form component representing a Form not a Field (e.g. subforms, widgets of type date beeing expanded, etc)
+has now a attribute called show_legend which controls wether the "form legend" is shown or not.
+
+This can be controlled globally by adapting your config.yml:
+
+ mopa_bootstrap:
+ form:
+ show_legend: false # default is true
+
+Now you can tell a specific form to have the legend beeing shown by using:
+
+ public function buildForm(FormBuilder $builder, array $options)
+ {
+ $builder->setAttribute('show_legend', true);
+ // ...
+
+
+#### Child Form Legends
+
+
+In symfony2 you can easily glue different forms together and build a nice tree.
+Normally there is for every sub form (including special widgets like date expanded, radio button expanded, etc)
+a label with the name of the Subform rendered.
+This might make sense or not. I decided to disable this by default, but enabling it is easy:
+
+To enable it globally use:
+
+ mopa_bootstrap:
+ form:
+ show_legend: true # default is false
+
+If you just want to have it in a special form do it like that:
+
+ // e.g. a form only consiting of subforms
+ public function buildForm(FormBuilder $builder, array $options)
+ {
+ $builder->setAttribute('show_legend', No);
+ // ...
+ $child = $builder->create('user', $this->registerform, array('show_child_legend' => true));
+ $builder->add($child);
+
+
+### Form Field Help
+
+Every Form Field component representing a Field not a Form (e.g. inputs, textarea, radiobuttons beeing not expanded etc)
+has three new attributes:
+
+ - help_inline: beeing shown right of the element if there is space
+ - help_block: beeing shown under the element
+ - help_label: beeing shown under the label of the element
+
+Now you can easily add a help text at different locations:
+
+ $builder
+ ->add('title', null, array(
+ "help_inline"=>"Please specify some understandable title"))
+ ->add('shortDescription', 'textarea', array(
+ "attr" => array("rows"=>3, 'class'=>'xxlarge'),
+ "help_block"=>"This is the short descriptions shown somewhere"
+ ))
+ ->add('longDescription', null, array(
+ "attr"=>array("rows" => 10),
+ "help_label"=>"Please enter a very very long description"
+ ))
+ ;
+
+Hope you have fun with it.
+
+
+## TODO
+
+ - Probably make a command to deal with bootstrap library submodule for init and update
+ - Probably add more form components
+ - Add more useful bootstrap stuff
+
+
+## Known Issues
+
+ - Nothing what could not be done in another way, probably some will arise as soon as its published
+ So make issues!
+ - There are probably things missing, so make PR's
@@ -5,5 +5,7 @@ services:
- { name: form.type_extension, alias: field } # the alias is the same than getExtendedType in the class
mopa.form.legend_extension:
class: Mopa\BootstrapBundle\Form\Extension\LegendFormTypeExtension
+ arguments:
+ - { show_legend: %mopa_bootstrap.form.show_legend%, show_child_legend: %mopa_bootstrap.form.show_child_legend% }
tags:
- { name: form.type_extension, alias: form } # the alias is the same than getExtendedType in the class
@@ -1,4 +1,5 @@
{% extends 'form_div_layout.html.twig' %}
+{% from 'MopaBootstrapBundle::flash.html.twig' import flash %}
{# labels #}
@@ -35,10 +36,9 @@
{# Errors #}
{% block form_errors %}
-{% import 'MopaBootstrapBundle::bootstrap_flash.html.twig' as flash %}
{% spaceless %}
{% for error in errors %}
- {{ flash.show('error', error.messageTemplate|trans(error.messageParameters, 'validators')) }}
+ {{ flash('error', error.messageTemplate|trans(error.messageParameters, 'validators')) }}
{% endfor %}
{% endspaceless %}
{% endblock form_errors %}
@@ -77,7 +77,9 @@
<div class="clearfix {% if errors|length > 0 %}error{% endif %}">
{% endif %}
{% if 'form' in form.get('types') and form.hasParent() != 0 %}
- {# Wuerde bei sub forms aufgerufen werden #}
+ {% if show_child_legend %}
+ {{ block('form_legend') }}
+ {% endif %}
{% else %}
{{ form_label(form, label) }}
{% endif %}
@@ -1,3 +0,0 @@
-{% macro form_legend(form, label) %}
- {{ block('form_legend') }}
-{% endmacro %}
@@ -1,10 +0,0 @@
-{% macro show(type, message, close) %}
-<div class="alert-message {{ type }}" data-alert="alert">
- {% if close|default(false) %}
- <a class="close" href="#">×</a>
- {% endif %}
- <p>
- {{ message | trans }}
- </p>
-</div>
-{% endmacro %}
@@ -0,0 +1,29 @@
+{% macro flash(type, message, close) %}
+<div class="alert-message {{ type }}" data-alert="alert">
+ {% if close|default(false) %}
+ <a class="close" href="#">×</a>
+ {% endif %}
+ <p>
+ {{ message | trans }}
+ </p>
+</div>
+{% endmacro %}
+
+{% macro session_flash(type) %}
+{% set types = ['info', 'error', 'warning', 'success'] %}
+{% if app.session.getFlashes()|length > 0 %}
+<div class="row">
+ <div class="span16">
+ {% if type|default(false) %}
+ {% else %}
+ {% for type in types %}
+ {% if app.session.hasFlash(type) %}
+ {{ _self.flash(type, app.session.flash(type)) }}
+ {% endif %}
+ {% endfor %}
+ {% endif %}
+ </div>
+</div>
+{% endif %}
+{% endmacro %}
+
Oops, something went wrong.

0 comments on commit 3fe77b8

Please sign in to comment.