You are here

public function FixedToContentMappingHandler::getFixedBlock in Fixed Block Content 8

Gets the fixed block linked to the given block content.

Parameters

\Drupal\block_content\BlockContentInterface $block_content: The block content.

Return value

\Drupal\fixed_block_content\FixedBlockContentInterface|null The fixed block, NULL if none found.

Overrides FixedToContentMappingHandlerInterface::getFixedBlock

File

src/FixedToContentMappingHandler.php, line 144

Class

FixedToContentMappingHandler
Fixed block to block content mapping entity handler.

Namespace

Drupal\fixed_block_content

Code

public function getFixedBlock(BlockContentInterface $block_content) {

  // New block content cannot be linked to any fixed block.
  if ($block_content
    ->isNew()) {
    return NULL;
  }

  /** @var \Drupal\Core\Database\StatementInterface $bids */
  $bids = $this->database
    ->select('fixed_block_content', 'fbc')
    ->fields('fbc', [
    'fbid',
  ])
    ->range(0, 1)
    ->condition('fbc.bid', $block_content
    ->id())
    ->execute();
  if ($fbid = $bids
    ->fetchField()) {
    $fixed_block_content_storage = $this->entityTypeManager
      ->getStorage('fixed_block_content');
    return $fixed_block_content_storage
      ->load($fbid);
  }
  return NULL;
}