summaryrefslogtreecommitdiffstats
path: root/core/modules/image/image.install
blob: fd14d038de9d613cf93616410f2c98b9d0b41d8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php

/**
 * @file
 * Install, update and uninstall functions for the image module.
 */

/**
 * Implements hook_install().
 */
function image_install() {
  // Create the styles directory and ensure it's writable.
  $directory = file_default_scheme() . '://styles';
  file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
}

/**
 * Implements hook_uninstall().
 */
function image_uninstall() {
  // Remove the styles directory and generated images.
  file_unmanaged_delete_recursive(file_default_scheme() . '://styles');
}

/**
 * Implements hook_requirements() to check the PHP GD Library.
 *
 * @param $phase
 */
function image_requirements($phase) {
  if ($phase != 'runtime') {
    return array();
  }

  $toolkit = \Drupal::service('image.toolkit.manager')->getDefaultToolkit();
  if ($toolkit) {
    $plugin_definition = $toolkit->getPluginDefinition();
    $requirements = array(
      'image.toolkit' => array(
        'title' => t('Image toolkit'),
        'value' => $toolkit->getPluginId(),
        'description' => $plugin_definition['title'],
      ),
    );

    foreach ($toolkit->getRequirements() as $key => $requirement) {
      $namespaced_key = 'image.toolkit.' . $toolkit->getPluginId() . '.' . $key;
      $requirements[$namespaced_key] = $requirement;
    }
  }
  else {
    $requirements = array(
      'image.toolkit' => array(
        'title' => t('Image toolkit'),
        'value' => t('None'),
        '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."),
        'severity' => REQUIREMENT_ERROR,
      ),
    );
  }

  return $requirements;
}