public function AdministerContentTypes::build in Total Control Admin Dashboard 8.2
Same name and namespace in other branches
- 3.0.x src/Plugin/Block/AdministerContentTypes.php \Drupal\total_control\Plugin\Block\AdministerContentTypes::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/ AdministerContentTypes.php, line 137
Class
- AdministerContentTypes
- Provides a 'Administer Content Types'.
Namespace
Drupal\total_control\Plugin\BlockCode
public function build() {
if (!$this->moduleHandler
->moduleExists('field_ui')) {
$markup_data = $this
->t('You have to enable') . ' <strong>' . $this
->t('Field UI') . '</strong> ' . $this
->t('module to see this block.');
return [
'#type' => 'markup',
'#markup' => $markup_data,
];
}
$types = $this->entityTypeManager
->getStorage('node_type')
->loadMultiple();
$access = $this->currentUser
->hasPermission('administer content types');
$config = $this
->getConfiguration();
$header = [
[
'data' => $this
->t('Content type'),
],
[
'data' => $this
->t('Operations'),
'colspan' => 3,
],
];
$destination = $this->redirectDestination
->getAsArray();
$options = [
$destination,
];
$rows = [];
foreach ($types as $type => $object) {
// Config data says to include the type.
if (!array_key_exists($type, $config['total_control_admin_types']) || (isset($config['total_control_admin_types']) && $config['total_control_admin_types'][$type]) == $type) {
// Check access, then add a link to create content.
if ($access) {
$rows[] = [
'data' => [
$object
->get('name'),
Link::fromTextAndUrl($this
->t('Configure'), new Url('field_ui.field_storage_config_add_node', [
'node_type' => $object
->get('type'),
'options' => $options,
]))
->toString(),
Link::fromTextAndUrl($this
->t('Manage fields'), new Url('entity.node.field_ui_fields', [
'node_type' => $object
->get('type'),
'options' => $options,
]))
->toString(),
Link::fromTextAndUrl($this
->t('Manage display'), new Url('entity.entity_view_display.node.default', [
'node_type' => $object
->get('type'),
'options' => $options,
]))
->toString(),
],
];
}
}
}
if (empty($rows)) {
$rows[] = [
[
'data' => $this
->t('There are no content types to display.'),
'colspan' => 4,
],
];
}
$link = NULL;
if ($this->currentUser
->hasPermission('administer content types')) {
$link = Link::fromTextAndUrl($this
->t('Content type administration'), new Url('entity.node_type.collection'));
}
$body_data = [
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
];
$markup_data = $this->renderer
->render($body_data);
if ($link instanceof RenderableInterface) {
$markup_data .= $link
->toString();
}
return [
'#type' => 'markup',
'#markup' => $markup_data,
];
}