class BlockContentThemeHooks

Theme hook implementations for block_content.

Hierarchy

Expanded class hierarchy of BlockContentThemeHooks

File

core/modules/block_content/src/Hook/BlockContentThemeHooks.php, line 14

Namespace

Drupal\block_content\Hook
View source
class BlockContentThemeHooks {
  public function __construct(protected readonly RequestStack $requestStack) {
  }
  
  /**
   * Implements hook_preprocess_HOOK() for entity_add_list.
   *
   * Adds query parameters to the add links on the block add page so they are
   * forwarded to the add form, this allows a theme to be set automatically
   * on the block.
   *
   * @see \Drupal\block_content\Controller\BlockContentController::addForm()
   */
  public function preprocessEntityAddList(&$variables) : void {
    $query = $this->requestStack
      ->getCurrentRequest()->query
      ->all();
    if (count($query) === 0) {
      return;
    }
    foreach ($variables['bundles'] as $bundleId => $bundle) {
      if ($bundle['add_link'] instanceof Link) {
        $url = $bundle['add_link']->getUrl();
        if ($url->getRouteName() !== 'entity.block_content.add_form') {
          continue;
        }
        $url->setOption('query', $query);
        $variables['bundles'][$bundleId]['add_link']->setUrl($url);
      }
    }
  }

}

Members

Title Sort descending Modifiers Object type Summary
BlockContentThemeHooks::preprocessEntityAddList public function Implements hook_preprocess_HOOK() for entity_add_list.
BlockContentThemeHooks::__construct public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.