[ 'component' => [ $skin['path'] => [ 'minified' => TRUE, ], ], ], 'dependencies' => [ 'core/jquery', ], ]; } return $libraries; } /** * Helper function to list available skins. */ function _audiofield_list_skins($player) { $skins = []; if ($player == 'jplayer_audio_player') { $files = file_scan_directory(DRUPAL_ROOT . '/libraries/jplayer/dist/skin/', '#.*\.min\.css#'); foreach ($files as $file) { // Generate a human readable name. $name = preg_replace("/^(jplayer\.)(.*)(\.min)/", '$2', $file->name); $skins[$name] = [ 'library_name' => 'audiofield.jplayer.theme_' . preg_replace('#[^A-Za-z0-9]#', '', $name), 'name' => $name, 'path' => str_replace(DRUPAL_ROOT, '', $file->uri), ]; } } ksort($skins); return $skins; } /** * Implements hook_theme(). */ function audiofield_theme($existing, $type, $theme, $path) { return [ 'audiofield_download_links' => [ 'variables' => [ 'links' => NULL, ], ], 'audioplayer' => [ 'variables' => [ 'plugin_id' => NULL, 'plugin_theme' => NULL, 'files' => NULL, 'settings' => NULL, ], ], ]; } /** * Implements hook_theme_suggestions_HOOK_alter(). */ function audiofield_theme_suggestions_audioplayer_alter(array &$suggestions, array $variables) { // Suggest a template using the plugin name. $suggestions[] = 'audioplayer__' . $variables['plugin_id']; // Suggest a template with the plugin/theme name if it exists. if (!empty($variables['plugin_theme'])) { $suggestions[] = 'audioplayer__' . $variables['plugin_id'] . '__' . $variables['plugin_theme']; } } /** * Implements hook_theme_registry_alter(). */ function audiofield_theme_registry_alter(&$theme_registry) { /* * By default, Drupal 8 does not include theme suggestions from inside the * module in which they were created, so we must add them manually here. */ $path = drupal_get_path('module', 'audiofield'); $audioplayer_templates = drupal_find_theme_templates($theme_registry, '.html.twig', $path); foreach ($audioplayer_templates as &$audioplayer_template) { $audioplayer_template['type'] = 'module'; } $theme_registry += $audioplayer_templates; } /** * Implements hook_help(). */ function audiofield_help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.audiofield': $output = ''; $output .= '
' . t('AudioField is a file formatter for the File and Link modules. It allows you to upload or link audio files and play them on your site using one of several audio players available. It supports most audio formats (depends on the selected audio player). Please see the module documentation for examples of the players in use.', [':url' => 'https://www.drupal.org/docs/8/modules/audiofield']) . '
'; $output .= '' . t('Audiofield supports the following audio players, which must be downloaded and installed as libraries:') . '
'; $output .= '