Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / layout_builder / src / Controller / ChooseBlockController.php
index 5287be25fcff10b8908ebf93a5c9b3538bab84a2..ac8514c48d1c44dc26ae6f4ab0cf4c2f06f04e09 100644 (file)
@@ -2,8 +2,10 @@
 
 namespace Drupal\layout_builder\Controller;
 
+use Drupal\Core\Ajax\AjaxHelperTrait;
 use Drupal\Core\Block\BlockManagerInterface;
 use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
+use Drupal\Core\StringTranslation\StringTranslationTrait;
 use Drupal\Core\Url;
 use Drupal\layout_builder\Context\LayoutBuilderContextTrait;
 use Drupal\layout_builder\SectionStorageInterface;
@@ -18,6 +20,7 @@ class ChooseBlockController implements ContainerInjectionInterface {
 
   use AjaxHelperTrait;
   use LayoutBuilderContextTrait;
+  use StringTranslationTrait;
 
   /**
    * The block manager.
@@ -59,10 +62,19 @@ class ChooseBlockController implements ContainerInjectionInterface {
    *   A render array.
    */
   public function build(SectionStorageInterface $section_storage, $delta, $region) {
+    $build['#title'] = $this->t('Choose a block');
     $build['#type'] = 'container';
     $build['#attributes']['class'][] = 'block-categories';
 
-    $definitions = $this->blockManager->getDefinitionsForContexts($this->getAvailableContexts($section_storage));
+    // @todo Explicitly cast delta to an integer, remove this in
+    //   https://www.drupal.org/project/drupal/issues/2984509.
+    $delta = (int) $delta;
+
+    $definitions = $this->blockManager->getFilteredDefinitions('layout_builder', $this->getAvailableContexts($section_storage), [
+      'section_storage' => $section_storage,
+      'delta' => $delta,
+      'region' => $region,
+    ]);
     foreach ($this->blockManager->getGroupedDefinitions($definitions) as $category => $blocks) {
       $build[$category]['#type'] = 'details';
       $build[$category]['#open'] = TRUE;