Easyadminbundle: misd-service-development/phone-number-bundle not supported

Created on 18 Nov 2015  路  8Comments  路  Source: EasyCorp/EasyAdminBundle

Hey, by default, a phonenumber Type attribute is not being displayed,
I'm using a phonenumber column type from this bundle:
https://github.com/misd-service-development/phone-number-bundle

It's not beeing displayed in the list neither in the details view.

btw. great bundle!!

Most helpful comment

Works as a charm:

      #...
            edit:
                fields:
                    - { property: 'phone', type: 'Misd\PhoneNumberBundle\Form\Type\PhoneNumberType' }

Thanks @xabbuh

All 8 comments

The type field option is interpreted in two different ways:

  • In form-based views (new, edit) this is the form type. I guess this works for you.
  • In the other views (list, show) we can't use form types, so this is interpreted as the type of data stored in the property.

A quick fix for this problem is to use the raw type in list and show, which just outputs the contents of this property applying the |raw Twig filter:

easy_admin:
    # ...
    entities:
        User:
            list:
                fields:
                    - { property: 'phone', type: 'raw' }

If you still want to apply so custom formatting to better display the property contents, define the template option for the field and create the Twig template to display its contents:

easy_admin:
    # ...
    entities:
        User:
            list:
                fields:
                    - { property: 'phone', template: 'phonenumber' }

And now create either of these templates (first one that exists is used):

  • app/Resources/views/easy_admin/User/phonenumber.html.twig
  • app/Resources/views/easy_admin/phonenumber.html.twig

I'm fascinated from you and your bundle! :+1:
Thank you very much

The phone-number-bundle provides a twig function:

{{ phone_number_format(myPhoneNumber, 'INTERNATIONAL') }}

I think you should use it in the template which @javiereguiluz described.

It also declares a FormType here:
https://github.com/misd-service-development/phone-number-bundle/blob/master/Form/Type/PhoneNumberType.php

You can use either tel or the type's FQCN as type attribute in the EasyAdmin config. It's much better because you can then create a field_tel.html.twig template for list and show views, and the form type will automatically trigger validation based on the bundle's form type.

Closing it as "fixed". In the near term I'm gonna revamp the documentation to make it easier to find solutions for common problems like this one.

Hey, I am having Could not load type "phone_number" problem in edit template.
I've already fixed the not displaying in list template by creating the phonenumber template as said @javiereguiluz.
I'm using Symfony 3.1.6
Any help please?

@janjango There is no phone_number form type (I guess you are confusing the form type and the DBAL type both provided by that bundle). You should use the FQCN instead which is Misd\PhoneNumberBundle\Form\Type\PhoneNumberType.

Works as a charm:

      #...
            edit:
                fields:
                    - { property: 'phone', type: 'Misd\PhoneNumberBundle\Form\Type\PhoneNumberType' }

Thanks @xabbuh

Was this page helpful?
0 / 5 - 0 ratings

Related issues

haithem-rihane picture haithem-rihane  路  4Comments

Ealenn picture Ealenn  路  3Comments

devkbsc picture devkbsc  路  3Comments

tamert picture tamert  路  3Comments

nickicool picture nickicool  路  4Comments