Loading…
Transcript

Drupal 7 Front-end Development

modules and themes have taught each other some tricks

Hooks work by naming convention.

To implement a hook, take the 'hook' part off the hook name and replace it with your module's (machine) name. Thus, hook_help() implemented in the Xray module is the function xray_help().

Presentation in a Module?

Heretic.

benjamin melançon

ben@agaric.com

dgd7.org • agaric.com

Welcome to the Weird

What Goes Where

Themes in Modules

Modules in Themes

Miscellaneous

Drupal 7 Theming

Awesomeness

Modules that Do Theming

Every hook that used to be restricted to modules and can now be done in themes can also still be used in modules.

New in Drupal 7 Themes

Advantages

drupal.org/update/themes/6/7#theme_alter

  • Theme override suggestions
  • Some hooks only work (reliably) from modules.
  • You can more easily share your modification between projects and people.

Community Karma needed to Punishment for Various Crimes

Disadvantages

  • You just got sucked deeper into the Drupal vortex.

How NOT to Do It

hook_form_alter()

  • Presentation and display go in a theme or dedicated theming modules.
  • Regions have templates

<plug class="shameless">

hook_css_alter()

  • Theme functions must begin with the theme name.

hook_html_head_alter()

dgd7.org

</plug>

  • Functionality and logic go in ordinary modules.

The End

agaric.com

dgd7.org

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

From Module to Theme to Module

hook_page_alter

Tip: grep

grep -nHR module_implements_alter .

./includes/module.inc:646: if ($hook != 'module_implements_alter') {

./modules/system/system.api.php:1775:function hook_module_implements_alter(&$implementations, $hook) {

Tip: Examples Project

Tip: Looking up hooks

We can look up hook definitions and their function signatures the same way we look up any Drupal function, at api.drupal.org:

api.drupal.org/hook_help

  • api.drupal.org
  • drupalcontrib.org