سؤال

When writing a module, how can I perform an operation every time a node is viewed by a user?

هل كانت مفيدة؟

المحلول

You can use hook_nodeapi() in Drupal 6 and check that the $op argument is 'view'. In Drupal 7, this has been changed to hook_node_$op() where $op is replaced by the value you would have checked for in the Drupal 6 version. So you would use hook_node_view(). For more details about the changes from Drupal 6 to Drupal 7 see http://drupal.org/update/modules/6/7#remove_op.

نصائح أخرى

Alternatively you could use Drupals Trigger module which has a 'When content is viewed by an authenticated user' trigger by default.

You can create an Action through /admin/settings/actions, or write your own based on the information at http://drupal.org/documentation/modules/trigger. You will also find modules that have predefined triggers and actions.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى drupal.stackexchange
scroll top