You are here

public function DirectoryListBuilder::render in Private files download permission 3.x

Same name and namespace in other branches
  1. 8.2 src/DirectoryListBuilder.php \Drupal\pfdp\DirectoryListBuilder::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/DirectoryListBuilder.php, line 22

Class

DirectoryListBuilder
Defines a class to build a list of Private files download permission directory entities.

Namespace

Drupal\pfdp

Code

public function render() {
  $settings = \Drupal::config('pfdp.settings');

  // Prepare the information render array.
  $information = [];
  $information['margin'] = [
    '#markup' => '<p />',
  ];

  // Check if the file system download method is set to private.
  if ('private' !== \Drupal::config('system.file')
    ->get('default_scheme')) {
    \Drupal::messenger()
      ->addWarning($this
      ->t('Your @default_download_method is not set to private. Please keep in mind that these settings only affect private file system downloads.', [
      '@default_download_method' => Link::fromTextAndUrl('default download method', Url::fromRoute('system.file_system_settings'))
        ->toString(),
    ]));
  }

  // Check the private file system path.
  $private_file_system_path = Settings::get('file_private_path');
  if (!$private_file_system_path) {
    \Drupal::messenger()
      ->addWarning($this
      ->t('Your private file system path is not set.'));
  }
  else {
    $information['private_file_system_path'] = [
      '#markup' => '<p>' . $this
        ->t('Your private file system path is set to %path.', [
        '%path' => $private_file_system_path,
      ]) . '</p>',
    ];
  }

  // Check if by-user checks are enabled.
  if (!$settings
    ->get('by_user_checks')) {
    $information['by_user_checks'] = [
      '#markup' => '<p>' . $this
        ->t('@by_user_checks are not enabled.', [
        '@by_user_checks' => Link::fromTextAndUrl('By-user checks', Url::fromRoute('pfdp.settings'))
          ->toString(),
      ]) . '</p>',
    ];
  }

  // Return the render array.
  return $information + parent::render();
}