Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 301029

Fix hook_uninstall() example in core/lib/Drupal/Core/Extension/module.api.php

$
0
0

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

  1. Come up with more reasonable examples for hook_install() and hook_uninstall().
  2. Write the patch.
  3. Reviews/nitpicks/bikeshed
  4. RTBC
  5. Commit

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

N/A


Viewing all articles
Browse latest Browse all 301029

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>