日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Drupal 自己定义主题实体 Theming Custom Entities

發布時間:2025/3/15 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Drupal 自己定义主题实体 Theming Custom Entities 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在自己定義主題中輸出結果時,有三個部分或很多其它特殊的函數。如 hook_menu,Page Callback。MODULE_theme 鉤子

1、hook_menu

為了使用自己定義的實體。像創建、編輯、刪除、查看實體的功能,就必須要創建一些 Menu path。這里創建、編輯、刪除是與Drupal's Form API相關的,通過hook_menu,能夠定義我們須要的路徑來訪問這個新創建的實體內容

function my_module_menu() {$items['my_entity/%my_entity'] = array('title callback' ? => 'my_entity_page_title','title arguments' ?=> array(1),'page callback' ? ?=> 'my_entity_page_view','page arguments' ? => array(1),'access arguments' => array('view entities'),'type' ? ? ? ? ? ? => MENU_CALLBACK,);return $items;}

2、Page Callback

在上面的樣例中。我們在訪問這個路徑時,定義了 page callback 相應的?my_entity_page_view 函數,因此,接下來就須要創建這個函數,例如以下

/*** This is the callback we defined to be executed when a user* requests http://mysite.com/my_entity/1 (1 is just an example ID,* it could be anything). This function will set up the data and* prepare the render array(s). You will specify the template to* use in this callback. The critical thing to note below is the* order in which field_attach_prepare_view, entity_prepare_view* and field_attach_view are called. These functions must be called* in this order and they must be called before you specify which* theme to use.*/function my_entity_page_view($entity, $view_mode='full') {$entity_type = $entity->entityType();$entity_id = entity_id($entity_type, $entity);//// Remove previously built content, if exists//$entity->content = array();$entity->title = filter_xss($entity->title);//// Build the fields content//field_attach_prepare_view($entity_type, array($entity_id => $entity), $view_mode);entity_prepare_view($entity_type, array($entity_id => $entity));$entity->content += field_attach_view($entity_type, $entity, $view_mode);// Specify the theme to use and set the #element. Note that the key// you use to pass the entity object must match the key you set in the// variables in my_module_theme(). So in the case below, we use the key// named #element because in my_module_theme() we set the following code://// array(// ? 'my_entity' => array(// ? ? 'variables' => array('element' => null),// ? ? 'template' => 'my_entity'// ? ),// );//$entity->content += array('#theme' ? ? => $entity_type,'#element' ? => $entity,'#view_mode' => $view_mode,'#language' ?=> LANGUAGE_NONE,);return $entity->content;}

3、MODULE_theme() Hook

到眼下為止,為了這個實體我們已經定義了菜單項還有CALL BACK返回值,接下來。剩下的就須要創建一個指向模板的文件。看上面部分內容,能夠看到內容為:

$entity->content += array('#theme' => 'my_entity'); 意思是說。指向?my_entity?,那么,應該怎樣定義呢? function my_module_theme($existing, $type, $theme, $path) {return array('my_entity' => array('variables' => array('element' => null),'template' => 'my_entity_template'),);}

4、依據第三部分的內容。我們則須要創建名為?my_entity_template.tpl.php 的模板文件

[php// In a real module variables should be manipulated in a preprocess function.$content = $element->content;] <div class="[php print $classes; ]"> [php print render($content['title']); ] [php print render($content['field_date']); ][php print render($content['field_author']);][php print render($content['field_image']);] [php print render($content['field_description']);]

原文鏈接:https://drupal.org/node/1238606

轉載于:https://www.cnblogs.com/blfbuaa/p/7080092.html

總結

以上是生活随笔為你收集整理的Drupal 自己定义主题实体 Theming Custom Entities的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。