-
-
Notifications
You must be signed in to change notification settings - Fork 387
[StimulusBundle] Attribute Builder #2450
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
base: 2.x
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,162 @@ | ||||||||||||||||||
<?php | ||||||||||||||||||
|
||||||||||||||||||
/* | ||||||||||||||||||
* This file is part of the Symfony package. | ||||||||||||||||||
* | ||||||||||||||||||
* (c) Fabien Potencier <[email protected]> | ||||||||||||||||||
* | ||||||||||||||||||
* For the full copyright and license information, please view the LICENSE | ||||||||||||||||||
* file that was distributed with this source code. | ||||||||||||||||||
*/ | ||||||||||||||||||
|
||||||||||||||||||
namespace App\Form\Extension; | ||||||||||||||||||
|
||||||||||||||||||
use Symfony\Component\Form\AbstractTypeExtension; | ||||||||||||||||||
use Symfony\Component\Form\Extension\Core\Type\FormType; | ||||||||||||||||||
use Symfony\Component\Form\FormInterface; | ||||||||||||||||||
use Symfony\Component\Form\FormView; | ||||||||||||||||||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||||||||||||||||||
use Symfony\UX\StimulusBundle\Dto\StimulusAttributes; | ||||||||||||||||||
use Twig\Environment; | ||||||||||||||||||
use Twig\Loader\ArrayLoader; | ||||||||||||||||||
|
||||||||||||||||||
class FormTypeExtension extends AbstractTypeExtension | ||||||||||||||||||
{ | ||||||||||||||||||
private StimulusAttributes $stimulusAttributes; | ||||||||||||||||||
|
||||||||||||||||||
public static function getExtendedTypes(): iterable | ||||||||||||||||||
{ | ||||||||||||||||||
return [FormType::class]; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
public function buildView(FormView $view, FormInterface $form, array $options): void | ||||||||||||||||||
{ | ||||||||||||||||||
if ( | ||||||||||||||||||
|
||||||||||||||||||
isset($options['stimulus_controller']) | ||||||||||||||||||
|| !isset($options['stimulus_target']) | ||||||||||||||||||
|| !isset($options['stimulus_action']) | ||||||||||||||||||
) { | ||||||||||||||||||
|
if ( | |
isset($options['stimulus_controller']) | |
|| !isset($options['stimulus_target']) | |
|| !isset($options['stimulus_action']) | |
) { | |
if ($options['stimulus_controller'] || $options['stimulus_target'] || $options['stimulus_action']) { |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (isset($options['stimulus_controller'])) { | |
$this->handleController($options['stimulus_controller']); | |
} | |
if ($options['stimulus_controller']) { | |
$this->handleController($options['stimulus_controller']); | |
} | |
// same for the other ones |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$attributes = array_merge($view->vars['attr'], $this->stimulusAttributes->toArray()); | |
$view->vars['attr'] = $attributes; | |
$view->vars['attr'] = [...$view->vars['attr'], ...$this->stimulusAttributes->toArray()]; |
Avoid unnecessary var
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be handle outside this method i suppose (will call $this->stimulusAttributes->addController(...) every case)
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be removed / inline when it is called
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason i want another object, we should not have to duplicate this in multiple place. Will open a draft later if i can
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(i cannot 😅 🕐 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is temporary right ?
I think we won't need it and use a new object but if we don't, you can inject the StimulusHelper here