function block_content_entity_operation

Same name in other branches
  1. 10 core/modules/block_content/block_content.module \block_content_entity_operation()

Implements hook_entity_operation().

1 call to block_content_entity_operation()
BlockContentTest::testOperationLinks in core/modules/block_content/tests/src/Kernel/BlockContentTest.php
Tests the editing links for BlockContentBlock.

File

core/modules/block_content/block_content.module, line 223

Code

function block_content_entity_operation(EntityInterface $entity) : array {
    $operations = [];
    if ($entity instanceof BlockInterface) {
        $plugin = $entity->getPlugin();
        if ($plugin->getBaseId() === 'block_content') {
            $custom_block = \Drupal::entityTypeManager()->getStorage('block_content')
                ->loadByProperties([
                'uuid' => $plugin->getDerivativeId(),
            ]);
            $custom_block = reset($custom_block);
            if ($custom_block && $custom_block->access('update')) {
                $operations['block-edit'] = [
                    'title' => t('Edit block'),
                    'url' => $custom_block->toUrl('edit-form')
                        ->setOptions([]),
                    'weight' => 50,
                ];
            }
        }
    }
    return $operations;
}

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