'@name.install', 'hooks' => array( 'enable', 'disable', // 'requirements', // @todo Breaks update_help(). 05/06/2009 sun ), ), array( 'target' => '@name.registry.inc', 'header' => 'Registry-type hooks for @title module.', 'hooks' => array( 'system_info_alter', 'menu', 'menu_alter', 'menu_link_alter', 'theme', 'theme_registry_alter', 'flush_caches', 'elements', 'node_info', 'fieldable_info', 'field_build_modes', 'field_info', 'field_formatter_info', 'field_widget_info', 'hook_info', 'action_info[^(]*', 'aggregator_fetch_info', 'aggregator_parse_info', 'aggregator_process_info', 'modules_[^(]*', ), 'reorder' => TRUE, ), array( 'target' => '@name.actions.inc', 'header' => 'Action hooks for @title module.', 'hooks' => array( '[^(]*action[^(]*', ), ), array( 'target' => '@name.mail.inc', 'header' => 'Mail hooks for @title module.', 'hooks' => array( 'mail', 'mail_alter', ), ), array( 'target' => '@name.user.inc', 'header' => 'User hooks for @title module.', 'hooks' => array( 'perm', 'user_after_update', 'user_cancel', 'user_categories', 'user_form', 'user_login', 'user_logout', 'user_insert', 'user_operations[^(]*', 'user_register', 'user_submit', 'user_update', 'user_timezone', // This is not a hook, system.module only. 05/06/2009 sun 'user_validate', ), ), array( 'target' => '@name.block.inc', 'header' => 'Block hooks for @title module.', 'hooks' => array( 'block_list', 'block_configure', 'block_save', ), 'reorder' => TRUE, ), array( 'target' => '@name.node.inc', 'header' => 'Node hooks for @title module.', 'hooks' => array( 'node_access_records', 'node_delete', 'node_delete_revision', 'node_insert', 'node_operations', 'node_prepare', 'node_prepare_translation', 'node_presave', 'node_type', 'node_update', 'node_update_index', 'node_validate', ), ), array( 'target' => '@name.comment.inc', 'header' => 'Comment hooks for @title module.', 'hooks' => array( 'comment_delete', 'comment_insert', 'comment_publish', 'comment_unpublish', 'comment_update', 'comment_validate', // No CRUD function. // 'comment_view', ), ), array( 'target' => '@name.taxonomy.inc', 'header' => 'Taxonomy hooks for @title module.', 'hooks' => array( 'taxonomy', // @todo Lonely left over. 'taxonomy_term_delete', 'taxonomy_term_insert', 'taxonomy_term_update', 'taxonomy_vocabulary_delete', 'taxonomy_vocabulary_insert', 'taxonomy_vocabulary_update', ), ), array( 'target' => '@name.search.inc', 'header' => 'Search hooks for @title module.', 'hooks' => array( 'node_update_index', 'ranking', 'search', 'search_preprocess', 'search_page', // 'update_index', // @todo Breaks SearchAdvancedSearchForm test. 05/06/2009 sun ), ), array( 'target' => '@name.cron.inc', 'header' => 'Cron functionality for @title module.', 'hooks' => array( 'cron', ), ), array( 'target' => '@name.xmlrpc.inc', 'header' => 'XML-RPC hooks for @title module.', 'hooks' => array( 'xmlrpc', // Blog API XML-RPC callbacks. 'blogger_[^(]*', 'metaweblog_[^(]*', 'mt_[^(]*', ), ), array( 'target' => '@name.form.inc', 'header' => 'Form alter hooks for specific forms for @title module.', 'hooks' => array( 'form_[^(]*_alter', ), ), // Loaded on all pages (@see Advanced Help in core). 05/06/2009 sun // @todo Also breaks search_view() 05/06/2009 sun /* array( 'target' => '@name.help.inc', 'header' => 'Help for @title module.', 'hooks' => array( 'help', ), ), */ array( 'target' => '@name.watchdog.inc', 'header' => 'Watchdog functionality for @title module.', 'hooks' => array( 'watchdog', ), ), array( 'target' => '@name.field_storage.inc', 'header' => 'Field storage hooks for @title module.', 'hooks' => array( 'field_storage_create_field', 'field_storage_delete_field', 'field_storage_write', 'field_storage_delete', 'field_storage_delete_revision', 'field_storage_delete_instance', 'field_storage_rename_bundle', ), ), array( 'target' => '@name.field.inc', 'header' => 'Field hooks for @title module.', 'hooks' => array( 'field_schema', 'field_validate', // 'field_sanitize', // @todo registry. 05/06/2009 sun // 'field_is_empty', // @todo registry. 05/06/2009 sun 'content_is_empty', 'field_widget', 'field_widget_error', ), ), array( 'target' => '@name.file.inc', 'header' => 'File hooks for @title module.', 'hooks' => array( 'image_toolkits', 'file_copy', 'file_delete', 'file_download', 'file_insert', 'file_move', 'file_references', 'file_update', 'file_validate', ), ), array( 'target' => '@name.aggregator.inc', 'header' => 'Aggregator hooks for @title module.', 'hooks' => array( 'aggregator_fetch', 'aggregator_parse', 'aggregator_process', 'aggregator_remove', ), ), ); /** * @} End of "defgroup all_modules". */ /** * @defgroup core_modules Core modules. * @{ */ $config['@^(block)\.module$@'] = array( array( 'target' => '@name.block.inc', 'hooks' => array('box_get', 'box_form', 'box_save'), ), array( 'target' => '@name.form.inc', 'hooks' => array('system_themes_form_submit'), ), ); $config['@^(blog)\.module$@'] = array( array( 'target' => '@name.node.inc', 'hooks' => array('form', 'view'), ), ); $config['@^(blogapi)\.module$@'] = array( array( 'target' => '@name.admin.inc', 'hooks' => array('admin_settings'), ), ); $config['@^(color)\.module$@'] = array( array( 'target' => '@name.form.inc', 'hooks' => array('scheme_form[^(]*'), ), ); $config['@^(comment)\.module$@'] = array( array( 'target' => '@name.form.inc', 'hooks' => array('form', 'form_validate', 'validate', 'form_add_preview', 'form_submit'), 'reorder' => TRUE, ), ); $config['@^(number|options|text)\.module$@'] = array( array( 'target' => '@name.field.inc', 'hooks' => array('[^(]*process', '[^(]*validate'), ), ); $config['@^(filter)\.module$@'] = array( array( 'target' => '@name.admin.inc', 'hooks' => array('admin_format_title'), ), /* array( 'target' => '@name.form.inc', 'hooks' => array('filter_tips'), ), */ ); $config['@^(forum)\.module$@'] = array( array( 'target' => '@name.node.inc', 'hooks' => array('form', 'view'), ), ); $config['@^(menu)\.module$@'] = array( array( 'target' => '@name.form.inc', 'hooks' => array('node_form_submit'), ), ); $config['@^(node)\.module$@'] = array( array( 'target' => '@name.pages.inc', 'hooks' => array('page_default'), ), array( 'target' => '@name.form.inc', 'hooks' => array('search_validate', 'content_form'), ), ); $config['@^(openid)\.module$@'] = array( array( 'target' => '@name.form.inc', 'hooks' => array('login_validate'), ), ); $config['@^(path)\.module$@'] = array( array( 'target' => '@name.admin.inc', 'hooks' => array('admin_delete'), ), ); $config['@^(poll)\.module$@'] = array( array( 'target' => '@name.form.inc', 'hooks' => array('view_voting', 'view_voting_validate', 'vote', 'cancel_form', 'cancel'), ), array( 'target' => '@name.node.inc', 'hooks' => array('form', 'view', 'more_choices_submit', 'node_form_submit', 'validate', 'node_prepare_translation', 'insert', 'update', 'delete'), ), ); $config['@^(profile)\.module$@'] = array( array( 'target' => '@name.user.inc', 'hooks' => array('form_profile', 'validate_profile', 'save_profile', 'categories'), 'reorder' => TRUE, ), ); $config['@^(search)\.module$@'] = array( array( 'target' => '@name.form.inc', 'hooks' => array('form'), ), ); $config['@^(system)\.module$@'] = array( array( 'target' => '@name.form.inc', 'hooks' => array('settings_form_submit'), ), ); $config['@^(taxonomy)\.module$@'] = array( array( 'target' => '@name.admin.inc', 'hooks' => array('admin_vocabulary_title_callback'), ), array( 'target' => '@name.node.inc', 'hooks' => array('node_save'), ), ); $config['@^(upload)\.module$@'] = array( array( 'target' => '@name.form.inc', 'hooks' => array('node_form_submit'), ), array( 'target' => '@name.pages.inc', 'hooks' => array('js'), ), ); $config['@^(user)\.module$@'] = array( array( 'target' => '@name.form.inc', // @todo 'edit_form' required by user_user_form() in user.user.inc. 05/06/2009 sun 'hooks' => array('login', 'login_name_validate', 'login_authenticate_validate', 'login_final_validate', 'login_submit', 'login_block', 'register', 'register_validate', 'register_submit'), 'reorder' => TRUE, ), array( 'target' => '@name.user.inc', 'hooks' => array('multiple_role_edit', 'multiple_cancel_confirm', 'multiple_cancel_confirm_submit'), ), ); /** * @} End of "defgroup core_modules". */ /* -------------------------------------------------------------------------- */ /** * Script application. */ foreach ($config as $source => $targets) { $files = file_scan_directory('.', $source); foreach ($files as $file) { $module = preg_replace($source, '$1', $file->filename); // Skip error_test.module due to hard-coded line numbers for expected // exceptions. if ($module == 'error_test') { continue; } // Fetch the source file content. $content = file_get_contents($file->filepath); foreach ($targets as $rewrite) { $newfile = (object) array( 'filepath' => dirname($file->filepath) . '/' . strtr($rewrite['target'], array('@name' => $module)), 'filename' => strtr($rewrite['target'], array('@name' => $module)), ); // Retrieve code to move. $remove = array(); if (empty($rewrite['reorder'])) { $rewrite['hooks'] = array(implode('|', $rewrite['hooks'])); } foreach ($rewrite['hooks'] as $hook) { // Dunno why, but this only matches 1 function. Who cares, while() helps. 21/05/2009 sun $s = '@ (?:^/\*\*(?:(?!\*\*).)+?\*/\s+)? # Optional PHPDoc ^function\ ' . $module . '_(?:' . $hook . ')\(.*?\) # Function name + arguments (?:(?!^\}).)+? # Function body ^\} # Closing function body \s+ # White-space to next function @smx'; while (preg_match($s, $content, $matches) && !empty($matches[0])) { $remove[] = $matches[0]; $content = str_replace($matches[0], '', $content); } } // Continue to next rewrite target if there's nothing to rewrite. if (empty($remove)) { continue; } echo "$file->filepath => $newfile->filepath\n"; // Write new target file. $newcontent = ''; if (file_exists($newfile->filepath)) { $flags = FILE_APPEND; } else { $flags = 0; $header = ' ucfirst($module))); $newcontent = strtr($header, array('@summary' => $summary)); } $newcontent .= implode('', $remove); file_put_contents($newfile->filepath, $newcontent, $flags); // Remove code from source file. file_put_contents($file->filepath, $content); // Add target file to .info file. $infofile = dirname($file->filepath) . '/' . $module . '.info'; if (file_exists($infofile)) { $info_content = file_get_contents($infofile); if (strpos($info_content, $newfile->filename) === FALSE) { file_put_contents($infofile, 'files[] = ' . $newfile->filename . "\n", FILE_APPEND); } } // Add target file to CVS. $CVS = dirname($file->filepath) . '/CVS/Entries'; if (file_exists($CVS)) { $CVS_content = file_get_contents($CVS); if (strpos($CVS_content, $newfile->filename) === FALSE) { file_put_contents($CVS, '/' . $newfile->filename . "/0/Initial import.//\n", FILE_APPEND); } } } } }