public function CountBlock::build in Basic cart 8.5
Same name and namespace in other branches
- 8.6 src/Plugin/Block/CountBlock.php \Drupal\basic_cart\Plugin\Block\CountBlock::build()
- 8.2 src/Plugin/Block/CountBlock.php \Drupal\basic_cart\Plugin\Block\CountBlock::build()
- 8.3 src/Plugin/Block/CountBlock.php \Drupal\basic_cart\Plugin\Block\CountBlock::build()
- 8.4 src/Plugin/Block/CountBlock.php \Drupal\basic_cart\Plugin\Block\CountBlock::build()
Builds and returns the renderable array for this block plugin.
If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).
Return value
array A renderable array representing the content of the block.
Overrides BlockPluginInterface::build
See also
\Drupal\block\BlockViewBuilder
File
- src/
Plugin/ Block/ CountBlock.php, line 23
Class
- CountBlock
- Provides a 'Basic Cart Count' block.
Namespace
Drupal\basic_cart\Plugin\BlockCode
public function build() {
$config = $this
->getConfiguration();
$render = array(
'#theme' => 'basic_cart_count_block',
'#cartcount' => Utility::cartCount(),
'#cache' => array(
'max-age' => 0,
),
);
if ($config['float']) {
$render['#float'] = SafeMarkup::checkPlain($config['float'])
->__toString();
}
if ($config['size']) {
$render['#size'] = SafeMarkup::checkPlain($config['size'])
->__toString();
$render['#size_class'] = "-" . str_replace("x", "-", SafeMarkup::checkPlain($config['size'])
->__toString());
$css = str_replace("x", "", SafeMarkup::checkPlain($config['size'])
->__toString());
}
if ($config['top']) {
$render['#top'] = SafeMarkup::checkPlain($config['top'])
->__toString() . 'px';
}
if ($config['bottom']) {
$render['#bottom'] = SafeMarkup::checkPlain($config['bottom'])
->__toString() . 'px';
}
if ($config['left']) {
$render['#left'] = SafeMarkup::checkPlain($config['left'])
->__toString() . 'px';
}
if ($config['right']) {
$render['#right'] = SafeMarkup::checkPlain($config['right'])
->__toString() . 'px';
}
if (!$css) {
$css = "4839";
}
$render['#attached']['library'][] = 'basic_cart/' . $css;
return $render;
}