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@0
|
8 /**
|
Chris@0
|
9 * Implements hook_install().
|
Chris@0
|
10 */
|
Chris@0
|
11 function image_install() {
|
Chris@0
|
12 // Create the styles directory and ensure it's writable.
|
Chris@0
|
13 $directory = file_default_scheme() . '://styles';
|
Chris@0
|
14 file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
|
Chris@0
|
15 }
|
Chris@0
|
16
|
Chris@0
|
17 /**
|
Chris@0
|
18 * Implements hook_uninstall().
|
Chris@0
|
19 */
|
Chris@0
|
20 function image_uninstall() {
|
Chris@0
|
21 // Remove the styles directory and generated images.
|
Chris@0
|
22 file_unmanaged_delete_recursive(file_default_scheme() . '://styles');
|
Chris@0
|
23 }
|
Chris@0
|
24
|
Chris@0
|
25 /**
|
Chris@0
|
26 * Implements hook_requirements() to check the PHP GD Library.
|
Chris@0
|
27 *
|
Chris@0
|
28 * @param $phase
|
Chris@0
|
29 */
|
Chris@0
|
30 function image_requirements($phase) {
|
Chris@0
|
31 if ($phase != 'runtime') {
|
Chris@0
|
32 return [];
|
Chris@0
|
33 }
|
Chris@0
|
34
|
Chris@0
|
35 $toolkit = \Drupal::service('image.toolkit.manager')->getDefaultToolkit();
|
Chris@0
|
36 if ($toolkit) {
|
Chris@0
|
37 $plugin_definition = $toolkit->getPluginDefinition();
|
Chris@0
|
38 $requirements = [
|
Chris@0
|
39 'image.toolkit' => [
|
Chris@0
|
40 'title' => t('Image toolkit'),
|
Chris@0
|
41 'value' => $toolkit->getPluginId(),
|
Chris@0
|
42 'description' => $plugin_definition['title'],
|
Chris@0
|
43 ],
|
Chris@0
|
44 ];
|
Chris@0
|
45
|
Chris@0
|
46 foreach ($toolkit->getRequirements() as $key => $requirement) {
|
Chris@0
|
47 $namespaced_key = 'image.toolkit.' . $toolkit->getPluginId() . '.' . $key;
|
Chris@0
|
48 $requirements[$namespaced_key] = $requirement;
|
Chris@0
|
49 }
|
Chris@0
|
50 }
|
Chris@0
|
51 else {
|
Chris@0
|
52 $requirements = [
|
Chris@0
|
53 'image.toolkit' => [
|
Chris@0
|
54 'title' => t('Image toolkit'),
|
Chris@0
|
55 'value' => t('None'),
|
Chris@0
|
56 '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
|
57 'severity' => REQUIREMENT_ERROR,
|
Chris@0
|
58 ],
|
Chris@0
|
59 ];
|
Chris@0
|
60 }
|
Chris@0
|
61
|
Chris@0
|
62 return $requirements;
|
Chris@0
|
63 }
|
Chris@0
|
64
|
Chris@0
|
65 /**
|
Chris@0
|
66 * Flush caches as we changed field formatter metadata.
|
Chris@0
|
67 */
|
Chris@0
|
68 function image_update_8201() {
|
Chris@0
|
69 // Empty update to trigger a cache flush.
|
Chris@4
|
70
|
Chris@4
|
71 // Use hook_post_update_NAME() instead to clear the cache. The use of
|
Chris@4
|
72 // hook_update_N() to clear the cache has been deprecated see
|
Chris@4
|
73 // https://www.drupal.org/node/2960601 for more details.
|
Chris@0
|
74 }
|