Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176
This commit is contained in:
commit
9921556621
13277 changed files with 1459781 additions and 0 deletions
36
core/modules/block/src/Controller/BlockAddController.php
Normal file
36
core/modules/block/src/Controller/BlockAddController.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\block\Controller\BlockAddController.
|
||||
*/
|
||||
|
||||
namespace Drupal\block\Controller;
|
||||
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Controller for building the block instance add form.
|
||||
*/
|
||||
class BlockAddController extends ControllerBase {
|
||||
|
||||
/**
|
||||
* Build the block instance add form.
|
||||
*
|
||||
* @param string $plugin_id
|
||||
* The plugin ID for the block instance.
|
||||
* @param string $theme
|
||||
* The name of the theme for the block instance.
|
||||
*
|
||||
* @return array
|
||||
* The block instance edit form.
|
||||
*/
|
||||
public function blockAddConfigureForm($plugin_id, $theme) {
|
||||
// Create a block entity.
|
||||
$entity = $this->entityManager()->getStorage('block')->create(array('plugin' => $plugin_id, 'theme' => $theme));
|
||||
|
||||
return $this->entityFormBuilder()->getForm($entity);
|
||||
}
|
||||
|
||||
}
|
||||
101
core/modules/block/src/Controller/BlockController.php
Normal file
101
core/modules/block/src/Controller/BlockController.php
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\block\Controller\BlockController.
|
||||
*/
|
||||
|
||||
namespace Drupal\block\Controller;
|
||||
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Drupal\Core\Extension\ThemeHandler;
|
||||
use Drupal\Core\Extension\ThemeHandlerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Controller routines for admin block routes.
|
||||
*/
|
||||
class BlockController extends ControllerBase {
|
||||
|
||||
/**
|
||||
* The theme handler.
|
||||
*
|
||||
* @var \Drupal\Core\Extension\ThemeHandlerInterface
|
||||
*/
|
||||
protected $themeHandler;
|
||||
|
||||
/**
|
||||
* Constructs a new BlockController instance.
|
||||
*
|
||||
* @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
|
||||
* The theme handler.
|
||||
*/
|
||||
public function __construct(ThemeHandlerInterface $theme_handler) {
|
||||
$this->themeHandler = $theme_handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('theme_handler')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a block theme demo page.
|
||||
*
|
||||
* @param string $theme
|
||||
* The name of the theme.
|
||||
*
|
||||
* @return array
|
||||
* A #type 'page' render array containing the block region demo.
|
||||
*/
|
||||
public function demo($theme) {
|
||||
$page = [
|
||||
'#title' => $this->themeHandler->getName($theme),
|
||||
'#type' => 'page',
|
||||
'#attached' => array(
|
||||
'drupalSettings' => [
|
||||
// The block demonstration page is not marked as an administrative
|
||||
// page by \Drupal::service('router.admin_context')->isAdminRoute()
|
||||
// function in order to use the frontend theme. Since JavaScript
|
||||
// relies on a proper separation of admin pages, it needs to know this
|
||||
// is an actual administrative page.
|
||||
'path' => ['currentPathIsAdmin' => TRUE],
|
||||
],
|
||||
'library' => array(
|
||||
'block/drupal.block.admin',
|
||||
),
|
||||
),
|
||||
];
|
||||
|
||||
// Show descriptions in each visible page region, nothing else.
|
||||
$visible_regions = $this->getVisibleRegionNames($theme);
|
||||
foreach (array_keys($visible_regions) as $region) {
|
||||
$page[$region]['block_description'] = array(
|
||||
'#type' => 'inline_template',
|
||||
'#template' => '<div class="block-region demo-block">{{ region_name }}</div>',
|
||||
'#context' => array('region_name' => $visible_regions[$region]),
|
||||
);
|
||||
}
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the human-readable list of regions keyed by machine name.
|
||||
*
|
||||
* @param string $theme
|
||||
* The name of the theme.
|
||||
*
|
||||
* @return array
|
||||
* An array of human-readable region names keyed by machine name.
|
||||
*/
|
||||
protected function getVisibleRegionNames($theme) {
|
||||
return system_region_list($theme, REGIONS_VISIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
34
core/modules/block/src/Controller/BlockListController.php
Normal file
34
core/modules/block/src/Controller/BlockListController.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\block\Controller\BlockListController.
|
||||
*/
|
||||
|
||||
namespace Drupal\block\Controller;
|
||||
|
||||
use Drupal\Core\Entity\Controller\EntityListController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Defines a controller to list blocks.
|
||||
*/
|
||||
class BlockListController extends EntityListController {
|
||||
|
||||
/**
|
||||
* Shows the block administration page.
|
||||
*
|
||||
* @param string|null $theme
|
||||
* Theme key of block list.
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
* The current request.
|
||||
*
|
||||
* @return array
|
||||
* A render array as expected by drupal_render().
|
||||
*/
|
||||
public function listing($theme = NULL, Request $request = NULL) {
|
||||
$theme = $theme ?: $this->config('system.theme')->get('default');
|
||||
return $this->entityManager()->getListBuilder('block')->render($theme, $request);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\block\Controller\CategoryAutocompleteController.
|
||||
*/
|
||||
|
||||
namespace Drupal\block\Controller;
|
||||
|
||||
use Drupal\Core\Block\BlockManagerInterface;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Returns autocomplete responses for block categories.
|
||||
*/
|
||||
class CategoryAutocompleteController implements ContainerInjectionInterface {
|
||||
|
||||
/**
|
||||
* The block manager.
|
||||
*
|
||||
* @var \Drupal\Core\Block\BlockManagerInterface
|
||||
*/
|
||||
protected $blockManager;
|
||||
|
||||
/**
|
||||
* Constructs a new CategoryAutocompleteController.
|
||||
*
|
||||
* @param \Drupal\Core\Block\BlockManagerInterface $block_manager
|
||||
* The block manager.
|
||||
*/
|
||||
public function __construct(BlockManagerInterface $block_manager) {
|
||||
$this->blockManager = $block_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('plugin.manager.block')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves suggestions for block category autocompletion.
|
||||
*
|
||||
* @param \Symfony\Component\HttpFoundation\Request $request
|
||||
* The current request.
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\JsonResponse
|
||||
* A JSON response containing autocomplete suggestions.
|
||||
*/
|
||||
public function autocomplete(Request $request) {
|
||||
$typed_category = $request->query->get('q');
|
||||
$matches = array();
|
||||
foreach ($this->blockManager->getCategories() as $category) {
|
||||
if (stripos($category, $typed_category) === 0) {
|
||||
$matches[] = array('value' => $category, 'label' => SafeMarkup::checkPlain($category));
|
||||
}
|
||||
}
|
||||
return new JsonResponse($matches);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in a new issue