In my module I use the mymodulename_entity_update()
function to listen when an entity is updated:
function mymodulename_entity_update($entity) {
file_put_contents(__DIR__.'/test.txt', $entity->bundle());
}
When I update an article or a page which is not related to menu link, I receive 'node'
as value of the ->bundle()
property, as expected.
But if I update a page which is related to a menu link, I receive the 'menu_link_content'
as the bundle value and all the data of the $entity
object is the data of menu link. The same data I receive when update a menu link. And the only thing that helps me to detect whether a page was updated or menu link is the ->expanded->value
property: in the case of a page it equals 0.
The second problem is, how to get ID of the node which is related to the menu link?
I was trying $entity->getRouteParameters()['node']
as recommended by the link https://drupal.stackexchange.com/a/281646/104765 but I receive the error
Call to undefined method
Drupal\menu_link_content\Entity\MenuLinkContent::getRouteParameters()...