Jun 8, 2014

The .install script: hook_schema(), hook_install(), hook_enable(), etc.

Converting the optimizely.install script:

hook_schema() works as is under Drupal 8 without any changes.

hook_install() works as is except that the  st() function which is used within installation scripts has been removed in Drupal 8. The  t() function is used instead.

In D7 you could disable a module without uninstalling it, but with Drupal 8 you can only uninstall. The source articles below describe numerous problems that can happen when a module is disabled but not uninstalled, so this is changed for D8. A module is either installed or not installed.

Consequently, hook_enable() and hook_disable() have been removed. Functionality that was previously in hook_enable() may need to be moved to hook_install(). Functionality that was previously in hook_disable() may need to be moved to hook_uninstall().

Upon uninstalling, hook_uninstall() automatically removes tables defined in hook_schema() as in D7.

I removed the existing several implementations of  hook_update_N(), for the moment just creating optimizely_hook_8000(). The function only sets a status message since the schema is not changing during this conversion.


Sources:

Modules cannot be in a disabled state anymore, only installed and uninstalled
https://drupal.org/node/2193013

Disabled modules are broken beyond repair so the "disable" functionality needs to be removed
https://drupal.org/node/1199946

Removed st() and get_t(), just use t() in place, simple!
https://drupal.org/node/2021435


1 comment:

  1. Ekkk! hook_disable() is not supported and the module schema is removed with the only option of uninstalling. This means a user should not try different modules, invest in one, enter data/settings and then switch with the idea of possibly switching back.

    OK, good to know.

    ReplyDelete