Chris@14: blockManager = $block_manager; Chris@14: } Chris@14: Chris@14: /** Chris@14: * {@inheritdoc} Chris@14: */ Chris@14: public static function create(ContainerInterface $container) { Chris@14: return new static( Chris@14: $container->get('plugin.manager.block') Chris@14: ); Chris@14: } Chris@14: Chris@14: /** Chris@14: * Provides the UI for choosing a new block. Chris@14: * Chris@14: * @param \Drupal\layout_builder\SectionStorageInterface $section_storage Chris@14: * The section storage. Chris@14: * @param int $delta Chris@14: * The delta of the section to splice. Chris@14: * @param string $region Chris@14: * The region the block is going in. Chris@14: * Chris@14: * @return array Chris@14: * A render array. Chris@14: */ Chris@14: public function build(SectionStorageInterface $section_storage, $delta, $region) { Chris@14: $build['#type'] = 'container'; Chris@14: $build['#attributes']['class'][] = 'block-categories'; Chris@14: Chris@14: $definitions = $this->blockManager->getDefinitionsForContexts($this->getAvailableContexts($section_storage)); Chris@14: foreach ($this->blockManager->getGroupedDefinitions($definitions) as $category => $blocks) { Chris@14: $build[$category]['#type'] = 'details'; Chris@14: $build[$category]['#open'] = TRUE; Chris@14: $build[$category]['#title'] = $category; Chris@14: $build[$category]['links'] = [ Chris@14: '#theme' => 'links', Chris@14: ]; Chris@14: foreach ($blocks as $block_id => $block) { Chris@14: $link = [ Chris@14: 'title' => $block['admin_label'], Chris@14: 'url' => Url::fromRoute('layout_builder.add_block', Chris@14: [ Chris@14: 'section_storage_type' => $section_storage->getStorageType(), Chris@14: 'section_storage' => $section_storage->getStorageId(), Chris@14: 'delta' => $delta, Chris@14: 'region' => $region, Chris@14: 'plugin_id' => $block_id, Chris@14: ] Chris@14: ), Chris@14: ]; Chris@14: if ($this->isAjax()) { Chris@14: $link['attributes']['class'][] = 'use-ajax'; Chris@14: $link['attributes']['data-dialog-type'][] = 'dialog'; Chris@14: $link['attributes']['data-dialog-renderer'][] = 'off_canvas'; Chris@14: } Chris@14: $build[$category]['links']['#links'][] = $link; Chris@14: } Chris@14: } Chris@14: return $build; Chris@14: } Chris@14: Chris@14: }