You are here

public function VersionWarning::showVersionWarning in CMS Content Sync 2.0.x

Same name and namespace in other branches
  1. 8 modules/cms_content_sync_developer/src/EventSubscriber/VersionWarning.php \Drupal\cms_content_sync_developer\EventSubscriber\VersionWarning::showVersionWarning()
  2. 2.1.x modules/cms_content_sync_developer/src/EventSubscriber/VersionWarning.php \Drupal\cms_content_sync_developer\EventSubscriber\VersionWarning::showVersionWarning()

Show version warning.

Parameters

\Symfony\Component\HttpKernel\Event\GetResponseEvent $event: The Event to process.

File

modules/cms_content_sync_developer/src/EventSubscriber/VersionWarning.php, line 64

Class

VersionWarning
A subscriber triggering a config when certain configuration changes.

Namespace

Drupal\cms_content_sync_developer\EventSubscriber

Code

public function showVersionWarning(GetResponseEvent $event) {
  $current_user = $this->current_user;
  if ($current_user
    ->hasPermission('administer cms content sync')) {
    $config = $this->config_factory;
    $messenger = $this->messenger;
    $developer_config = $config
      ->getEditable('cms_content_sync.developer');
    $version_mismatch = $developer_config
      ->get('version_mismatch');
    if (!empty($version_mismatch)) {
      $links = [];
      foreach ($version_mismatch as $flow_id => $flow) {
        $links[$flow_id] = Link::fromTextAndUrl($flow_id, Url::fromRoute('entity.cms_content_sync_flow.edit_form', [
          'cms_content_sync_flow' => $flow_id,
        ], [
          'absolute' => TRUE,
        ]))
          ->toString();
      }
      $mismatching_flow_labels = implode(',', $links);
      $message = new TranslatableMarkup("You have to update the related flow(s) @flows to keep the content synchronization intact. Failing to update the config may break the synchronization and lead to damaged or missing content.", [
        '@flows' => new FormattableMarkup($mismatching_flow_labels, []),
      ]);
      $messenger
        ->addWarning($message);
    }
  }
}