class LayoutTestController

Controller routines for layout_test routes.

Hierarchy

Expanded class hierarchy of LayoutTestController

File

drupal/core/modules/layout/tests/lib/Drupal/layout_test/Controller/LayoutTestController.php, line 16
Contains \Drupal\layout_test\Controller\LayoutTestController.

Namespace

Drupal\layout_test\Controller
View source
class LayoutTestController implements ControllerInterface {

  /**
   * Stores the entity storage controller.
   *
   * @var \Drupal\Core\Entity\EntityStorageControllerInterface
   */
  protected $entityStorageController;

  /**
   * Constructs a \Drupal\layout_test\Controller\LayoutTestController object.
   *
   * @param \Drupal\Core\Entity\EntityStorageControllerInterface $entity_storage_controller
   *   The entity storage controller.
   */
  function __construct(EntityStorageControllerInterface $entity_storage_controller) {
    $this->entityStorageController = $entity_storage_controller;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('plugin.manager.entity')
      ->getStorageController('display'));
  }

  /**
   * Displays basic page for layout testing purposes.
   *
   * @return string
   *   An HTML string representing the contents of layout_test page.
   */
  public function layoutTestPage() {

    // Hack to enable and apply the theme to this page and manually invoke its
    // layout plugin and render it.
    global $theme;
    $theme = 'layout_test_theme';
    theme_enable(array(
      $theme,
    ));
    $displays = $this->entityStorageController
      ->load(array(
      'test_twocol',
    ));
    $display = reset($displays);
    $layout = $display
      ->getLayoutInstance();

    // @todo This tests that the layout can render its regions, but does not test
    //   block rendering: http://drupal.org/node/1812720.
    // Add sample content in the regions that is looked for in the tests.
    $regions = $layout
      ->getRegions();
    foreach ($regions as $region => $info) {
      $regions[$region] = '<h3>' . $info['label'] . '</h3>';
    }
    return $layout
      ->renderLayout(FALSE, $regions);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LayoutTestController::$entityStorageController protected property Stores the entity storage controller.
LayoutTestController::create public static function Instantiates a new instance of this controller. Overrides ControllerInterface::create
LayoutTestController::layoutTestPage public function Displays basic page for layout testing purposes.
LayoutTestController::__construct function Constructs a \Drupal\layout_test\Controller\LayoutTestController object.