image.install 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. // Use hook_post_update_NAME() instead to clear the cache. The use of
  63. // hook_update_N() to clear the cache has been deprecated see
  64. // https://www.drupal.org/node/2960601 for more details.
  65. }