image.install 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the image module.
  5. */
  6. /**
  7. * Implements hook_install().
  8. */
  9. function image_install() {
  10. // Create the styles directory and ensure it's writable.
  11. $directory = file_default_scheme() . '://styles';
  12. file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
  13. }
  14. /**
  15. * Implements hook_uninstall().
  16. */
  17. function image_uninstall() {
  18. // Remove the styles directory and generated images.
  19. file_unmanaged_delete_recursive(file_default_scheme() . '://styles');
  20. }
  21. /**
  22. * Implements hook_requirements() to check the PHP GD Library.
  23. *
  24. * @param $phase
  25. */
  26. function image_requirements($phase) {
  27. if ($phase != 'runtime') {
  28. return [];
  29. }
  30. $toolkit = \Drupal::service('image.toolkit.manager')->getDefaultToolkit();
  31. if ($toolkit) {
  32. $plugin_definition = $toolkit->getPluginDefinition();
  33. $requirements = [
  34. 'image.toolkit' => [
  35. 'title' => t('Image toolkit'),
  36. 'value' => $toolkit->getPluginId(),
  37. 'description' => $plugin_definition['title'],
  38. ],
  39. ];
  40. foreach ($toolkit->getRequirements() as $key => $requirement) {
  41. $namespaced_key = 'image.toolkit.' . $toolkit->getPluginId() . '.' . $key;
  42. $requirements[$namespaced_key] = $requirement;
  43. }
  44. }
  45. else {
  46. $requirements = [
  47. 'image.toolkit' => [
  48. 'title' => t('Image toolkit'),
  49. 'value' => t('None'),
  50. 'description' => t("No image toolkit is configured on the site. Check PHP installed extensions or add a contributed toolkit that doesn't require a PHP extension. Make sure that at least one valid image toolkit is enabled."),
  51. 'severity' => REQUIREMENT_ERROR,
  52. ],
  53. ];
  54. }
  55. return $requirements;
  56. }
  57. /**
  58. * Flush caches as we changed field formatter metadata.
  59. */
  60. function image_update_8201() {
  61. // Empty update to trigger a cache flush.
  62. }