Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. FieldUiHooks.php

function FieldUiHooks::entityOperation

Implements hook_entity_operation().

File

core/modules/field_ui/src/Hook/FieldUiHooks.php, line 150

Class

FieldUiHooks
Hook implementations for field_ui.

Namespace

Drupal\field_ui\Hook

Code

public function entityOperation(EntityInterface $entity) {
    $operations = [];
    $info = $entity->getEntityType();
    // Add manage fields and display links if this entity type is the bundle
    // of another and that type has field UI enabled.
    if (($bundle_of = $info->getBundleOf()) && \Drupal::entityTypeManager()->getDefinition($bundle_of)
        ->get('field_ui_base_route')) {
        $account = \Drupal::currentUser();
        if ($account->hasPermission('administer ' . $bundle_of . ' fields')) {
            $operations['manage-fields'] = [
                'title' => t('Manage fields'),
                'weight' => 15,
                'url' => Url::fromRoute("entity.{$bundle_of}.field_ui_fields", [
                    $entity->getEntityTypeId() => $entity->id(),
                ]),
            ];
        }
        if ($account->hasPermission('administer ' . $bundle_of . ' form display')) {
            $operations['manage-form-display'] = [
                'title' => t('Manage form display'),
                'weight' => 20,
                'url' => Url::fromRoute("entity.entity_form_display.{$bundle_of}.default", [
                    $entity->getEntityTypeId() => $entity->id(),
                ]),
            ];
        }
        if ($account->hasPermission('administer ' . $bundle_of . ' display')) {
            $operations['manage-display'] = [
                'title' => t('Manage display'),
                'weight' => 25,
                'url' => Url::fromRoute("entity.entity_view_display.{$bundle_of}.default", [
                    $entity->getEntityTypeId() => $entity->id(),
                ]),
            ];
        }
    }
    return $operations;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal