You are here

function yamlform_page_attachments in YAML Form 8

Implements hook_page_attachments().

File

./yamlform.module, line 254
Enables the creation of forms and questionnaires.

Code

function yamlform_page_attachments(&$page) {
  $route_name = Drupal::routeMatch()
    ->getRouteName();
  $url = Url::fromRoute('<current>')
    ->toString();

  // Attach global libraries.
  if (preg_match('/^(yamlform\\.|^entity\\.([^.]+\\.)?yamlform)/', $route_name) || preg_match('#(/node/add/yamlform|/admin/help/yamlform)#', $url)) {

    // Attach theme specific library to yamlform routers so that we can tweak
    // the seven.theme.
    $theme = \Drupal::theme()
      ->getActiveTheme()
      ->getName();
    if (file_exists(drupal_get_path('module', 'yamlform') . "/css/yamlform.theme.{$theme}.css")) {
      $page['#attached']['library'][] = "yamlform/yamlform.theme.{$theme}";
    }

    // Attach details element save open/close library.
    if (\Drupal::config('yamlform.settings')
      ->get('ui.details_save')) {
      $page['#attached']['library'][] = 'yamlform/yamlform.element.details.save';
    }
  }

  // Attach codemirror library to block admin to ensure that the library
  // is loaded by the form block is placed using AJAX.
  if (\Drupal::routeMatch()
    ->getRouteName() == 'block.admin_display') {
    $page['#attached']['library'][] = 'yamlform/yamlform.codemirror.yaml';
  }
}