Download & Extend

Hook to define new buildmodes

Project:Build modes
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

It'd be useful to also have a hook for defining new buildmodules, which would make it easier to wrap them in Features.

Comments

#1

Status:active» needs review

How does this work?

AttachmentSize
buildmodes-n1058262.patch 2.3 KB

#2

Status:needs review» fixed

The hook originates in CCK. hook_content_build_modes() which us not well documented in CCK, but you can pick it up by seeing how CCK implements it on behalf of core modules.

http://drupalcontrib.org/api/drupal/contributions--cck--content.module/f...

#3

Status:fixed» needs review

While I could use hook_content_build_modes() to do the initial work, and it's simple to do, to replicate all of BuildModes' functionality increases the amount of custom code required for maintenance.

#4

So you want to be able to alter the build modes?

#5

The main goal is to be able to add build modes to the system list from a module and have the additional theming functionality, the drupal_alter() is more a convention to always allow data structures to be altered when loaded from a "default" hook. Having a single short hook to the module to do this means less custom module code, and an easier maintenance path per site.

#6

We have a hook to define new build modes. I don't understand how hook_content_build_mode is not sufficient.

/**
* Implementations of hook_content_build_modes
*/
function eipackages_content_build_modes() {
  return array(
    'eipackages' => array(
      'title' => t('Packages'),
      'build modes' => array(
        'package_basic' => array(
          'title' => t('Basic package'),
          'views style' => TRUE,
        ),
        'poster' => array(
          'title' => t('Poster'),
          'views style' => TRUE,
        ),
      ),
    ),
  );
}

/**
* Implementation of hook_content_build_modes().
*/
function alshabaka_core_content_build_modes() {
  return array(
    'alshabaka' => array(
      'title' => t('Al-Shabaka'),
      'build modes' => array(
        'promo_teaser' => array(
          'title' => t('Promo teaser'),
          'views style' => TRUE,
        ),
      ),
    ),
  );
}

How is another hook more work than the current hook?

#7

Using the patch I provided above removes the need to add additional preprocess functions to replicate the functionality provided by BuildModes, thus less custom code.

#8

Can you share an example of a preprocess function this patch makes unnecessary? I'm sorry for being thick. The only thing I see this patch doing is allowing the custom build modes created through the UI to be altered.

#9

Using hook_content_build_modes() doesn't automatically give me the templating options provided by buildmodes_preprocess_content_field(), buildmodes_preprocess_node() or the code from buildmodes_node_view(), so I'd have to duplicate them. And, like I said previously, I'd rather not increase the amount of custom code when this it's already sitting in buildmodes.

#10

buildmodes_node_view() is not a hook implementation, and it's provided as a convenience for use in your own modules. The example usage is provided in buildmodes.pages.inc. There's no way to rewrite Drupal to use this node view function instead of core without substituting a lot of menu callbacks. The suggested method is to use Views to display nodes with different build modes.

buildmodes_preprocess_content_field() will fail to make template suggestions in versions of CCK earlier than 2.9 because CCK didn't use a template preprocess function and implemented content_preprocess_content_field() instead. See #728472: Misnamed preprocessor functions.

The buildmodes_preprocess_node() template suggestions work as-is when I implement hook_content_build_modes().