annotate core/modules/image/image.install @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 /**
Chris@0 4 * @file
Chris@0 5 * Install, update and uninstall functions for the image module.
Chris@0 6 */
Chris@0 7
Chris@18 8 use Drupal\Core\File\Exception\FileException;
Chris@18 9 use Drupal\Core\File\FileSystemInterface;
Chris@18 10
Chris@0 11 /**
Chris@0 12 * Implements hook_install().
Chris@0 13 */
Chris@0 14 function image_install() {
Chris@0 15 // Create the styles directory and ensure it's writable.
Chris@0 16 $directory = file_default_scheme() . '://styles';
Chris@18 17 \Drupal::service('file_system')->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
Chris@0 18 }
Chris@0 19
Chris@0 20 /**
Chris@0 21 * Implements hook_uninstall().
Chris@0 22 */
Chris@0 23 function image_uninstall() {
Chris@0 24 // Remove the styles directory and generated images.
Chris@18 25 /** @var \Drupal\Core\File\FileSystemInterface $file_system */
Chris@18 26 $file_system = \Drupal::service('file_system');
Chris@18 27 try {
Chris@18 28 $file_system->deleteRecursive(file_default_scheme() . '://styles');
Chris@18 29 }
Chris@18 30 catch (FileException $e) {
Chris@18 31 // Ignore failed deletes.
Chris@18 32 }
Chris@0 33 }
Chris@0 34
Chris@0 35 /**
Chris@0 36 * Implements hook_requirements() to check the PHP GD Library.
Chris@0 37 *
Chris@0 38 * @param $phase
Chris@0 39 */
Chris@0 40 function image_requirements($phase) {
Chris@0 41 if ($phase != 'runtime') {
Chris@0 42 return [];
Chris@0 43 }
Chris@0 44
Chris@0 45 $toolkit = \Drupal::service('image.toolkit.manager')->getDefaultToolkit();
Chris@0 46 if ($toolkit) {
Chris@0 47 $plugin_definition = $toolkit->getPluginDefinition();
Chris@0 48 $requirements = [
Chris@0 49 'image.toolkit' => [
Chris@0 50 'title' => t('Image toolkit'),
Chris@0 51 'value' => $toolkit->getPluginId(),
Chris@0 52 'description' => $plugin_definition['title'],
Chris@0 53 ],
Chris@0 54 ];
Chris@0 55
Chris@0 56 foreach ($toolkit->getRequirements() as $key => $requirement) {
Chris@0 57 $namespaced_key = 'image.toolkit.' . $toolkit->getPluginId() . '.' . $key;
Chris@0 58 $requirements[$namespaced_key] = $requirement;
Chris@0 59 }
Chris@0 60 }
Chris@0 61 else {
Chris@0 62 $requirements = [
Chris@0 63 'image.toolkit' => [
Chris@0 64 'title' => t('Image toolkit'),
Chris@0 65 'value' => t('None'),
Chris@0 66 '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."),
Chris@0 67 'severity' => REQUIREMENT_ERROR,
Chris@0 68 ],
Chris@0 69 ];
Chris@0 70 }
Chris@0 71
Chris@0 72 return $requirements;
Chris@0 73 }
Chris@0 74
Chris@0 75 /**
Chris@0 76 * Flush caches as we changed field formatter metadata.
Chris@0 77 */
Chris@0 78 function image_update_8201() {
Chris@0 79 // Empty update to trigger a cache flush.
Chris@17 80
Chris@17 81 // Use hook_post_update_NAME() instead to clear the cache. The use of
Chris@17 82 // hook_update_N() to clear the cache has been deprecated see
Chris@17 83 // https://www.drupal.org/node/2960601 for more details.
Chris@0 84 }