You are here

function single_page_site_page_attachments in Single Page Site 8

Same name and namespace in other branches
  1. 2.x single_page_site.module \single_page_site_page_attachments()
  2. 2.0.x single_page_site.module \single_page_site_page_attachments()

Implements hook_page_attachments().

File

./single_page_site.module, line 36

Code

function single_page_site_page_attachments(array &$page) {
  $settings = \Drupal::config('single_page_site.config');
  if (!empty($settings)) {

    // Add JS to create anchors.
    $settings_js = array(
      'className' => !empty($settings
        ->get('class')) ? $settings
        ->get('class') : 'li',
      'menuClass' => $settings
        ->get('menuclass'),
      'isFrontpage' => $settings
        ->get('homepage'),
    );
    if (!$settings
      ->get('homepage')) {
      $settings_js['urlAlias'] = Url::fromRoute('single_page_site.page')
        ->toString();
    }
    $page['#attached']['drupalSettings']['singlePage'] = $settings_js;
    $page['#attached']['library'][] = 'single_page_site/single_page_site.menu';
  }
}