Currently you can define a single form type in the routing:
foo_thing:
resource: |
# ...
form: transaction_type
Or a form _class_ in the resource configuration, I think something like:
sylius_resource:
resources:
locastic.loyalty_rule:
classes:
model: RuleBundle\Entity\Rule
form:
create: RuleBundle\Form\RuleCreateType
update: RuleBundle\Form\RuleUpdateType
The resource configuration does not allow the specification of a service (it
just uses a factory to create the named class), and routing does not allow the
diferentiation between update and create.
So questions:
The configuration in routing generator is just for routing generation. If you need different forms for update and create, you will need to define the routes manually. I do not want to make the generation too powerful, it is mostly for simple use-cases and demo/testing purposes. With more advanced use-cases you will define routing manually most of the time.
The configuration in resources should also be as simple as possible, thus you have only one form. The "main" form.
In your case, I see 2 options:
app_admin_book_update:
...
defaults:
_sylius:
form:
type: app_book
options:
include_title: false # Based on this option, add (or not) the title field.
If we continue adding more options to the generator it can end up really ugly and overpowered. WDYT?
ok that makes sense.
But on the other hand, we do seem to allow the specification of form classes (default, update, create) in the resource configuration (as opposed to routing configuration) - and it is not possible to use a service.
Is there duplication of responsiblity here? Would it make sense to not use a factory[1] to create the form types (see also #5243) and remove the routing option f.e.?
[1] Referring to a resource factory - we could use the Symfony form factory.
I am now in situation where I want to use a customized controller for a resource, and I feel uncomfortable in setting the class - as it seems like an anti-pattern (about 12 services are injected and then the container is also injected).
Could we consider replaceing the classes option with something like the following which allows services to be specified?
sylius_resource:
resources:
acme.post_folder:
driver: doctrine/phpcr-odm
controller: my.controller # class or service
form: my.form.service # class or service
factory: my.factory.servce # class or service
class: Namespace\MyModel # class
interface: MyInterface # interface
Any opinions?
:+1: for allowing to specify services and then aliasing them as sylius.RESOURCE.SERVICE
It would resolve a lot of problems problems and increase a DX. 馃憤
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in a week if no further activity occurs. Thank you for your contributions.
Most helpful comment
I am now in situation where I want to use a customized controller for a resource, and I feel uncomfortable in setting the class - as it seems like an anti-pattern (about 12 services are injected and then the container is also injected).
Could we consider replaceing the
classesoption with something like the following which allows services to be specified?