Forums OroPlatform OroPlatform – Programming Questions add function to entity that extended

This topic contains 2 replies, has 2 voices, and was last updated by  thinh2010 4 months, 2 weeks ago.

  • Creator
  • #28972



    I extended User entity. Now I want to create a fucntion getCustomName() to return my custom name for user
    and then I can call it via twig by user.customName

    Do you know how can I do that?

    This is my information about the system I use

    Application Type: OroPlatform
    Application Version: 2.0.*
    Application Edition: Community

    OS, name and version: Ubuntu 14.04 64bit
    Web server, name and version: Apache,
    Database, name and version: MarialDB 10.0.21
    PHP, version: 5.6.30

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
  • #28973


    1. If you need to add some additional filed to entity User, you can create migration in custom bundle to create a extend field for entity.
    Example for field ‘title’ of user entity:

    To add field CustomName you need create migration like this

    As result new column ‘customName’ will be created in oro_user table.
    Entity User will have property $customName and methods getCustomName and setCustomName.

    Value is available in twig template by user.customName.
    Also field customName is added on user edit page.

    2. If you need some method which will return value based on other properties of entity user and it should be available in twig template, in this case better create twig extension and use it.




    Thanks for your reply, I will try with twig extension

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.