Commit 750930e8 authored by Ted Bowman's avatar Ted Bowman
Browse files

Issue #3244679 by tedbow, kunal.sachdev, rkoller: Should readiness checks be...

Issue #3244679 by tedbow, kunal.sachdev, rkoller: Should readiness checks be displayed on admin pages if cron updates are disabled?
parent 2d52693c
Loading
Loading
Loading
Loading
+21 −2
Changes for src/Validation/AdminReadinessMessages.php: 21 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,8 @@

namespace Drupal\automatic_updates\Validation;

use Drupal\automatic_updates\CronUpdater;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Messenger\MessengerTrait;
@@ -57,6 +59,13 @@ final class AdminReadinessMessages implements ContainerInjectionInterface {
   */
  protected $currentRouteMatch;

  /**
   * The config factory service.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $config;

  /**
   * Constructs a ReadinessRequirement object.
   *
@@ -72,14 +81,17 @@ final class AdminReadinessMessages implements ContainerInjectionInterface {
   *   The translation service.
   * @param \Drupal\Core\Routing\CurrentRouteMatch $current_route_match
   *   The current route match.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config
   *   The config factory service.
   */
  public function __construct(ReadinessValidationManager $readiness_checker_manager, MessengerInterface $messenger, AdminContext $admin_context, AccountProxyInterface $current_user, TranslationInterface $translation, CurrentRouteMatch $current_route_match) {
  public function __construct(ReadinessValidationManager $readiness_checker_manager, MessengerInterface $messenger, AdminContext $admin_context, AccountProxyInterface $current_user, TranslationInterface $translation, CurrentRouteMatch $current_route_match, ConfigFactoryInterface $config) {
    $this->readinessCheckerManager = $readiness_checker_manager;
    $this->setMessenger($messenger);
    $this->adminContext = $admin_context;
    $this->currentUser = $current_user;
    $this->setStringTranslation($translation);
    $this->currentRouteMatch = $current_route_match;
    $this->config = $config;
  }

  /**
@@ -92,7 +104,8 @@ final class AdminReadinessMessages implements ContainerInjectionInterface {
      $container->get('router.admin_context'),
      $container->get('current_user'),
      $container->get('string_translation'),
      $container->get('current_route_match')
      $container->get('current_route_match'),
      $container->get('config.factory')
    );
  }

@@ -127,6 +140,12 @@ final class AdminReadinessMessages implements ContainerInjectionInterface {
   *   Whether the messages should be displayed on the current page.
   */
  protected function displayResultsOnCurrentPage(): bool {
    // If updates will not run during cron then we don't need to show the
    // readiness checks on admin pages.
    if ($this->config->get('automatic_updates.settings')->get('cron') === CronUpdater::DISABLED) {
      return FALSE;
    }

    if ($this->adminContext->isAdminRoute() && $this->currentUser->hasPermission('administer site configuration')) {
      // These routes don't need additional nagging.
      $disabled_routes = [
+10 −0
Changes for tests/src/Functional/ReadinessValidationTest.php: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ use Drupal\automatic_updates\Event\ReadinessCheckEvent;
use Drupal\automatic_updates_test\Datetime\TestTime;
use Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1;
use Drupal\automatic_updates_test2\EventSubscriber\TestSubscriber2;
use Drupal\Core\Url;
use Drupal\system\SystemManager;
use Drupal\Tests\automatic_updates\Traits\ValidationTestTrait;
use Drupal\Tests\Traits\Core\CronRunTrait;
@@ -291,6 +292,15 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
    $assert->pageTextContainsOnce(static::$warningsExplanation);
    $assert->pageTextContainsOnce($expected_results[0]->getMessages()[0]);
    $assert->pageTextNotContains($expected_results[0]->getSummary());

    // Confirm readiness messages are not displayed when cron updates are
    // disabled.
    $this->drupalGet(Url::fromRoute('update.settings'));
    $edit['automatic_updates_cron'] = 'disable';
    $this->submitForm($edit, 'Save configuration');
    $this->drupalGet('admin/structure');
    $assert->pageTextNotContains(static::$warningsExplanation);
    $assert->pageTextNotContains($expected_results[0]->getMessages()[0]);
  }

  /**