function BlockContentHooks::entityOperation

Implements hook_entity_operation().

Attributes

#[Hook('entity_operation')]

File

core/modules/block_content/src/Hook/BlockContentHooks.php, line 144

Class

BlockContentHooks
Hook implementations for block_content.

Namespace

Drupal\block_content\Hook

Code

public function entityOperation(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' => $this->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.