You are here

public function PoolListBuilder::render in CMS Content Sync 2.1.x

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

Class

PoolListBuilder
Provides a listing of Pool.

Namespace

Drupal\cms_content_sync\Controller

Code

public function render() {
  $build = parent::render();
  $overwritten = 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 pool.', [
      '@link' => $link,
    ]));
  }
  if (!empty($rows)) {
    foreach ($rows as $row) {
      if (strpos($row['backend_url']
        ->__toString(), 'Overwritten')) {
        $overwritten = true;
      }
    }
    if ($overwritten) {
      $build['explanation_overwritten'] = [
        '#markup' => '<i>' . $this
          ->t('Overwritten: This configuration has been overwritten within your settings.php file.') . '</i><br>',
      ];
    }
    $build['hints'] = [
      '#markup' => '<h3>' . $this
        ->t('Hints') . '</h3>' . $this
        ->t('You can overwrite parts of your pool configuration using your settings.php file:'),
    ];
    $overwrite_sync_core_url_example = '<li>' . $this
      ->t('Sync Core URL: <i>@overwrite_sync_core_url</i>', [
      '@overwrite_sync_core_url' => '$settings["cms_content_sync"]["pools"][<pool_machine_name>]["backend_url"] = "http://example.com";',
    ]) . '</li>';
    $build['hints_examples'] = [
      '#markup' => '<ul>' . $overwrite_sync_core_url_example . '</ul>',
    ];
  }
  return $build;
}