Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh

In this article, I'll show you how to create or update entity operations links in Drupal 8 by using hook_entity_operation.

Suppose I want to add custom operation and link it to my own page, but only for article content type. I can do it by implementing hook_entity_operation link following.

 * Implements hook_entity_operation().
function MODULENAME_entity_operation_alter(array &$operations, EntityInterface $entity) {
    $entityTypeId = $entity->getEntityTypeId();
    if ($entityTypeId !== 'node') {
    $nodeType = $entity->getType();
    $nodeId = $entity->id();
    if ($nodeType === 'article') {
        // add custom operation
        $editUrl = Url::fromRoute('entity.node.edit_form', ['node' => $nodeId]);
        $operations['custom_operation'] = array(
            'title' => t('Custom'),
            'weight' => 20,
            'url' => $editUrl,
custom operation link

also using hook_entity_operation, you can modify any entity operations links, for example modify the article edit operation and link it to your own page.


Add new comment

Restricted HTML


Page Facebook

Become a patron

If you need some help or you search a Drupal freelancer don't hesitate to contact us.


Contact Us

All the content is FREE but I still need your help


Become a patreon