Problem/Motivation
I first noticed this at #3039026-8: Deprecate file_directory_temp() and move to FileSystem service
The docs in core/lib/Drupal/Core/Extension/module.api.php
are seriously weird for hook_install()
and hook_uninstall()
function hook_install() {
// Create the styles directory and ensure it's writable.
$directory = file_default_scheme() . '://styles';
\Drupal::service('file_system')->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
}
...
function hook_uninstall() {
// Remove the styles directory and generated images.
\Drupal::service('file_system')->deleteRecursive(file_default_scheme() . '://styles');
}
A) It's too bad all these examples are using file-related methods that are in the process of being deprecated and killed. ;)
B) What if the site admin changes their default file scheme between when this hypothetical module was installed and uninstalled? :/ Maybe on uninstall we recursively delete an entirely wrong directory(!). Ugh.
Proposed resolution
I don't really care what we replace this with, but I think we need to remove these confusing and frankly dangerous examples.
Remaining tasks
- Come up with more reasonable examples for hook_install() and hook_uninstall().
- Write the patch.
- Reviews/nitpicks/bikeshed
- RTBC
- Commit
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
N/A