You are here

public function BlockContentController::add in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/block_content/src/Controller/BlockContentController.php \Drupal\block_content\Controller\BlockContentController::add()

Displays add custom block links for available types.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The current request object.

Return value

array A render array for a list of the custom block types that can be added or if there is only one custom block type defined for the site, the function returns the custom block add page for that custom block type.

1 string reference to 'BlockContentController::add'
block_content.routing.yml in core/modules/block_content/block_content.routing.yml
core/modules/block_content/block_content.routing.yml

File

core/modules/block_content/src/Controller/BlockContentController.php, line 80
Contains \Drupal\block_content\Controller\BlockContentController.

Class

BlockContentController

Namespace

Drupal\block_content\Controller

Code

public function add(Request $request) {
  $types = $this->blockContentTypeStorage
    ->loadMultiple();
  if ($types && count($types) == 1) {
    $type = reset($types);
    return $this
      ->addForm($type, $request);
  }
  if (count($types) === 0) {
    return array(
      '#markup' => $this
        ->t('You have not created any block types yet. Go to the <a href=":url">block type creation page</a> to add a new block type.', [
        ':url' => Url::fromRoute('block_content.type_add')
          ->toString(),
      ]),
    );
  }
  return array(
    '#theme' => 'block_content_add_list',
    '#content' => $types,
  );
}