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

CHAPTER 15 WORKING WITH TAXONOMY

/**

* Implements hook_vocabulary_update() */

function taxonomymonitor_vocabulary_update($vocabulary) { _send_notification('vocabulary', 'updated', $vocabulary->name);

}

/**

* Implements hook_vocabulary_delete() */

function taxonomymonitor_vocabulary_delete($vocabulary) { _send_notification('vocabulary', 'deleted', $vocabulary->name);

}

/**

*Log changes to taxonomy using watchdog and send out an email notification

*describing the change

*/

function _send_notification($type, $action, $name) {

watchdog('Taxonomy Monitor', 'A @type named @name was @action', array('@type' => $type, '@name' => $name, '@action'=> $action))

$to = variable_get('site_mail','');

$subject = t("There was a change to taxonomy"); $body = t("A $type named $name was $action"); // Send email here.

}

For extra bonus points, you could modify the module to include the name of the user who made the change.

Common Tasks

Here are some common tasks you may encounter when working with taxonomies.

Displaying Taxonomy Terms Associated with a Node

Taxonomy terms in Drupal 7 are essentially just fields attached to the node. To get the value of the taxonomy terms you must first know a little bit about the content type associated with the node you are looking at, specifically the name of the field used to store the taxonomy terms. As an example, I’ll use an Article that I created and assigned tags to. After creating the node and capturing the node ID of the new node (in my example it was 2), I could display the taxonomy terms associated with this node using the following code snippet. I’ll paste the snippet into a new block, set the input format to PHP code, and assign the block to a region on my page.

354

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