Skip to content

Instantly share code, notes, and snippets.

@EclipseGc
Created September 18, 2012 17:50
Show Gist options
  • Save EclipseGc/3744611 to your computer and use it in GitHub Desktop.
Save EclipseGc/3744611 to your computer and use it in GitHub Desktop.
<?php
namespace Drupal\layout\Plugin\layout\layout;
use Drupal\layout\Plugin\LayoutInterface;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Annotations\Plugin;
/**
* @Plugin(
* derivative = "Drupal\layout\Plugin\Derivative\Layouts"
* )
*/
class DefaultLayout extends PluginBase implements LayoutInterface {
public function getRegions() {
$definition = $this->getDefinition();
return $definition['regions'];
}
public function getCss() {
$definition = $this->getDefinition();
drupal_add_css($definition['path'] . '/' . $definition['css']);
}
public function getAdminCss() {
$definition = $this->getDefinition();
$css = isset($definition['admin css']) ? $definition['admin css'] : $definition['css'];
drupal_add_css($definition['path'] . '/' . $css);
}
public function getJs() {
$definition = $this->getDefinition();
if (isset($definition['js'])) {
drupal_add_js($definition['path'] . '/' . $definition['js']);
}
}
public function renderLayout(RendererInterface $renderer, $admin = FALSE) {
$definition = $this->getDefinition();
$regions = array();
foreach ($this->getRegions() as $region => $title) {
foreach ($this->configuration['regions'][$region] as $block_id => $configuration) {
$block = block_load($block_id, $configuration);
if ($block->access()) {
// Need to check the caching method on the block to determine exactly
// how we're going to get it. Should probably be abstracted out of
// this code so that the renderer worries about it instead.
$regions[$region][] = $block->build();
}
}
}
if (!$admin) {
$this->getCss();
$this->getJs();
}
else {
$this->getAdminCss();
}
return theme($definition['layout'], $regions);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment