MenuOperationsLinkTestHooks.php

Namespace

Drupal\menu_operations_link_test\Hook

File

core/modules/menu_link_content/tests/menu_operations_link_test/src/Hook/MenuOperationsLinkTestHooks.php

View source
<?php

declare (strict_types=1);
namespace Drupal\menu_operations_link_test\Hook;

use Drupal\Core\Url;
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Hook\Attribute\Hook;

/**
 * Hook implementations for menu_operations_link_test.
 */
class MenuOperationsLinkTestHooks {
    
    /**
     * Implements hook_entity_operation_alter().
     */
    public function entityOperationAlter(array &$operations, EntityInterface $entity) {
        if (!$entity instanceof MenuLinkContent) {
            return;
        }
        // Alter the title of the edit link appearing in operations menu.
        $operations['edit']['title'] = t('Altered Edit Title');
    }
    
    /**
     * Implements hook_entity_operation().
     */
    public function entityOperation(EntityInterface $entity) {
        if (!$entity instanceof MenuLinkContent) {
            return;
        }
        $operations['custom_operation'] = [
            'title' => t('Custom Home'),
            'weight' => 20,
            'url' => Url::fromRoute('<front>'),
        ];
        return $operations;
    }

}

Classes

Title Deprecated Summary
MenuOperationsLinkTestHooks Hook implementations for menu_operations_link_test.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.