Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form actions patch #286

Merged
merged 2 commits into from
Aug 21, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions Form/Extension/ButtonTypeExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Braincrafted\Bundle\BootstrapBundle\Form\Extension;

use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\FormInterface;

/**
* FormControlStaticType
*
* @package BraincraftedBootstrapBundle
* @subpackage Form
* @author André Püschel <[email protected]>
* @copyright 2014 André Püschel
* @license http://opensource.org/licenses/MIT The MIT License
* @link http://bootstrap.braincrafted.com Bootstrap for Symfony2
*/
class ButtonTypeExtension extends AbstractTypeExtension
{
/**
* {@inheritDoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['button_class'] = $form->getConfig()->getOption('button_class');
$view->vars['as_link'] = $form->getConfig()->getOption('as_link');
}

/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setOptional(array('button_class', 'as_link'));
}

/**
* {@inheritdoc}
*/
public function getExtendedType()
{
return 'button';
}
}
5 changes: 5 additions & 0 deletions Resources/config/services/form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<parameter key="braincrafted_bootstrap.form.type.money.class">Braincrafted\Bundle\BootstrapBundle\Form\Type\MoneyType</parameter>
<parameter key="braincrafted_bootstrap.form.type.form_actions.class">Braincrafted\Bundle\BootstrapBundle\Form\Type\FormActionsType</parameter>
<parameter key="braincrafted_bootstrap.form.extension.typesetter_extension.class">Braincrafted\Bundle\BootstrapBundle\Form\Extension\TypeSetterExtension</parameter>
<parameter key="braincrafted_bootstrap.form.extension.button_extension.class">Braincrafted\Bundle\BootstrapBundle\Form\Extension\ButtonTypeExtension</parameter>
<parameter key="braincrafted_bootstrap.form.extension.input_group_button.class">Braincrafted\Bundle\BootstrapBundle\Form\Extension\InputGroupButtonExtension</parameter>
</parameters>

Expand All @@ -29,6 +30,10 @@
<tag name="form.type_extension" alias="form" />
</service>

<service id="braincrafted_bootstrap.form.extension.form_action_button" class="%braincrafted_bootstrap.form.extension.button_extension.class%">
<tag name="form.type_extension" alias="button" />
</service>

<service id="braincrafted_bootstrap.form.extension.input_group_button" class="%braincrafted_bootstrap.form.extension.input_group_button.class%">
<tag name="form.type_extension" alias="text" />
</service>
Expand Down
16 changes: 9 additions & 7 deletions Resources/views/Form/bootstrap.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -502,11 +502,15 @@
{% set label = name|humanize %}
{% endif %}
{% if type is defined and type == 'submit' %}
{% set attr = attr|merge({ 'class': (attr.class|default('') ~ ' btn btn-'~attr.type|default('primary'))|trim }) %}
{% set attr = attr|merge({ 'class': (attr.class|default('') ~ ' btn btn-'~button_class|default('primary'))|trim }) %}
{% else %}
{% set attr = attr|merge({ 'class': (attr.class|default('') ~ ' btn btn-'~attr.type|default('default'))|trim }) %}
{% set attr = attr|merge({ 'class': (attr.class|default('') ~ ' btn btn-'~button_class|default('default'))|trim }) %}
{% endif %}
{% if as_link is defined and as_link == true %}
<a {{ block('button_attributes') }}>{% if attr.icon is defined and attr.icon != '' %}{{ icon(attr.icon) }}{% endif %}{{ label|trans({}, translation_domain) }}</a>
{% else %}
<button type="{{ type|default('button') }}" {{ block('button_attributes') }}>{% if attr.icon is defined and attr.icon != '' %}{{ icon(attr.icon) }}{% endif %}{{ label|trans({}, translation_domain) }}</button>
{% endif %}
<button type="{{ type|default('button') }}" {{ block('button_attributes') }}>{% if attr.icon is defined and attr.icon != '' %}{{ icon(attr.icon) }}{% endif %}{{ label|trans({}, translation_domain) }}</button>
{% endspaceless %}
{% endblock button_widget %}

Expand Down Expand Up @@ -894,9 +898,7 @@
{% endspaceless %}
{% endblock widget_container_attributes %}

{% block button_attributes %}
{% spaceless %}
{% block button_attributes -%}
id="{{ id }}" name="{{ full_name }}"{% if disabled %} disabled="disabled"{% endif %}
{% for attrname, attrvalue in attr %}{{ attrname }}="{{ attrvalue }}" {% endfor %}
{% endspaceless %}
{%- for attrname, attrvalue in attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}
{% endblock button_attributes %}