public function VarbaseCreateContent::build in Varbase Total Control Dashboard 9.0.x
Same name and namespace in other branches
- 8.6 src/Plugin/Block/VarbaseCreateContent.php \Drupal\varbase_total_control\Plugin\Block\VarbaseCreateContent::build()
- 8 src/Plugin/Block/VarbaseCreateContent.php \Drupal\varbase_total_control\Plugin\Block\VarbaseCreateContent::build()
- 8.5 src/Plugin/Block/VarbaseCreateContent.php \Drupal\varbase_total_control\Plugin\Block\VarbaseCreateContent::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/ VarbaseCreateContent.php, line 114
Class
- VarbaseCreateContent
- Provides a 'Create content'.
Namespace
Drupal\varbase_total_control\Plugin\BlockCode
public function build() {
$types = array_reverse($this->entityTypeManager
->getStorage('node_type')
->loadMultiple());
$links = [];
$config = $this
->getConfiguration();
$destination = $this->redirectDestination
->getAsArray();
$options = [
$destination,
];
foreach ($types as $type => $object) {
// Check against pane config for type.
if (!array_key_exists($type, $config['total_control_admin_types_links']) || (isset($config['total_control_admin_types_links']) && $config['total_control_admin_types_links'][$type]) == $type) {
// Check access, then add a link to create content.
if ($this->currentUser
->hasPermission('create ' . $object
->get('type') . ' content')) {
$link_options = [
'attributes' => [
'class' => [
Html::cleanCssIdentifier(mb_strtolower($object
->get('type'))),
],
],
];
$url = new Url('node.add', [
'node_type' => $object
->get('type'),
], $options);
$url
->setOptions($link_options);
$links[] = Link::fromTextAndUrl($object
->get('name'), $url);
}
}
}
$links[] = Link::fromTextAndUrl($this
->t('More...'), new Url('node.add_page', $options));
$body_data = [
'#theme' => 'item_list',
'#list_type' => 'ul',
'#items' => $links,
];
$markup_data = $this->renderer
->render($body_data);
return [
'#type' => 'markup',
'#markup' => $markup_data,
];
}