Chris@0: blockManager = $block_manager; Chris@0: $this->routeMatch = $route_match; Chris@0: $this->localActionManager = $local_action_manager; Chris@0: $this->contextRepository = $context_repository; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function create(ContainerInterface $container) { Chris@0: return new static( Chris@0: $container->get('plugin.manager.block'), Chris@0: $container->get('context.repository'), Chris@0: $container->get('current_route_match'), Chris@0: $container->get('plugin.manager.menu.local_action') Chris@0: ); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Shows a list of blocks that can be added to a theme's layout. Chris@0: * Chris@0: * @param \Symfony\Component\HttpFoundation\Request $request Chris@0: * The current request. Chris@0: * @param string $theme Chris@0: * Theme key of the block list. Chris@0: * Chris@0: * @return array Chris@0: * A render array as expected by the renderer. Chris@0: */ Chris@0: public function listBlocks(Request $request, $theme) { Chris@0: // Since modals do not render any other part of the page, we need to render Chris@0: // them manually as part of this listing. Chris@0: if ($request->query->get(MainContentViewSubscriber::WRAPPER_FORMAT) === 'drupal_modal') { Chris@0: $build['local_actions'] = $this->buildLocalActions(); Chris@0: } Chris@0: Chris@0: $headers = [ Chris@0: ['data' => $this->t('Block')], Chris@0: ['data' => $this->t('Category')], Chris@0: ['data' => $this->t('Operations')], Chris@0: ]; Chris@0: Chris@17: $region = $request->query->get('region'); Chris@17: $weight = $request->query->get('weight'); Chris@17: Chris@0: // Only add blocks which work without any available context. Chris@17: $definitions = $this->blockManager->getFilteredDefinitions('block_ui', $this->contextRepository->getAvailableContexts(), [ Chris@17: 'theme' => $theme, Chris@17: 'region' => $region, Chris@17: ]); Chris@0: // Order by category, and then by admin label. Chris@0: $definitions = $this->blockManager->getSortedDefinitions($definitions); Chris@14: // Filter out definitions that are not intended to be placed by the UI. Chris@14: $definitions = array_filter($definitions, function (array $definition) { Chris@14: return empty($definition['_block_ui_hidden']); Chris@14: }); Chris@0: Chris@0: $rows = []; Chris@0: foreach ($definitions as $plugin_id => $plugin_definition) { Chris@0: $row = []; Chris@0: $row['title']['data'] = [ Chris@0: '#type' => 'inline_template', Chris@0: '#template' => '