Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Apress.Pro.Drupal.7.Development.3rd.Edition.Dec.2010.pdf
Скачиваний:
73
Добавлен:
14.03.2016
Размер:
12.64 Mб
Скачать

CHAPTER 3 HOOKS, ACTIONS, AND TRIGGERS

Figure 3-7. The newly defined trigger appears as a tab in the triggers user interface.

Adding Triggers to Existing Hooks

Sometimes, you may want to add triggers to an existing hook if your code is adding a new operation. For example, you might want to add a hook called hook_node_archive. Suppose you have written an archive module that takes old nodes and moves them to a data warehouse. You could define an entirely new hook for this, and that would be perfectly appropriate. But since this operation is on a node, you might want to fire hook_node_archive instead so that triggers on content all appear under the same tab in the triggers interface. Assuming you named your module “archive,” the following code would add the additional trigger:

/**

* Implementation of hook_trigger_info(). */

function archive_trigger_info() { return array(

'node' => array( 'archive_nodes' => array(

'label' => t('Archive old nodes'),

)

)

);

}

54

CHAPTER 3 HOOKS, ACTIONS, AND TRIGGERS

The new trigger is now available at the end of the list of triggers on the triggers administration page, as shown in Figure 3-8.

Figure 3-8. The additional trigger (“When the post is about to be archived”) appears in the user interface.

Summary

After reading this chapter, you should be able to

Understand how to assign actions to triggers.

Write a simple action.

Write an advanced action and its associated configuration form.

Create and rename instances of advanced actions using the actions administration page.

Understand what a context is.

Understand how actions can use the context to change their behavior.

Understand how actions are stored, retrieved, and executed.

Define your own hooks and have them displayed as triggers.

55

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]