Last active
November 28, 2016 21:58
-
-
Save jenter/e79b913e75c9345e42c496c126244fc4 to your computer and use it in GitHub Desktop.
A preprocess function that adds count wrappers in Drupal regions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Drupal\Component\Utility\Html; | |
use Drupal\Core\Render\Markup; | |
use Drupal\Core\Render\Element; | |
/** | |
* Implements hook_preprocess_region(). | |
*/ | |
function MYTHEME_preprocess_region(&$variables) { | |
$elements = $variables['elements']; | |
$region_children = Element::children($elements); | |
$variables['region'] = $elements['#region']; | |
// Utility regional classes for $content. | |
$variables['content'] = array(); | |
foreach ($region_children as $k => $v) { | |
$region_classes = Html::cleanCssIdentifier('region--' . ($k + 1) . '-of-' . count($region_children)); | |
$variables['content'][] = '<div class="' . $region_classes . '">' . $variables['elements'][$v]['#markup'] . '</div>'; | |
} | |
$variables['content'] = Markup::create(implode($variables['content'])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment