Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3925

Symfony 4 - EasyAdmin Bundle - default form value

$
0
0

Hello everyone !

I'm using easyadmin for a project and i'm a bit confuse. I have a User entity with roles "ROLE_CUSTOMER" and "ROLE_REPAIRMAN". I can display and add users depend on their roles :

entities.yaml :

easy_admin:
  entities:
    Customer:
      label: 'Customer'
      class: App\Entity\User
      list:
        dql_filter: "entity.roles LIKE '%%ROLE_CUSTOMER%%'"
      form:
        title: "Add Customer"
        fields: &userFormFields
          - { property: 'email' }
          - { property: 'civility' }
          - { property: 'lastname' }
          - { property: 'firstname' }
          - { property: 'phone' }
          - { property: 'mobile' }
    Repairman:
      label: 'Repairman'
      class: App\Entity\User
      controller: App\Controller\Admin\RepairmanController
      list:
        dql_filter: "entity.roles LIKE '%%ROLE_REPAIRMAN%%'"
        fields:
          - id
          - company
          - email
          - civility
          - firstname
          - lastname
          - { property: 'isAdminGroup' }
      form:
        title: "Add Repairman"
        fields:
          - { property: 'email' }
          - { property: 'civility' }
          - { property: 'lastname' }
          - { property: 'firstname' }
          - { property: 'phone' }
          - { property: 'mobile' }
          - { property: 'company' }
          - { property: 'vitrage' }
          - { property: 'kbis' }
          - { property: 'siret' }
          - { property: 'isAdminGroup' }

menu.yaml

easy_admin:
  design:
    menu:
      - label: 'Clients'
        icon: 'users'
        entity: 'Customer'
        children:
          - { label: 'Show', entity: 'Customer', params: { action: 'list' } }
          - { label: 'Add', entity: 'Customer', params: { action: 'new' } }
      - label: 'Repairman'
        icon: 'users'
        entity: 'Repairman'
        children:
          - { label: 'Show', entity: 'Repairman', params: { action: 'list' } }
          - { label: 'Add', entity: 'Repairman', params: { action: 'new' } }

When I click on add a customer, I would like his role to be ROLE_CUSTOMER and when I click on add a repairman, his role to be ROLE_REPAIRMAN

I tried to extend the AdminController, the RepairmanController but I can't get what I want. I also tried to set a default value using :

- { property: 'roles', type: 'hidden', type_options: { empty_data: "['ROLE_REPAIRMAN']" } }

Here I have an error because he needs an array and he interprets the value as a string.

Can someone help me to figure it out please ? Or do you have a better solution ?

Thank you !


Viewing all articles
Browse latest Browse all 3925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>