New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question/Bug] Issues adding a new property to an existing Core Entity #300
Comments
Hello @Allex1337 You did almost all right, except overriding the entity. Also steps with running oro:entity-config:cache:clear and oro:entity-extend:cache:clear are redundant. Here are correct steps:
That is all, after that you can do other changes, like creation datagrid. |
Hey @vsoroka, Thank you for your answer. Please read carefully all the steps from my post. Please look again at the steps followed by me and the outcome. |
I've tried your grid in the following way:
Could you please check it one more time? In case if it will not work, please upload your bundle, I will take a look at it. |
Hey @vsoroka, It seems to be working now but only without creating the entity and the extend entity (without having my own empty src/ContactBundle/Entity/ContactAddress.php & the one which is extended src/ContactBundle/Model/ExtendContactAddress.php with setters and getters for the new property) but this is the way it supposed to work? $contactAddress = new Oro\Bundle\ContactBundle\Entity\ContactAddress();
$contactAddress->setAreaName('demo'); cannot work (I've put the full namespace on purpose to ensure that we are referring to the core entity, since I do no longer have the empty entity and the one with the getters and setters)? All the documentation is seriously confusing on this point. Also, as a second note with lower priority, I had to override the bundle and copied the entire contents of Oro/Bundle/ContactBundle/Resources/views/Contact/index.html.twig to my src/ContactBundle/Resources/views/Contact/index.html.twig and changed the gridName for this to work. Is this the only method to set the new gridName properly? Is it possible to change only the gridName to not have to copy the entire contents of the index.html.twig file? Please clarify. |
Yes, to add new field you just need to create a migration. About adding your column on the contact grid. There are two solutions. The first one is to copy TWIG template and change grid name there. The second solution is to create an event listener for existing contact grid and add your column there. Here is an example of such listener: <?php
namespace Oro\Bridge\ContactUs\EventListener;
use Oro\Bundle\DataGridBundle\Event\BuildBefore;
class ContactRequestDatagridListener
{
/**
* @param BuildBefore $event
*/
public function onBuildBefore(BuildBefore $event)
{
$config = $event->getConfig();
$config->addColumn(
'customerUserName',
['label' => 'oro.contactus.contactrequest.customer_user.label'],
'customerUser.firstName as customerUserName',
['data_name' => 'customerUserName'],
[
'type' => 'string',
'data_name' => 'customerUserName'
]
);
$query = $config->getOrmQuery();
$query->addLeftJoin($query->getRootAlias().'.customer_user', 'customerUser');
}
} to register the listener use oro_contact_us_bridge.event_listener.contact_request_datagrid:
class: 'Oro\Bridge\ContactUs\EventListener\ContactRequestDatagridListener'
tags:
- { name: kernel.event_listener, event: oro_datagrid.datagrid.build.before.contacts-grid, method: onBuildBefore } |
Hey @vsoroka, Thanks again for the answer. But then how can I make a new instance of the ContactAddress class and set or get the new property somewhere in a service or controller if I would want to? $contactAddress = new Oro\Bundle\ContactBundle\Entity\ContactAddress();
$contactAddress->setAreaName('demo'); can no longer work. Should I retrieve somehow the entity differently or? A new instance of the cached entity is not wise and is also abstract by design. Looking forward for your answer. |
Your code will work fine. There is no difference for creation a regular and extendable entity because the autogenerated class is a superclass for extendable entity. |
Everything is clear now, thanks a lot for clarifications! All the best! |
Hey guys!
I have tried endlessly to add a property to a Core Entity and have it displayed in the data grid and nothing is working.
I have tried of course to follow all the steps from the documentation as well as many other things that passed through my mind and nothing seems to work.
Let me give you the following example:
To achieve this, I have the following:
src/ContactBundle/ContactBundle.php
src/ContactBundle/Entity/ContactAddress.php
src/ContactBundle/Model/ExtendContactAddress.php
*As a kind note - my ExtendContactAddress entity also extends the Core ContactAddress entity - I know this makes sense else it would be viewed as a standalone entity and not as an overwritten one, even though the documentation skips this part
src/ContactBundle/Migrations/Schema/v1_0/AddAreaNameToContactAddress.php
src/ContactBundle/Resources/config/oro/datagrids.yml
src/ContactBundle/Resources/config/oro/bundles.yml
But when I try to load the Contacts tab in the UI, it says "No records found" and in the Network console tab, the XHR request responded with:
No matter what I tried I end up with the same error. I cant get it shown in the UI.
I have also tried to overwrite the parameter oro_contact.contact_address.entity.class with my class (both via app/config/config.yml and even via a CompilerPass) and I cant seem to overcome this error.
Can you please explain what am I missing or if there is an issue?
Thanks a lot in advance!
The text was updated successfully, but these errors were encountered: