public function CustomBlockController::add

Displays add custom block links for available types.

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 'CustomBlockController::add'
custom_block.routing.yml in drupal/core/modules/block/custom_block/custom_block.routing.yml
drupal/core/modules/block/custom_block/custom_block.routing.yml

File

drupal/core/modules/block/custom_block/lib/Drupal/custom_block/Controller/CustomBlockController.php, line 74
Contains \Drupal\custom_block\Controller\CustomBlockController

Class

CustomBlockController

Namespace

Drupal\custom_block\Controller

Code

public function add() {
  $options = array();
  if (($theme = $this->request->attributes
    ->get('theme')) && in_array($theme, array_keys(list_themes()))) {

    // We have navigated to this page from the block library and will keep track
    // of the theme for redirecting the user to the configuration page for the
    // newly created block in the given theme.
    $options = array(
      'query' => array(
        'theme' => $theme,
      ),
    );
  }
  $types = $this->entityManager
    ->getStorageController('custom_block_type')
    ->load();
  if ($types && count($types) == 1) {
    $type = reset($types);

    // @todo convert this to OO once block/add/%type uses a Controller. Will
    //   be fixed in http://drupal.org/node/1978166.
    $this->moduleHandler
      ->loadInclude('custom_block', 'pages.inc');
    return custom_block_add($type);
  }
  return array(
    '#theme' => 'custom_block_add_list',
    '#content' => $types,
  );
}