-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[ResourceBundle] Automatic form registration #1927
[ResourceBundle] Automatic form registration #1927
Conversation
9583b83
to
2108b07
Compare
@@ -134,8 +176,7 @@ protected function getClassMetadataDefinition($models) | |||
->setFactoryService($this->getManagerServiceKey()) | |||
->setFactoryMethod('getClassMetadata') | |||
->setArguments(array($models)) | |||
->setPublic(false) |
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 should be reverted
@Sylius/core-team What do you think about it ? |
e533980
to
97fa87e
Compare
cab7792
to
b49990c
Compare
Reworked and added specs. |
|
||
$container | ||
->getDefinition('sylius.form.type.province_choice') | ||
->setArguments([ |
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.
We supports PHP 5.3 :)
@pjedrzejewski The functionality is very interesting, I would want it into the resource bundle!! @Strontium-90 Why do you merge #2012 into this PR? Can you revert it and squash your commit I will review it again. |
5df2b79
to
c9f3a60
Compare
public function __construct($className, $driver, $name) | ||
{ | ||
$this->className = $className; | ||
$this->parent = $driver; |
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 useless as you assign this variable in switch
later...
6ab7b58
to
c14bb9d
Compare
45b1df4
to
48ed8e2
Compare
@pjedrzejewski, @Arn0d, I reworked to this config, rebased... Any review and lets finish here? |
$suffix = ($name === self::DEFAULT_KEY ? '' : sprintf('_%s', $name)); | ||
$alias = sprintf('%s_%s%s', $this->applicationName, $model, $suffix); | ||
$definition = new Definition($class); | ||
if ($name == 'choice') { |
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.
'choice' === $name.
Awesome work Aleksey! Please tweak these few things I have mentioned + rebase and I will merge it. :) Thank you! 👍 |
I had a quick look, it seems good! |
9c9aaf6
to
18971da
Compare
done |
Seems like there are still conflicts. :) |
97b2021
to
7e8af31
Compare
Rebased again. |
Could you have a look why scenarios are failing? Master is green. |
e6b4247
to
a03be9b
Compare
Good news. Almost green, but some suites exited with 137... |
[ResourceBundle] Automatic form registration
Thank you so much Aleksey! This is a really cool thing, I will remove other forms. :) 👍 |
I think this will more easy, if we finish this PR #1921. |
This change is nice, I like it. However there's something slightly counter-intuitive in having to manipulate the service definitions just to pass in dependencies: $container
->getDefinition('my.form.type.blog')
->setArguments(array(
new Reference('my.repository.blog')
))
; Perhaps in another PR, this can be exposed to the config? |
I agree with @adamelso, I think it would be easier to have a check to see if the form's definition already exists and if so, it doesn't create it. That way any form that isn't standard you can create in your service definitions and any simple ones will just get created by themselves. It seems silly to mess with the definitions programmatically only. Kind of adds a big learning curve for newer users and is harder to read and trace out errors. Should be simple to change it to this: protected function registerFormTypes(array $config, ContainerBuilder $container)
{
foreach ($config['classes'] as $model => $serviceClasses) {
if (!isset($serviceClasses['form']) || !is_array($serviceClasses['form'])) {
continue;
}
foreach ($serviceClasses['form'] as $name => $class) {
$suffix = ($name === self::DEFAULT_KEY ? '' : sprintf('_%s', $name));
$alias = sprintf('%s_%s%s', $this->applicationName, $model, $suffix);
$definitionId = sprintf('%s.form.type.%s%s', $this->applicationName, $model, $suffix);
// HERE
if ($container->hasDefinition($definitionId)) {
continue;
}
$definition = new Definition($class);
if ('choice' === $name) {
$definition->setArguments(array(
$serviceClasses['model'],
$config['driver'],
$alias
));
} else {
$definition->setArguments(array(
$serviceClasses['model'],
new Parameter(sprintf('%s.validation_group.%s%s', $this->applicationName, $model, $suffix))
));
}
$definition->addTag('form.type',array('alias' => $alias));
$container->setDefinition(
$definitionId,
$definition
);
}
}
} |
@isometriks I've use some your code snippet in my PR #2483 . |
…tration [ResourceBundle] Automatic form registration
…tration [ResourceBundle] Automatic form registration
…tration [ResourceBundle] Automatic form registration
Register resource form types as services.
Its possible register many form for resourse, i.e: