Drupal - How do I override a function from a module?

It's Drupal...there's always a way, but the amount of time it will take to do might make you think twice :)

If you look a bit further up the food chain so-to-speak you'll see that this function is exclusively used by commerce_price_table_field_formatter_view(), which declares a field formatter that is used for the commerce_price_table field type.

With that in mind, you can quite easily implement your own field formatter, assign it to the commerce_price_table field type, and use as much custom code as you want, all the time keeping in line with best practices.

Basically you need to implement hook_field_formatter_info():

function MYMODULE_field_formatter_info() {
  return array(
    'MYMODULE_commerce_multiprice_default' => array(
      'label' => t('MyModule Price chart'),
      'field types' => array('commerce_price_table'),
      'settings' => array(
        'calculation' => FALSE,
        'price_label' => t('Price'),
        'quantity_label' => t('Quantity'),
        'table_orientation' => t('Orientation'),
      ),
    ),
  );
}

And then implement hook_field_formatter_view(), field_formatter_settings_form() and (optionally) hook_field_formatter_summary().

For each of these functions just take the code from the same function in the contrib module, and make the changes where you need to.


Seems, you can’t override this function because it doesn’t use theme or hook workflow.

The only way - is to directly change commerce_price_table_display_quantity_headers() function. Then create a patch with you changes.

Later if you update the Commerce module - you will need apply your patch.

Tags:

7

Commerce