You are here

public function FlowListBuilder::render in CMS Content Sync 2.0.x

Same name and namespace in other branches
  1. 8 src/Controller/FlowListBuilder.php \Drupal\cms_content_sync\Controller\FlowListBuilder::render()
  2. 2.1.x src/Controller/FlowListBuilder.php \Drupal\cms_content_sync\Controller\FlowListBuilder::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

File

src/Controller/FlowListBuilder.php, line 113

Class

FlowListBuilder
Provides a listing of Flow.

Namespace

Drupal\cms_content_sync\Controller

Code

public function render() {
  $build = parent::render();
  $status_overwritten = false;
  $version_mismatch = false;
  $rows = $build['table']['#rows'];

  // Check if the site has already been registered.
  $settings = ContentSyncSettings::getInstance();
  if (Migration::alwaysUseV2() && !$settings
    ->getSiteUuid()) {
    $link = Link::fromTextAndUrl($this
      ->t('registered'), Url::fromRoute('cms_content_sync.site'))
      ->toString();
    $this
      ->messenger()
      ->addWarning($this
      ->t('The site needs to be @link before creating a flow.', [
      '@link' => $link,
    ]));
  }
  if (!empty($rows)) {
    foreach ($rows as $row) {
      if (strpos($row['status']
        ->__toString(), 'Overwritten')) {
        $status_overwritten = true;
      }
      if (strpos($row['status']
        ->__toString(), 'Version mismatch')) {
        $version_mismatch = true;
      }
    }
    if ($status_overwritten) {
      $build['explanation_overwritten'] = [
        '#markup' => '<i>' . $this
          ->t('Overwritten: The status of this flow has been overwritten in a settings file.') . '</i><br>',
      ];
    }
    if ($version_mismatch) {
      $build['explanation_version_mismatch'] = [
        '#markup' => '<i>' . $this
          ->t('Version mismatch: The flow contains mismatching bundle versions and needs to be re-saved and exported.') . '</i>',
      ];
    }
    $build['hints'] = [
      '#markup' => '<h3>' . $this
        ->t('Hints') . '</h3>' . $this
        ->t('You can enable / disable Flows using your settings.php file:'),
    ];
    $overwrite_status = '<li>' . $this
      ->t('Status: <i>@overwrite_status</i>', [
      '@overwrite_status' => '$config["cms_content_sync.flow.<flow_machine_name>"]["status"] = FALSE;',
    ]) . '</li>';
    $build['hints_examples'] = [
      '#markup' => '<ul>' . $overwrite_status . '</ul>',
    ];
  }
  return $build;
}