You are here

function _ds_register_build_modes in Display Suite 6.3

Same name and namespace in other branches
  1. 6 includes/ds.registry.inc \_ds_register_build_modes()
  2. 6.2 includes/ds.registry.inc \_ds_register_build_modes()

Register build modes.

1 call to _ds_register_build_modes()
ds_get_build_modes in ./ds.module
Api function to return all build modes.

File

includes/ds.registry.inc, line 512
Registry functions.

Code

function _ds_register_build_modes() {
  $weight = 10;
  $build_modes = array();

  // Build modes defined in hooks.
  foreach (module_implements('content_build_modes') as $module) {
    $module_data = array();
    $function = $module . '_content_build_modes';
    $cck_grouped = call_user_func($function);

    // We need to do some fiddling existing build modes.
    if (!empty($cck_grouped)) {
      foreach ($cck_grouped as $group_key => $group) {

        // Sane build modes.
        foreach ($group['build modes'] as $build_mode_key => $build_mode) {

          // If no module key is set, we are adding it ourselves. This hook only applies
          // to nodes anyway, so yes, we use nd as the $module key.
          $module_name = isset($build_mode['module']) ? $build_mode['module'] : 'nd';
          $build_modes[$module_name][$build_mode_key] = array(
            'weight' => isset($build_mode['weight']) ? $build_mode['weight'] : $weight++,
            'title' => $build_mode['title'],
            'type' => 'code',
            'module' => $module,
            'group' => check_plain($group['title']),
            'overridden' => FALSE,
          );
        }
      }
    }
  }
  $code_modes = $build_modes;

  // Custom build modes via the UI.
  foreach (module_implements('ds_api') as $module) {
    $weight = 10;
    $db_build_modes = variable_get($module . '_build_modes', array());
    if (!empty($db_build_modes)) {
      foreach ($db_build_modes as $key => $name) {
        $build_modes[$module][$key] = array(
          'weight' => $weight++,
          'title' => check_plain($name),
          'build modes' => array(
            $key => array(
              'title' => check_plain($name),
            ),
          ),
          'type' => 'db',
          'module' => isset($code_modes[$module][$key]['module']) && $module != 'nd' ? $code_modes[$module][$key]['module'] : '',
          'group' => t('Custom'),
          'overridden' => isset($code_modes[$module][$key]) ? TRUE : FALSE,
        );
      }
    }
    asort($build_modes[$module]);
  }

  // Give modules a change to alter build_modes.
  drupal_alter('ds_buildmodes', $build_modes);

  // Cache all build modes.
  variable_set('ds_all_build_modes', $build_modes);
  return $build_modes;
}