Active
Project:
Build modes
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
18 Feb 2010 at 07:46 UTC
Updated:
19 Feb 2010 at 00:23 UTC
Getting some nice hints from your code.
One thing I noticed was that the code generates a template for the teaser & not the page view, as 0 doesn't pass the if (). It would make sense (to me) to ignore the system modes by adding an is_numeric() check here.
e.g. the main system modes
<?php
define('NODE_BUILD_NORMAL', 0);
define('NODE_BUILD_PREVIEW', 1);
define('NODE_BUILD_SEARCH_INDEX', 2);
define('NODE_BUILD_SEARCH_RESULT', 3);
define('NODE_BUILD_RSS', 4);
define('NODE_BUILD_PRINT', 5);
?>
Also to provide a generic build node template for the build, (eg: XML export / HTML 5 / etc) which is applicable to all content types. These two things combined are:
<?php
/**
* Preprocess function for template suggestions
*/
function buildmodes_preprocess_node(&$vars) {
if (isset($vars['build_mode']) && !is_numeric($vars['build_mode'])) {
$vars['template_files'][] = 'node-'. $vars['type'] .'-'. $vars['build_mode'];
$vars['template_files'][] = 'node-'. $vars['build_mode'];
}
}
# new validation, must start with a letter or underscore, better than saying it can not be numeric but it can have numbers.
# This then also means that you can also use the name as a PHP variable too.
# PS: I did not test the modification below
if (!preg_match('!^[a-z_]+[a-z0-9_]*$!', $name)) {
form_set_error('name', t('The machine-readable name must contain only lowercase letters, numbers, and underscores, and it can not start with a number.'));
}
?>
Comments
Comment #1
alan d. commentedUPDATE: Then again, providing template for every build mode does make sense. Maybe add a prefix if it is numeric so that these do not conflict with other "node-#" templates, "node-build-mode-#" for example. (Common trick to provide a template for a specific node uses the "node-#" pattern)
[Edit] The code that I ended up using was: