public function AutologoutWarningBlock::build in Automated Logout 8
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/ AutologoutWarningBlock.php, line 131
Class
- AutologoutWarningBlock
- Provides an 'Automated Logout info' block.
Namespace
Drupal\autologout\Plugin\BlockCode
public function build() {
$autologout_manager = $this->manager;
if ($autologout_manager
->preventJs()) {
// Don't display the block if the user is not going
// to be logged out on this page.
return [];
}
if ($autologout_manager
->refreshOnly()) {
$markup = $this
->t('Autologout does not apply on the current page,
you will be kept logged in whilst this page remains open.');
}
elseif ($this->moduleHandler
->moduleExists('jstimer') && $this->moduleHandler
->moduleExists('jst_timer')) {
return $this->builder
->getForm('Drupal\\autologout\\Form\\AutologoutBlockForm');
}
else {
$timeout = (int) $autologout_manager
->getUserTimeout();
$markup = $this
->t('You will be logged out in @time if this page is not refreshed before then.', [
'@time' => $this->dateFormatter
->formatInterval($timeout),
]);
}
return [
'#type' => 'markup',
'#markup' => $markup,
];
}