You are here

protected function ReusableBlocksController::loadBlockOrThrow in Gutenberg 8.2

Load a reusable block content entity or throw an HTTP exception.

An HTTP exception is thrown if the block could not be loaded or it's not a reusable block type.

Parameters

int $block_id: The block ID.

Return value

\Drupal\block_content\BlockContentInterface The block instance.

3 calls to ReusableBlocksController::loadBlockOrThrow()
ReusableBlocksController::delete in src/Controller/ReusableBlocksController.php
Delete reusable block.
ReusableBlocksController::load in src/Controller/ReusableBlocksController.php
Returns JSON representing the loaded blocks.
ReusableBlocksController::save in src/Controller/ReusableBlocksController.php
Saves reusable block.

File

src/Controller/ReusableBlocksController.php, line 188

Class

ReusableBlocksController
Returns responses for our blocks routes.

Namespace

Drupal\gutenberg\Controller

Code

protected function loadBlockOrThrow($block_id) {
  $block_id = (int) $block_id;
  if ($block_id > 0 && ($block = BlockContent::load($block_id))) {

    /* @var \Drupal\block_content\BlockContentInterface $block */
    if ($block
      ->bundle() !== 'reusable_block') {

      // Avoid accidental/malicious manipulation of non reusable blocks in
      // this controller.
      throw new BadRequestHttpException("Block '{$block_id}' is not a reusable block.");
    }
    return $block;
  }
  throw new NotFoundHttpException("Block '{$block_id}' does not exist.");
}