Created
August 8, 2020 19:39
-
-
Save heitoralthmann/f940e4a22d95ce7164a0df179be9a561 to your computer and use it in GitHub Desktop.
How to add new entity operations in Drupal 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_entity_operation(). | |
*/ | |
function modulename_entity_operation(\Drupal\Core\Entity\EntityInterface $entity) { | |
if(in_array($entity->bundle(), ['article'])) { | |
$operations = array(); | |
$operations['play'] = array( | |
'title' => t('Play'), | |
'url' => Url::fromRoute('some.route',["node" => $entity->id()]), | |
'weight' => 150, | |
); | |
$operations['another_play'] = array( | |
'title' => t('Just an example for multiple'), | |
'url' => Url::fromRoute('some.route',["node" => $entity->id()]), | |
'weight' => 151, | |
); | |
return $operations; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment