public function WebformNodeReferencesListController::render in Webform 6.x
Same name and namespace in other branches
- 8.5 modules/webform_node/src/Controller/WebformNodeReferencesListController.php \Drupal\webform_node\Controller\WebformNodeReferencesListController::render()
Builds the entity listing as renderable array for table.html.twig.
@todo Add a link to add a new item to the #empty text.
Overrides EntityListBuilder::render
1 call to WebformNodeReferencesListController::render()
- WebformNodeReferencesListController::listing in modules/
webform_node/ src/ Controller/ WebformNodeReferencesListController.php - Provides the listing page for webform node references.
File
- modules/
webform_node/ src/ Controller/ WebformNodeReferencesListController.php, line 343
Class
- WebformNodeReferencesListController
- Defines a controller for webform node references.
Namespace
Drupal\webform_node\ControllerCode
public function render() {
$build = [];
$build['info'] = $this
->buildInfo();
$build += parent::render();
$build['table']['#sticky'] = TRUE;
// Customize the empty message.
$build['table']['#empty'] = $this
->t('There are no webform node references.');
// Must manually add local actions because we can't alter local actions and
// add query string parameter.
// @see https://www.drupal.org/node/2585169
$local_actions = [];
if ($this->webform
->hasVariants()) {
foreach ($this->nodeTypes as $bundle => $node_type) {
if ($node_type
->access('create')) {
$local_actions['webform_node.references.add_form'] = [
'#theme' => 'menu_local_action',
'#link' => [
'title' => $this
->t('Add reference'),
'url' => Url::fromRoute('entity.webform.references.add_form', [
'webform' => $this->webform
->id(),
]),
'attributes' => WebformDialogHelper::getModalDialogAttributes(WebformDialogHelper::DIALOG_NARROW),
],
];
WebformDialogHelper::attachLibraries($local_actions['webform_node.references.add_form']);
}
}
}
else {
foreach ($this->nodeTypes as $bundle => $node_type) {
if ($node_type
->access('create')) {
$local_actions['webform_node.references.add_' . $bundle] = [
'#theme' => 'menu_local_action',
'#link' => [
'title' => $this
->t('Add @title', [
'@title' => $node_type
->label(),
]),
'url' => Url::fromRoute('node.add', [
'node_type' => $bundle,
], [
'query' => [
'webform_id' => $this->webform
->id(),
],
]),
],
];
}
}
}
if ($local_actions) {
$build['local_actions'] = [
'#prefix' => '<ul class="action-links">',
'#suffix' => '</ul>',
'#weight' => -100,
] + $local_actions;
}
$build['#attached']['library'][] = 'webform_node/webform_node.references';
return $build;
}