tailieunhanh - Drupal 7 Module Development phần 7

Điều này là quan trọng bởi vì người dùng cá nhân có thể chỉ định một tuỳ chọn ngôn ngữ khác với ngôn ngữ mặc định của trang web. Chúng ta nên tôn trọng sự lựa chọn này nếu có thể khi gửi e-mail của chúng tôi cho người dùng này. | Chapter 8 if flood_is_allowed contact limit window user_access administer contact forms drupal_set_message t You cannot send more than limit messages in @interval. Please try again later. array limit limit @ interval format_interval window error drupal_access_denied drupal_exit The preceding code stops all processing of the contact form page if the user is suspected of spamming the form. If the user violates the threshold of allowed messages per hour a warning message is delivered and the Access denied page is rendered. Note the use of drupal_exit here to stop the rest of the page execution. Since this access denied message is performed during form definition drupal_exit must be invoked to stop the rest of the rendering process. Note Do not call the normal PHP exit function from within Drupal yA code. Doing so may stop the execution of internal functions such as x session handling or API hooks. The drupal_exit function is provided to safely stop the execution of a Drupal request. Within a normal page context however we should return the constant MENU_ACCESS_DENIED instead of drupal_exit . We might do this instead of using a custom menu callback. Returning to our earlier example Implement hook_menu . function example_menu items user user content array title Content creation page callback example_user_page page arguments array 1 access arguments array view content creation permissions type MENU_LOCAL_TASK return items Custom page callback for a user tab. 225 Drupal Permissions and Security function example_user_page account global user if user- uid account- uid return MENU_ACCESS_DENIED . There is a subtle yet important difference between the two approaches. If we use a menu callback to assert access control the tab link will only be rendered if the user passes the access check. If we use an access check within the page callback the tab will always be rendered. It is poor usability to present a tab that only prints an access denied message to the user. For this .

TỪ KHÓA LIÊN QUAN