You are here

public function ImceFM::buildPage in IMCE 8

Same name and namespace in other branches
  1. 8.2 src/ImceFM.php \Drupal\imce\ImceFM::buildPage()

Builds file manager page.

1 call to ImceFM::buildPage()
ImceFM::buildRenderPage in src/ImceFM.php
Builds and renders the file manager page.

File

src/ImceFM.php, line 640

Class

ImceFM
Imce File Manager.

Namespace

Drupal\imce

Code

public function buildPage() {
  $page = [];
  $page['#attached']['library'][] = 'imce/drupal.imce';

  // Add meta for robots.
  $robots = [
    '#tag' => 'meta',
    '#attributes' => [
      'name' => 'robots',
      'content' => 'noindex,nofollow',
    ],
  ];
  $page['#attached']['html_head'][] = [
    $robots,
    'robots',
  ];

  // Disable cache.
  $page['#cache']['max-age'] = 0;

  // Run builders of available plugins.
  \Drupal::service('plugin.manager.imce.plugin')
    ->buildPage($page, $this);

  // Add active path to the conf.
  $conf = $this->conf;
  if (!isset($conf['active_path'])) {
    if ($folder = $this->activeFolder) {
      $conf['active_path'] = $folder
        ->getPath();
    }
    elseif ($this->request) {

      // Check $_GET['init_path'].
      if (($path = $this->request->query
        ->get('init_path')) && $this
        ->checkFolder($path)) {
        $conf['active_path'] = $path;
      }
      elseif ($this->user
        ->isAuthenticated() && ($path = $this->request
        ->getSession()
        ->get('imce_active_path'))) {
        if ($this
          ->checkFolder($path)) {
          $conf['active_path'] = $path;
        }
      }
    }
  }

  // Set initial messages.
  if ($messages = $this
    ->getMessages()) {
    $conf['messages'] = $messages;
  }
  $page['#attached']['drupalSettings']['imce'] = $conf;
  return $page;
}