audiofield.install in AudioField 8
Same filename and directory in other branches
Installation file for Audiofield module.
File
audiofield.installView source
<?php
/**
* @file
* Installation file for Audiofield module.
*/
use Drupal\Core\Link;
use Drupal\Core\Url;
/**
* Implements hook_requirements().
*/
function audiofield_requirements($phase) {
$requirements = [];
if ($phase == 'runtime') {
$requirements['audiofield'] = [
'title' => t('AudioField Players'),
'severity' => REQUIREMENT_INFO,
'value' => '',
'description' => [
'installed' => [
'#theme' => 'item_list',
'#items' => [],
'#title' => '',
'#list_type' => 'ul',
'#attributes' => [],
],
'outdated' => [
'#theme' => 'item_list',
'#items' => [],
'#title' => '',
'#list_type' => 'ul',
'#attributes' => [],
],
'uninstalled' => [
'#theme' => 'item_list',
'#items' => [],
'#title' => '',
'#list_type' => 'ul',
'#attributes' => [],
],
],
];
// Loop over each plugin and make sure it's library is installed.
foreach (\Drupal::service('plugin.manager.audiofield')
->getDefinitions() as $pluginName => $plugin) {
// Create an instance of this plugin.
$pluginInstance = \Drupal::service('plugin.manager.audiofield')
->createInstance($pluginName);
// Only check install if there is a library for the plugin.
if ($pluginInstance
->getPluginLibrary()) {
// Check if the plugin is installed.
if (!$pluginInstance
->checkInstalled()) {
// Show a warning here as something is not installed.
$requirements['audiofield']['description']['uninstalled']['#prefix'] = t('Unavailable players');
// Try to print the install directory (will fail if the library itself
// is broken somehow).
try {
$requirements['audiofield']['description']['uninstalled']['#items'][] = t(':library_name library has not been installed. Download from <a href=":url">:url</a> and install in %library', [
':library_name' => $pluginInstance
->getPluginTitle(),
':url' => $pluginInstance
->getPluginRemoteSource(),
'%library' => $pluginInstance
->getPluginLibraryPath(),
]);
} catch (Exception $e) {
$requirements['audiofield']['description']['uninstalled']['#items'][] = t(':library_name library has not been installed. Download and install in %library', [
':library_name' => $pluginInstance
->getPluginTitFle(),
'%library' => $pluginInstance
->getPluginLibraryPath(),
]);
}
}
elseif (!$pluginInstance
->checkVersion(FALSE)) {
$requirements['audiofield']['description']['outdated']['#prefix'] = t('Out of Date players');
$requirements['audiofield']['description']['outdated']['#items'][] = t(':library_name library (version @version) is installed at %library, but is out of date. Please update to the latest version available at @url, or by running %command', [
':library_name' => $pluginInstance
->getPluginTitle(),
'%library' => $pluginInstance
->getPluginLibraryPath(),
'@version' => $pluginInstance
->getPluginLibraryVersion(),
'@url' => Link::fromTextAndUrl($pluginInstance
->getPluginRemoteSource(), Url::fromUri($pluginInstance
->getPluginRemoteSource()))
->toString(),
'%command' => 'drush audiofield-update',
]);
}
else {
$requirements['audiofield']['description']['installed']['#prefix'] = t('Available players');
$requirements['audiofield']['description']['installed']['#items'][] = t(':library_name library (version @version) has been successfully installed at %library', [
':library_name' => $pluginInstance
->getPluginTitle(),
'@version' => $pluginInstance
->getPluginLibraryVersion(),
'%library' => $pluginInstance
->getPluginLibraryPath(),
]);
}
}
}
// Check if the audiowaveform command is installed for use with wavesurfer.
$requirements['audiowaveform'] = [
'title' => t('Audiowaveform'),
'severity' => REQUIREMENT_INFO,
'value' => '',
'description' => t('Audiowaveform is not currently installed or the PHP function shell_exec is unavailable on this server. Audiowaveform is used to pre-render waveform files for the Audiofield Wavesurfer module. See @audiowaveformlink', [
'@audiowaveformlink' => Link::fromTextAndUrl(t('the Audiowaveform installation instructions'), Url::fromUri('https://github.com/bbc/audiowaveform'))
->toString(),
]),
];
if (audiofield_check_audiowaveform_installed()) {
$requirements['audiowaveform']['description'] = t('@version is installed.', [
'@version' => shell_exec('audiowaveform -v'),
]);
$requirements['audiowaveform']['severity'] = REQUIREMENT_OK;
}
}
return $requirements;
}
Functions
Name | Description |
---|---|
audiofield_requirements | Implements hook_requirements(). |