Skip to content

Commit

Permalink
Change block text when environment actions are paused
Browse files Browse the repository at this point in the history
  • Loading branch information
David Coote committed Feb 6, 2025
1 parent bb3d44a commit 0c9aa1f
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\shp_time_restrictions\ActionsLogService;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand All @@ -19,6 +20,8 @@
*/
class TimeRestrictionNotificationBlock extends BlockBase implements ContainerFactoryPluginInterface {

use StringTranslationTrait;

/**
* The config factory.
*
Expand Down Expand Up @@ -70,9 +73,20 @@ public static function create(ContainerInterface $container, array $configuratio
* {@inheritdoc}
*/
public function build() {
if ($this->nodeActionsLogService->isOutsideEnvironmentCreationTimeDelay()) {
// No need to generate block content.
return;
}

$time_delay = $this->configFactory->get('shp_time_restrictions.settings')->get('environment_creation_time_delay');
$last_action_time = $this->nodeActionsLogService->getLastActionTimestamp();

$text = $this->t('To prevent errors there is a delay between environment actions. The next action is allowed in @seconds seconds',
['@seconds' => $time_delay - (time() - $last_action_time)]);

$build['content'] = [
'#markup' => !($this->nodeActionsLogService->isOutsideEnvironmentCreationTimeDelay()) ?
'<div class="messages messages--warning">Environment actions are not permitted at this time</div>' : FALSE,
'#markup' =>
'<div class="messages messages--warning">' . $text . '</div>',
];
return $build;
}
Expand Down

0 comments on commit 0c9aa1f

Please sign in to comment.