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

Dries Buytaert
committed
* Implements hook_install().
*/
function image_install(): void {
// Create the styles directory and ensure it's writable.

Lee Rowlands
committed
$directory = \Drupal::config('system.file')->get('default_scheme') . '://styles';
\Drupal::service('file_system')->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
}
/**

Dries Buytaert
committed
* Implements hook_uninstall().
*/
function image_uninstall(): void {
// Remove the styles directory and generated images.
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = \Drupal::service('file_system');
try {

Lee Rowlands
committed
$file_system->deleteRecursive(\Drupal::config('system.file')->get('default_scheme') . '://styles');
}
catch (FileException) {
// Ignore failed deletes.
}
}

Dries Buytaert
committed
/**
* Implements hook_requirements().

Dries Buytaert
committed
*/
function image_requirements($phase) {

Alex Pott
committed
if ($phase != 'runtime') {
return [];

Alex Pott
committed
}

Dries Buytaert
committed

Alex Pott
committed
$toolkit = \Drupal::service('image.toolkit.manager')->getDefaultToolkit();
if ($toolkit) {
$plugin_definition = $toolkit->getPluginDefinition();
$requirements = [
'image.toolkit' => [

Alex Pott
committed
'title' => t('Image toolkit'),
'value' => $toolkit->getPluginId(),
'description' => $plugin_definition['title'],
],
];

Dries Buytaert
committed

Alex Pott
committed
foreach ($toolkit->getRequirements() as $key => $requirement) {
$namespaced_key = 'image.toolkit.' . $toolkit->getPluginId() . '.' . $key;
$requirements[$namespaced_key] = $requirement;

Dries Buytaert
committed
}

Alex Pott
committed
}
else {
$requirements = [
'image.toolkit' => [

Alex Pott
committed
'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 installed."),

Dries Buytaert
committed
'severity' => REQUIREMENT_ERROR,
],
];

Dries Buytaert
committed
}
return $requirements;
}
/**
* Implements hook_update_last_removed().
*/
function image_update_last_removed(): int {
return 8201;