在自己定义主题中输出结果时,有三个部分或很多其它特殊的函数。如 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的更多相关文章

  1. Drupal如何解析主题继承关系?

    Drupal中,主题是可以继承的,或者说是扩展.例如,要创建一个新的名为custom的主题,该主题与名为default的主题只有某些细小的差别.这个时候,不需要复制一份default到custom,可 ...

  2. Java定义bean实体类中的变量时变量名的问题

    首先:TMD,这个问题花了我两个多小时,居然是因为一个字母的大小写导致的,我瞬间就&Y^%^&%&()*%¥%¥¥&^#@%&; 事情是酱紫的: 我定义了一个变 ...

  3. HTML字符实体(Character Entities),转义字符串(Escape Sequence)

    为什么要用转义字符串? HTML中<,>,&等有特殊含义(<,>,用于链接签,&用于转义),不能直接使用.这些符号是不显示在我们最终看到的网页里的,那如果我们希 ...

  4. HTML字符实体(Character Entities),转义字符串(Escape Sequence)【转】

    为什么要用转义字符串? HTML中<,>,&等有特殊含义(<,>,用于链接签,&用于转义),不能直接使用.这些符号是不显示在我们最终看到的网页里的,那如果我们希 ...

  5. HTML字符实体(Character Entities),转义字符串(Escape Sequence) 转

    为什么要用转义字符串? HTML中<,>,&等有特殊含义(<,>,用于链接签,&用于转义),不能直接使用.这些符号是不显示在我们最终看到的网页里的,那如果我们希 ...

  6. [转]HTML字符实体(Character Entities),转义字符串(Escape Sequence)

    为什么要用转义字符串? HTML中<,>,&等有特殊含义(<,>,用于链接签,&用于转义),不能直接使用.这些符号是不显示在我们最终看到的网页里的,那如果我们希 ...

  7. Android中为窗口定义主题

    在res/values/styles文件夹中定义如下: <style name="myTheme"> <item name="android:windo ...

  8. 在 EFCore 定义的实体中进行 FreeSql 开发

    EFCore 和 FreeSql 都是 ORM,在各自领域都有着独特的优势. 问题起源 假设某项目是使用 EFCore 开发的,且实体 特性或FluentApi 都配置好了,如: protected ...

  9. HTML字符实体(Character Entities)与 转义字符串(Escape Sequence)(转)

    为什么要用转义字符串?HTML中<,>,&等有特殊含义(<,>,用于链接签,&用于转义),不能直接使用.这些符号是不显示在我们最终看到的网页里的,那如果我们希望 ...

随机推荐

  1. [codeforces contest 1119 F] Niyaz and Small Degrees 解题报告 (树形DP+堆)

    interlinkage: http://codeforces.com/contest/1119/problem/F description: 有一颗$n$个节点的树,每条边有一个边权 对于一个$x$ ...

  2. 利用阿里云加速Docker For Windows

    1.进入阿里云的容器镜像服务,找到镜像中心的镜像加速器. https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors 2.进入Docker ...

  3. mysql 登录与权限

    一.mysql 登录方式 1.1 格式:mysql -u用户名 -p密码 -h ip -P 端口 -S 套接字 mysql -uvagrant -pvagrant -h 127.0.0.1 -P 33 ...

  4. ubuntu刚安装好之后apt-get使用异常

    gaozhang 刚安装好之后,想执行apt-get update 任务,出现以下错误提示   提示说明apt正在执行,我们就野蛮的将apt进程杀.死即可,不过有点多,一个个kill   执行完之后再 ...

  5. 大数据查询——HBase读写设计与实践--转

    背景介绍 本项目主要解决 check 和 opinion2 张历史数据表(历史数据是指当业务发生过程中的完整中间流程和结果数据)的在线查询.原实现基于 Oracle 提供存储查询服务,随着数据量的不断 ...

  6. 使用Word 2010群发邮件

    1.建立数据库,这里我使用了excel 字段:电子邮件地址,名字 填写需要发送的数据 2.新建word文档,这里我使用了word2010 点击工具栏邮件 开始邮件合并,电子邮件 选择收件人,使用现有列 ...

  7. Boost多线程-替换MFC线程

           Mfc的多线程看起来简单,可以把线程直接压入向量,由系统类似进行调配,其实在内存的处理问题上留下了漏洞.在新线程里面载入大量流,会导致内存泄露. 方便之处:直接使用结构体传入函数参数,供 ...

  8. "国学"能带给孩子什么?

       您是家长吗?   是!就点标题下方蓝色的 静心坊 三字,然后点关注!您就可以享受到我们为您提供的最新教育信息. 读国学,除大量识字之外,还能带给孩子什么呢? 男孩子读国学,国学能教会他做一个正直 ...

  9. 创建一个dynamics CRM workflow (六) - Debugging Custom Workflows

    我们也deploy部署了custom workflows, debugging是开发当中不可或缺的一个步骤. debug workflow的步骤和debug有些许不一样: 1. install pro ...

  10. Flex元素布局规则总结,以及布局和容器

    一.Flex中的元素分类从功能层面可以把Flex中的元素分为组件(Components)和容器(Containers)两大类:组件 - 是指那类具有明确交互或数据展示功能的元素,例如Button.Ch ...