"First Steps in Code Driven Development" covers basic techniques and good practices. Presented during the "Developer Session" at Krimson office, Antwerp (BE), the 27th of May 2010.
4. Major pitfalls
• Not ideal for a distributed team
• Makes difficult to push settings to production
• Content and settings are mixed in one db dump
• Easy to lose control
12. Hook helpers are then called from within your feature’s hooks.
/**
* Implementation of hook_content_default_fields().
*/
function atrium_blog_content_default_fields() {
module_load_include('inc', 'atrium_blog', 'atrium_blog.defaults');
$args = func_get_args();
return call_user_func_array('_atrium_blog_content_default_fields', $args);
}
/**
* Implementation of hook_views_default_views().
*/
function atrium_views_default_views() {
module_load_include('inc', 'atrium', 'atrium.features.views');
$args = func_get_args();
return call_user_func_array('_atrium_views_default_views', $args);
}
34. Tip:
Never share fields across several content types unless
you have really good reasons to do so.
If you do so you will make your features hardly re-usable.
37. Create Menus
/**
* Implementation of hook_install()
*/
function feature_controller_install() {
db_query("INSERT INTO {menu_custom} (menu_name, title, description)
VALUES ('%s', '%s', '%s')",
'menu-content',
'Content',
'Manage your site content.');
}
38. Create Menu Items
/**
* Implementation of hook_install()
*/
function feature_controller_install() {
$item['link_title'] = t('Home');
$item['link_path'] = '<front>';
$item['menu_name'] = 'primary-links';
$item['weight'] = -10;
menu_link_save($item);
}
39. Do all kind of dirty things...
/**
* Implementation of hook_install()
*/
function feature_controller_install() {
// Add OpenID to admin user
db_query("INSERT INTO {authmap} (uid, authname, module)
VALUES(1, 'http://nuvole.myopenid.com/', 'openid')");
// Weight feature_controller to come after other modules -- in particular, admin.
db_query("UPDATE {system}
SET weight = 1
WHERE name = 'feature_controller' AND type = 'module'");
}