How do I update the menu link description with hook_ENTITY_TYPE_presave()
?
I can print out the menu link title and menu link description with the following code.
kint($entity->menu['title']);
kint($entity->menu['description']);
I only want to update the menu link description when the menu link title is not NULL so the menu link will exist. In fact, I'm wanting to copy the menu link title into the menu link description (when the menu link title is not empty).
The following code updates the node title, but I would like to know how to update the menu link description.
/**
* Implements hook_ENTITY_TYPE_presave().
*/
function hook_entity_presave(Drupal\Core\Entity\EntityInterface $entity) {
if ($entity->bundle() == 'page') {
// save a different value as title
$entity->title = 'New Title';
// The below outputs the 'title' and 'description' of the menu link
kint($entity->menu['title']);
kint($entity->menu['description']);
// how do I update the menu description?
// the below doesn't work?
$entity->menu['description'] = "New menu link description";
}
}