Issue #2011094 by kgoel: Replace drupal_container() with Drupal::service() in the layout module.

8.0.x
Alex Pott 2013-07-11 10:25:29 +01:00
parent b67660cde3
commit 0059c7f01d
4 changed files with 6 additions and 16 deletions

View File

@ -17,11 +17,11 @@
* @see layout_menu() * @see layout_menu()
*/ */
function layout_page_view($key) { function layout_page_view($key) {
$layout = layout_manager()->getDefinition($key); $layout = Drupal::service('plugin.manager.layout')->getDefinition($key);
drupal_set_title(t('View template %name', array('%name' => $layout['title'])), PASS_THROUGH); drupal_set_title(t('View template %name', array('%name' => $layout['title'])), PASS_THROUGH);
// Render the layout in an admin context with region demonstrations. // Render the layout in an admin context with region demonstrations.
$instance = layout_manager()->createInstance($key, array()); $instance = Drupal::service('plugin.manager.layout')->createInstance($key, array());
$regions = $instance->getRegions(); $regions = $instance->getRegions();
foreach ($regions as $region => $info) { foreach ($regions as $region => $info) {
$regions[$region] = '<div class="layout-region-demonstration">' . check_plain($info['label']) . '</div>'; $regions[$region] = '<div class="layout-region-demonstration">' . check_plain($info['label']) . '</div>';

View File

@ -36,7 +36,7 @@ function layout_menu() {
* otherwise. * otherwise.
*/ */
function layout_user_access($key) { function layout_user_access($key) {
return (user_access('administer layouts') && layout_manager()->getDefinition($key)); return (user_access('administer layouts') && Drupal::service('plugin.manager.layout')->getDefinition($key));
} }
/** /**
@ -51,16 +51,6 @@ function layout_permission() {
); );
} }
/**
* Get the layout plugin manager instance.
*
* @return Drupal\layout\Plugin\Type\LayoutManager
* The layout plugin manager instance.
*/
function layout_manager() {
return drupal_container()->get('plugin.manager.layout');
}
/** /**
* Implements hook_theme(). * Implements hook_theme().
* *
@ -68,7 +58,7 @@ function layout_manager() {
*/ */
function layout_theme($existing, $type, $theme, $path) { function layout_theme($existing, $type, $theme, $path) {
$items = array(); $items = array();
foreach (layout_manager()->getDefinitions() as $name => $layout) { foreach (Drupal::service('plugin.manager.layout')->getDefinitions() as $name => $layout) {
$items[$layout['theme']] = array( $items[$layout['theme']] = array(
'variables' => array('content' => NULL), 'variables' => array('content' => NULL),
'path' => $layout['path'], 'path' => $layout['path'],

View File

@ -179,7 +179,7 @@ class Display extends DisplayBase implements BoundDisplayInterface {
throw new \Exception(sprintf('Display "%id" had no layout plugin attached.', array('%id' => $this->id())), E_RECOVERABLE_ERROR); throw new \Exception(sprintf('Display "%id" had no layout plugin attached.', array('%id' => $this->id())), E_RECOVERABLE_ERROR);
} }
$this->layoutInstance = layout_manager()->createInstance($this->layout, $this->layoutSettings); $this->layoutInstance = \Drupal::service('plugin.manager.layout')->createInstance($this->layout, $this->layoutSettings);
// @todo add handling for remapping if the layout could not be found // @todo add handling for remapping if the layout could not be found
} }

View File

@ -33,7 +33,7 @@ class LayoutDerivativesTest extends WebTestBase {
* Tests for module/theme layout derivatives. * Tests for module/theme layout derivatives.
*/ */
function testDerivatives() { function testDerivatives() {
$manager = drupal_container()->get('plugin.manager.layout'); $manager = $this->container->get('plugin.manager.layout');
$definitions = $manager->getDefinitions(); $definitions = $manager->getDefinitions();
$this->assertTrue(is_array($definitions), 'Definitions found.'); $this->assertTrue(is_array($definitions), 'Definitions found.');