OroPlatform Forums

Covering OroPlatform topics, including community updates and company announcements.

Forums 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 6 years, 7 months ago.

Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.

  • Creator
    Topic
  • #34448

    thinh2010
    Participant

    Hi,

    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
    Replies
  • #34449

    Hi,

    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:
    https://github.com/oroinc/platform/blob/2.3/src/Oro/Bundle/UserBundle/Migrations/Schema/v1_9/OroUserBundle.php

    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.

    #34450

    thinh2010
    Participant

    Hi,

    Thanks for your reply, I will try with twig extension

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

The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.

Back to top