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
Drupal 自定义主题实体 Theming Custom Entities相关推荐
- Drupal 自己定义主题实体 Theming Custom Entities
在自己定义主题中输出结果时,有三个部分或很多其它特殊的函数.如 hook_menu,Page Callback.MODULE_theme 钩子 1.hook_menu 为了使用自己定义的实体.像创建. ...
- 如何在Angular Material中制作自定义主题
by Charlee Li 通过李李 如何在Angular Material中制作自定义主题 (How to make a custom theme in Angular Material) Angu ...
- VS Code 安装插件、自定义模板、自定义配置参数、自定义主题、配置参数说明、常用的扩展插件
1. 下载和官网教程 下载地址:https://code.visualstudio.com/ 官方教程:https://code.visualstudio.com/docs 2. 安装插件 安装扩展插 ...
- ExtJS4.2:自定义主题 入门
背景 用过 ExtJs 的朋友都有一种趋势:审美疲劳,好在 Ext4.1 之后的版本提供了快速自定义主题的功能,本文的内容主要来自:http://docs.sencha.com/extjs/4.2.2 ...
- Drupal 7 主题模板概述
Drupal是一个开源的内容管理系统(CMS) 平台,它是用PHP写成的.主要用于构造提供多种功能和服务的动态网站,这些功能包括用户管理(UserAdministration).发布工作流 (Publ ...
- Dev-cpp自定义主题:
Dev-cpp自定义主题 1.在安装目录...\config\下新建文本文件,重命名为CustomTheme.syntax: 2.打开CustomTheme.syntax,复制以下内容并保存: [Ed ...
- Drupal 6 主题制作指南
译者:老葛, http://www.thinkindrupal.com/theme-guide-drupal-6 原文:http://drupal.org/theme-guide 欢迎来到主题制作的用 ...
- 彰显个性│博客园的自定义主题
目录预览 一.开放的博客园 二.主题推荐 三.自定义主题配置CSS 四.自定义主题配置JS 五.页面加载loading 六.页面看板 七.动态背景 八.标签动效 一.开放的博客园 在国内,开源社区有很 ...
- zsh安装与自定义主题
zsh安装与自定义主题 Zsh(Z-shell)是一款用于交互式使用的shell,也可以作为脚本解释器来使用.其包含了 bash, ksh,tcsh 等其他shell中许多优秀功能,也拥有诸多 ...
最新文章
- struts2 标签中read-only=true 和disabled的区别
- labview生成HTML报表,LabVIEW201
- 皮尔逊相关系数的计算(python代码版)
- R语言:预测算法常用包总结
- Bit-Z 关于交易隐藏及下线说明
- Codeforces Round #547 (Div. 3)
- python中的tkinter_基于python中tkinter的计算机实现
- linux 主机的网络属性基本配置:
- java json传值到前台_json前后台传值
- crop video in ffmpeg
- FMEA失效模式和影响分析
- 【番外篇】波动率的几种模型
- spring-AOP 增强接口Introductions
- Windows超级管理器 8.72 这一刻,刻不容缓。
- 华东理工大学pk华东师范大学计算机专业,华东理工大学朱为宏教授和华东师范大学杨海波教授合作在光控手性金属配位自组装体系的研究中取得突破性进展...
- 爬虫07 爬取阿里旅行特价机票
- 为什么有人会说「感谢拼多多」,让一贫如洗的我还能活下去?
- apk多开制作方法 试用ApkEditor 1.8 旗舰版轻松制作apk多开双开
- 未解决:自行打包cpio格式的Ramdisk,与编译成功生成的kernel.bin,deviceTree一起打包成image.ub,不能正常启动kernel的问题???
- 试衣网的商业模式很脆弱