Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Feedback required] Fixed asset version strategy #15108

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

Closed
wants to merge 2 commits into from
Closed

[Feedback required] Fixed asset version strategy #15108

wants to merge 2 commits into from

Conversation

XWB
Copy link
Contributor

@XWB XWB commented Jun 26, 2015

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? no
Fixed tickets #14832
License MIT
Doc PR -

EmptyVersionStrategy is completely ignored since Symfony 2.7 due to a string cast.

@XWB
Copy link
Contributor Author

XWB commented Jun 26, 2015

Not sure why the tests are failing.

@XWB XWB changed the title Fixed asset version strategy [2.7] Fixed asset version strategy Jun 26, 2015
@fabpot
Copy link
Member

fabpot commented Jun 28, 2015

Can you add some tests to avoid regressions?

@XWB
Copy link
Contributor Author

XWB commented Jun 30, 2015

This seems impossible to fix.

framework:
    assets:
        assets_version: %app_version%
        assets_version_format: "%%s?v=%%s"
        packages:
            foo:
                version: ~
                version_format: ~
            bar:
                base_urls: []

Both packages will have version value null in which case the default version will be used:

https://github.com/symfony/symfony/blob/2.7/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L587:L588

@XWB XWB changed the title [2.7] Fixed asset version strategy [Feedback required] Fixed asset version strategy Jun 30, 2015
@xabbuh xabbuh added the Asset label Jul 4, 2015
@xabbuh
Copy link
Member

xabbuh commented Jul 4, 2015

It's a bit more difficult to fix as the behaviour changed slightly with the new Asset component. I'll take a look into this.

@XWB
Copy link
Contributor Author

XWB commented Jul 6, 2015

@xabbuh That would be nice!

@fabpot
Copy link
Member

fabpot commented Aug 1, 2015

Any news on this one?

@xabbuh
Copy link
Member

xabbuh commented Aug 1, 2015

Didn't find the time to fix it. I hope to manage it some time the next days.

@XWB
Copy link
Contributor Author

XWB commented Sep 2, 2015

Any updates? @xabbuh

$version = $this->createVersion($container, $package['version'], $format, $name);
}
$format = $package['version_format'] ?: $config['version_format'];
$version = $this->createVersion($container, $package['version'], $format, $name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are changing the behavior of null here

@fabpot
Copy link
Member

fabpot commented Oct 6, 2015

Closing this PR as it cannot be merged as is and we have an issue that references the issue, so it's not lost.

@fabpot fabpot closed this Oct 6, 2015
derrabus added a commit that referenced this pull request Mar 18, 2021
…ino)

This PR was squashed before being merged into the 5.3-dev branch.

Discussion
----------

[Form] Add "form_attr" FormType option

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      |no
| New feature?  | yes
| Deprecations? | no
| Tickets       | N/A
| License       | MIT
| Doc PR        | [#15108](symfony/symfony-docs#15108)

## What is this about

This PR add support for [`form` attribute](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fae-form) to Symfony Form ([browser compatibility](https://caniuse.com/form-attribute)).

The `form` attribute allows form elements to override their associated form (which is their nearest ancestor form element by default). This is extremely useful to solve **nested form problem** and allows **form children** to be **rendered outside form tag** while still working as expected.

## New "form_attr" FormType option

#### form_attr
**type**: `bool` or `string` **default**: `false`

If set to `true` on a **root form**, adds [`form` attribute](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fae-form) on every children with their root **form id**.
This allows you to render form children outside the form tag and avoid **nested form problem** in some situations while keeping the form working properly.

If set to `true` on a **child**, adds [`form` attribute](https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fae-form) on it with its **root form id**.
This allows you to render **that child** outside the form tag and avoid **nested form problem** in some situations while keeping the form working properly.

If root form has no `id` (this may happen by create an *unnamed* form), you can set it to a `string` identifier to be used at `FormView` level to link children and root form anyway.

## Usage on Root Form Example

#### Form Type
Enable the feature by setting `form_attr` to `true` on the root form.

```php
use Symfony\Component\Form\Extension\Core\Type;

class ListFilterType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('search', Type\SearchType::class)
            ->add('orderBy', Type\ChoiceType::class, [
                'choices' => [
                    // ...
                ],
            ])
            ->add('perPage', Type\ChoiceType::class, [
                'choices' => [
                    // ...
                ],
            ])
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefault('form_attr', true); // <--- Set this to true
    }
}

```

#### Twig

The following Twig template **works properly** even if form children are **outside** their form tag ([browser compatibility](https://caniuse.com/form-attribute)).

```twig

<div class="header-filters">
    {{ form_errors(form) }}
    {{ form_row(form.search) }} {# has attribute form="list_filter" #}
    {{ form_row(form.orderBy) }} {# has attribute form="list_filter" #}
</div>

<!-- -->
<!-- Some other HTML content, like a table or even another Symfony form -->
<!-- -->

<div class="footer-filters">
    {{ form_row(form.perPage) }} {# has attribute form="list_filter" #}
</div>
{{ form_start(form) }} {# id="list_filter" #}
{{ form_end(form) }}
```
✅ Every form elements work properly even outside form tag.

## Usage on Form Child Example

Enable the feature by setting `form_attr` to `true` on selected child.

```php
use Symfony\Component\Form\Extension\Core\Type;

class ListFilterType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('search', Type\SearchType::class)
            ->add('orderBy', Type\ChoiceType::class, [
                'choices' => [
                    // ...
                ],
            ])
            ->add('perPage', Type\ChoiceType::class, [
                'form_attr' => true,  // <--- Set this to true
                'choices' => [
                    // ...
                ],
            ])
    }
}

```

#### Twig

The following Twig template **works properly** even if `form.perPage` is **outside** form tag ([browser compatibility](https://caniuse.com/form-attribute)).

```twig

<div class="header-filters">
    {{ form_start(form) }} {# id="list_filter" #}
        {{ form_errors(form) }}
        {{ form_row(form.search) }}
        {{ form_row(form.orderBy) }}
    {{ form_end(form, {'render_rest': false}) }}
</div>

<!-- -->
<!-- Some other HTML content, like a table or even another Symfony form -->
<!-- -->

<div class="footer-filters">
    {{ form_row(form.perPage) }} {# has attribute form="list_filter" #}
</div>
```
✅ `form.perPage` element work properly even outside form tag.

Commits
-------

5f913ce [Form] Add "form_attr" FormType option
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants