image.install

Same filename in other branches
  1. 7.x modules/image/image.install
  2. 9 core/modules/image/image.install
  3. 10 core/modules/image/image.install
  4. 11.x core/modules/image/image.install

Install, update and uninstall functions for the image module.

File

core/modules/image/image.install

View source
<?php


/**
 * @file
 * Install, update and uninstall functions for the image module.
 */
use Drupal\Core\File\Exception\FileException;
use Drupal\Core\File\FileSystemInterface;

/**
 * Implements hook_install().
 */
function image_install() {
    // Create the styles directory and ensure it's writable.
    $directory = \Drupal::config('system.file')->get('default_scheme') . '://styles';
    \Drupal::service('file_system')->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
}

/**
 * Implements hook_uninstall().
 */
function image_uninstall() {
    // Remove the styles directory and generated images.
    
    /** @var \Drupal\Core\File\FileSystemInterface $file_system */
    $file_system = \Drupal::service('file_system');
    try {
        $file_system->deleteRecursive(\Drupal::config('system.file')->get('default_scheme') . '://styles');
    } catch (FileException $e) {
        // Ignore failed deletes.
    }
}

/**
 * Implements hook_requirements() to check the PHP GD Library.
 *
 * @param $phase
 */
function image_requirements($phase) {
    if ($phase != 'runtime') {
        return [];
    }
    $toolkit = \Drupal::service('image.toolkit.manager')->getDefaultToolkit();
    if ($toolkit) {
        $plugin_definition = $toolkit->getPluginDefinition();
        $requirements = [
            'image.toolkit' => [
                '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 = [
            'image.toolkit' => [
                '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;
}

/**
 * Flush caches as we changed field formatter metadata.
 */
function image_update_8201() {
    // Empty update to trigger a cache flush.
    // Use hook_post_update_NAME() instead to clear the cache. The use of
    // hook_update_N() to clear the cache has been deprecated see
    // https://www.drupal.org/node/2960601 for more details.
}

Functions

Title Deprecated Summary
image_install Implements hook_install().
image_requirements Implements hook_requirements() to check the PHP GD Library.
image_uninstall Implements hook_uninstall().
image_update_8201 Flush caches as we changed field formatter metadata.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.