In classloader.info, weight = -1000 has no effet.

In the install file, we need to update it by a request.

CommentFileSizeAuthor
#9 classloader-weight-1929278-9.patch762 bytesEric_A
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Eric_A’s picture

Yes, using an insert query in an implementation of hook_install() certainly will have more effect.
For bootstrap modules that depend on Class Loader, the weight is important. Normal modules are not effected by this issue.

Somewhat related: #1869778: Class not found at menu object load time.

Sylvain Lecoy’s picture

Here is the snippet:
(sorry no patch)

<?php

/**
 * Implements hook_install().
 */
function classloader_install() {
  db_update('system')
    ->fields(array('weight' => -1000))
    ->condition('type', 'module')
    ->condition('name', 'classloader')
    ->execute();
}

?>
Sylvain Lecoy’s picture

Status: Active » Needs review
Eric_A’s picture

Status: Needs review » Needs work

If the module is already installed the weight needs to be fixed with an update function.

Sylvain Lecoy’s picture

Status: Needs work » Needs review

/**
 * Implements hook_install().
 */
function classloader_install() {
  db_update('system')
    ->fields(array('weight' => -1000))
    ->condition('type', 'module')
    ->condition('name', 'classloader')
    ->execute();
}

/**
 * Updates the module weight.
 */
function classloader_update_7000() {
  db_update('system')
    ->fields(array('weight' => -1000))
    ->condition('type', 'module')
    ->condition('name', 'classloader')
    ->execute();
}

don't be silly :)

Eric_A’s picture

Status: Needs review » Needs work

Much better! :-)

Though 7000 is the wrong hook_update_N() number here, since 70xx is reserved for initial porting to a new Drupal core API.
A 71xx number would be correct.

sun’s picture

Any chance to see a proper patch? :)

I don't really care too much for the module update number, since this module most likely won't see any other module update. But for the sake of completeness, @Eric_A is right with his interpretation of the module update numbering scheme. In the end, all module updates are ran and applied sequentially though, so the most important aspect is that we're counting up ;)

Sylvain Lecoy’s picture

Status: Needs work » Needs review

Ok:

<?php
/**
 * @file
 * Contains install, update and uninstall functions for the classloader module.
 */

/**
 * Implements hook_install().
 */
function classloader_install() {
  db_update('system')
    ->fields(array('weight' => -1000))
    ->condition('type', 'module')
    ->condition('name', 'classloader')
    ->execute();
}

/**
 * Updates the module weight.
 */
function classloader_update_7100() {
  db_update('system')
    ->fields(array('weight' => -1000))
    ->condition('type', 'module')
    ->condition('name', 'classloader')
    ->execute();
}

Eric_A’s picture

Attached is a straight copy and paste based patch (from #8).

EDIT: Note that there already is a classloader_install() function, which is not taken into account by the above snippets.

Existing code has direct calls to classloader_install() in order to activate the class loader and register all namespaces of enabled modules. Now that we're going to set the weight in there, we should create a helper function and call that. (Or replace every call with calls to drupal_classloader() and classloader_init().)

/**
 * Updates the module weight.
 */
function classloader_update_7100() {

The documentation block preceding this function is stripped of newlines and used as the description for the update on the pending updates task list. Core uses a different style for this:

/**
 * Update the module weight.
 */
Sylvain Lecoy’s picture

Status: Needs review » Reviewed & tested by the community

I'm ok with this, thanks for making a patch :)