Skip to content

Instantly share code, notes, and snippets.

@heitoralthmann
Created August 8, 2020 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heitoralthmann/f940e4a22d95ce7164a0df179be9a561 to your computer and use it in GitHub Desktop.
Save heitoralthmann/f940e4a22d95ce7164a0df179be9a561 to your computer and use it in GitHub Desktop.
How to add new entity operations in Drupal 8
<?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