In the docs for the line item type definition (http://www.drupalcommerce.org/specification/info-hooks/line-item) states this:

base - string used as the base for the magically constructed callback names, each of which will be defaulted to [base]_[callback] unless explicitly set; defaults to the type

But it doesn't seem to be implemented, I'm attaching a patch for this one.

Comments

pcambra’s picture

Status: Needs review » Active
pcambra’s picture

Status: Active » Needs review

Repo: git.drupal.org:sandbox/pcambra/1081200.git
Branch: 1112900
Diff: http://drupalcode.org/sandbox/pcambra/1081200.git/commitdiff/d3b8d8b5da5...

rszrama’s picture

Status: Active » Closed (works as designed)

It's used in initialization when the line item types are loaded, so the patch should be unnecessary. Was this not working for you somewhere?

See commerce_line_item_types():

      // Merge in default callbacks.
      foreach (array('configuration', 'title', 'add_form', 'add_form_submit') as $callback) {
        if (!isset($line_item_type['callbacks'][$callback])) {
          $line_item_type['callbacks'][$callback] = $line_item_type['base'] . '_' . $callback;
        }
      }
pcambra’s picture

If you enable a module that has a custom line item type defined, I think it goes through hook_modules_enabled and in line item module this function has this code:

/**
 * Implements hook_modules_enabled().
 */
function commerce_line_item_modules_enabled($modules) {
  // Loop through all the enabled modules.
  foreach ($modules as $module) {
    // If the module implements hook_commerce_line_item_type_info()...
    if (module_hook($module, 'commerce_line_item_type_info')) {
      $line_item_types = module_invoke($module, 'commerce_line_item_type_info');

      // Loop through and configure the line item types defined by the module.
      foreach ($line_item_types as $line_item_type) {
        commerce_line_item_configure_line_item_type($line_item_type);
      }
    }
  }
}

There's no call to commerce_line_item_types there so the base and callback are not merged. Maybe we could do an array_merge of $line_item_types and commerce_line_item_types() before calling the configure in the hook.

pcambra’s picture

Status: Closed (works as designed) » Active

Back to active

rszrama’s picture

Title: Callback for line items does not fallback to base » Rebuild line item cache when a line item type module is enabled prior to configuration

Ahh, indeed, that's a problem. : )

I think perhaps instead we should reset the line item type cache, use commerce_line_item_types() to retrieve the array, and then use the configuration callback from there. By clearing the cache and rebuilding the line item types, we give other modules an appropriate opportunity to alter the configuration callback if required before the configuration actually happens.

pcambra’s picture

Status: Active » Needs review

Something like this?
http://drupalcode.org/sandbox/pcambra/1081200.git/commitdiff/f0793c5d751...

Then we're rebuilding all line items whenever a module is enabled.

rszrama’s picture

Status: Needs review » Needs work

Not quite like that. We still only want to configure the newly enabled line item type, we just want to do the reset so the callbacks array for that particular line item type is populated and altered if necessary.

pcambra’s picture

Status: Needs work » Needs review
rszrama’s picture

Status: Needs review » Fixed

Closer. : ) I just committed a patch that takes it the next step and just doesn't bother with the merge... I just invoke the hook to find out the types to load and configure directly.

Commit: http://drupalcode.org/project/commerce.git/blobdiff/2b021129aee0a49bcb53...

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.