You are here

function HOOK_library_info_build in AT Tools 8.3

Same name and namespace in other branches
  1. 8 at_theme_generator/starterkits/starterkit/THEMENAME.theme \HOOK_library_info_build()
  2. 8.2 at_theme_generator/starterkits/starterkit/STARTERKIT.theme \HOOK_library_info_build()

Add dynamic library definitions.

Modules may implement this hook to add dynamic library definitions. Static libraries, which do not depend on any runtime information, should be declared in a modulename.libraries.yml file instead.

Return value

array[] An array of library definitions to register, keyed by library ID. The library ID will be prefixed with the module name automatically.

See also

core.libraries.yml

hook_library_info_alter()

File

at_theme_generator/starterkits/starterkit/STARTERKIT.theme, line 20

Code

function HOOK_library_info_build() {
  $libraries = [];
  $theme = 'HOOK';
  $theme_registry = \Drupal::service('theme.registry')
    ->get();
  $config = \Drupal::config($theme . '.settings')
    ->get('settings');

  // Layout libraries.
  $libraries[$theme . '.layout.page'] = [
    'css' => [
      'layout' => [
        'styles/css/generated/' . $theme . '.layout.page.css' => [],
      ],
    ],
  ];
  foreach ($theme_registry as $key => $values) {
    if (substr($key, 0, 6) == 'page__') {
      $suggestion = str_replace('_', '-', $key);
      $libraries[$theme . '.layout.' . $key] = [
        'css' => [
          'layout' => [
            'styles/css/generated/' . $theme . '.layout.' . $suggestion . '.css' => [],
          ],
        ],
      ];
    }
  }

  // Extension libraries.
  if (isset($config['enable_extensions']) && $config['enable_extensions'] === 1) {

    // Fonts.
    if (isset($config['enable_fonts']) && $config['enable_fonts'] === 1) {

      // Google fonts.
      if (!empty($config['font_google'])) {
        $libraries['google_fonts'] = [
          'remote' => 'https://fonts.google.com',
          'license' => [
            'name' => 'SIL (OFL)',
            'url' => 'http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=OFL',
            'gpl-compatible' => TRUE,
          ],
          'css' => [
            'base' => [
              Xss::filter($config['font_google']) => [],
            ],
          ],
          'weight' => -1000,
        ];
      }

      // Typekit.
      if (!empty($config['font_typekit'])) {
        $libraries['typekit_id'] = [
          'remote' => '//use.typekit.net/',
          'license' => [
            'name' => 'Apache 2.0',
            'url' => 'http://www.apache.org/licenses/LICENSE-2.0',
            'gpl-compatible' => TRUE,
          ],
          'js' => [
            '//use.typekit.net/' . Html::escape($config['font_typekit']) . '.js' => [
              'type' => 'external',
            ],
          ],
          'header' => TRUE,
        ];
      }
    }
  }
  return $libraries;
}