audiofield.install 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * @file
  4. * Installation file for Audiofield module.
  5. */
  6. use Drupal\Core\Link;
  7. use Drupal\Core\Url;
  8. /**
  9. * Implements hook_requirements().
  10. */
  11. function audiofield_requirements($phase) {
  12. $requirements = [];
  13. if ($phase == 'runtime') {
  14. $requirements['audiofield'] = [
  15. 'title' => t('AudioField Players'),
  16. 'severity' => REQUIREMENT_INFO,
  17. 'value' => '',
  18. 'description' => [
  19. 'installed' => [
  20. '#theme' => 'item_list',
  21. '#items' => [],
  22. '#title' => '',
  23. '#list_type' => 'ul',
  24. '#attributes' => [],
  25. ],
  26. 'outdated' => [
  27. '#theme' => 'item_list',
  28. '#items' => [],
  29. '#title' => '',
  30. '#list_type' => 'ul',
  31. '#attributes' => [],
  32. ],
  33. 'uninstalled' => [
  34. '#theme' => 'item_list',
  35. '#items' => [],
  36. '#title' => '',
  37. '#list_type' => 'ul',
  38. '#attributes' => [],
  39. ],
  40. ],
  41. ];
  42. // Loop over each plugin and make sure it's library is installed.
  43. foreach (\Drupal::service('plugin.manager.audiofield')->getDefinitions() as $pluginName => $plugin) {
  44. // Create an instance of this plugin.
  45. $pluginInstance = \Drupal::service('plugin.manager.audiofield')->createInstance($pluginName);
  46. // Only check install if there is a library for the plugin.
  47. if ($pluginInstance->getPluginLibrary()) {
  48. // Check if the plugin is installed.
  49. if (!$pluginInstance->checkInstalled()) {
  50. // Show a warning here as something is not installed.
  51. $requirements['audiofield']['description']['uninstalled']['#prefix'] = t('Unavailable players');
  52. // Try to print the install directory (will fail if the library itself
  53. // is broken somehow).
  54. try {
  55. $requirements['audiofield']['description']['uninstalled']['#items'][] = t(':library_name library has not been installed. Download from <a href=":url">:url</a> and install in %library', [
  56. ':library_name' => $pluginInstance->getPluginTitle(),
  57. ':url' => $pluginInstance->getPluginRemoteSource(),
  58. '%library' => $pluginInstance->getPluginLibraryPath(),
  59. ]);
  60. }
  61. catch (Exception $e) {
  62. $requirements['audiofield']['description']['uninstalled']['#items'][] = t(':library_name library has not been installed. Download and install in %library', [
  63. ':library_name' => $pluginInstance->getPluginTitFle(),
  64. '%library' => $pluginInstance->getPluginLibraryPath(),
  65. ]);
  66. }
  67. }
  68. elseif (!$pluginInstance->checkVersion(FALSE)) {
  69. $requirements['audiofield']['description']['outdated']['#prefix'] = t('Out of Date players');
  70. $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', [
  71. ':library_name' => $pluginInstance->getPluginTitle(),
  72. '%library' => $pluginInstance->getPluginLibraryPath(),
  73. '@version' => $pluginInstance->getPluginLibraryVersion(),
  74. '@url' => Link::fromTextAndUrl($pluginInstance->getPluginRemoteSource(), Url::fromUri($pluginInstance->getPluginRemoteSource()))->toString(),
  75. '%command' => 'drush audiofield-update',
  76. ]);
  77. }
  78. else {
  79. $requirements['audiofield']['description']['installed']['#prefix'] = t('Available players');
  80. $requirements['audiofield']['description']['installed']['#items'][] = t(':library_name library (version @version) has been successfully installed at %library', [
  81. ':library_name' => $pluginInstance->getPluginTitle(),
  82. '@version' => $pluginInstance->getPluginLibraryVersion(),
  83. '%library' => $pluginInstance->getPluginLibraryPath(),
  84. ]);
  85. }
  86. }
  87. }
  88. }
  89. return $requirements;
  90. }