image.install 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 array();
  29. }
  30. $toolkit = \Drupal::service('image.toolkit.manager')->getDefaultToolkit();
  31. if ($toolkit) {
  32. $plugin_definition = $toolkit->getPluginDefinition();
  33. $requirements = array(
  34. 'image.toolkit' => array(
  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 = array(
  47. 'image.toolkit' => array(
  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. }