OroCRM Forums

Covering OroCRM topics, including community updates and company announcements.

Forums Forums OroCRM OroCRM – Programming Questions Variable "entity" does not exist error

This topic contains 4 replies, has 2 voices, and was last updated by  Madhur 8 years, 2 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
  • #25085

    Madhur
    Participant

    Hi,

    Wish you all a very happy new year.

    I have created a custom entity using bundles. The Grid, Update, Create and Delete is working fine. But when I want to view the record, it is giving me this weird error:

    Variable “entity” does not exist in OroUIBundle:actions:view.html.twig at line 15

    Now I have no clue as to why this error is occurring. My view.html.twig looks like this:


    {% extends 'OroUIBundle:actions:view.html.twig' %}
    {% import 'OroUIBundle::macros.html.twig' as UI %}
    {% block navButtons %}
    {% if resource_granted('EDIT', partindex) %}
    {{ UI.editButton({
    'path' : path('partindex.partindex_update', { 'id': partindex.id }),
    'entity_label': 'PartIndex'|trans
    }) }}
    {% endif %}

    {% if resource_granted('DELETE', partindex) %}
    {{ UI.deleteButton({
    'dataUrl': path('partindex_api_delete_partindex', {'id': partindex.id}),
    'dataRedirect': path('partindex.partindex_index'),
    'aCss': 'no-hash remove-button',
    'id': 'btn-remove-partindex',
    'dataId': partindex.id,
    'entity_label': 'PartIndex'|trans,
    }) }}
    {% endif %}
    {% endblock navButtons %}

    {% block content_data %}
    {% set data %}
    <div class="widget-content">
    <div class="row-fluid form-horizontal">
    <div class="responsive-block">
    {{ UI.renderProperty('Code'|trans, partindex.partindexcode) }}
    {{ UI.renderProperty('Label'|trans, partindex.partindexlabel) }}
    </div>
    </div>
    </div>
    {% endset %}
    {% set dataBlocks = [
    {
    'title': 'Data'|trans,
    'class': 'active',
    'subblocks': [
    { 'data' : [data] }
    ]
    }
    ] %}

    {% set id = 'partindexView' %}
    {% set data = { 'dataBlocks': dataBlocks } %}
    {{ parent() }}
    {% endblock content_data %}

    Can you please tell me what I am doing wrong?

    Thanks and Regards,
    Madhur

Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
    Replies
  • #25086

    Rodolfo
    Participant

    Hi there!

    The UIBundle requires an object called “entity” here: https://github.com/orocrm/platform/blob/master/src/Oro/Bundle/UIBundle/Resources/views/actions/view.html.twig#L15

    So in order to fix that, you must send the entity from your controller when you call your template. Something like this:

    Let us know if it works! :)

    #25087

    Madhur
    Participant

    Hi Rodolfo,

    Thanks, that worked. The method in the controller was defined like this:

    So instead of that I wrote it as:

    and changed the twig template as :

    and it worked. :)

    Thanks.

    To continue with that, how do we add REST API methods to a custom entity and make it available publicly? These custom entities should be visible in an android app. And the best way to collect information from orocrm would be to use the REST API’s. So can you please point me in the right direction? How can I create REST API’s for my custom entities?

    Thanks for the good support. :)

    #25088

    Rodolfo
    Participant

    Hi there,

    Glad to hear that worked!

    Oro has an out-of-the-box solution to provide authentication when you want to use RESTApi. You can find more information here: https://github.com/orocrm/documentation/blob/master/cookbook/how_to_use_wsse_authentication.rst

    After authenticated, you can use all the abstract methods from Oro Platform. I believe the best way to learn how to implement it is checking some existing code. For example OroNoteBundle.

    Controllers:
    https://github.com/orocrm/platform/blob/master/src/Oro/Bundle/NoteBundle/Controller/Api/Rest/NoteController.php#L77-L92

    Form Handler:
    https://github.com/orocrm/platform/blob/master/src/Oro/Bundle/NoteBundle/Form/Handler/NoteApiHandler.php

    Form Type:
    https://github.com/orocrm/platform/blob/master/src/Oro/Bundle/NoteBundle/Form/Type/NoteApiType.php

    Routes:
    https://github.com/orocrm/platform/blob/master/src/Oro/Bundle/NoteBundle/Resources/config/oro/routing.yml#L6-L34

    Good luck!

    #25089

    Madhur
    Participant

    Hi Rodolfo,

    Thank you very much. I was able to get the REST API’s working. The links helped. :)

    Thanks and Regards,
    Madhur

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

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

Back to top