在自己定义主题中输出结果时,有三个部分或很多其它特殊的函数。如 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. Angular2之路由学习笔记

    目前工作中项目的主要技术栈是Angular2 在这里简单记录一下遇到的问题以及解决方案. 这篇笔记主要记录Angular2 的路由. 官方文档链接:https://angular.cn/docs/ts ...

  2. 安装windwos7 iis 出现错误,并非所有都成功更改的解决办法

    1.首先排除网上说的 安装的WIN7是精简版的问题,我这个是旗舰版,以前是正常安装IIS的,后来程序问题我卸载了,就安装不上了 2.网上说的修改什么UAC权限,也是胡扯,因为默认都是最低的 3.排除网 ...

  3. 利用js实现进入页面首先执行刷新操作,且只刷新一次

    让页面进行刷新,可以使用location.reload()方法,但是这种方法会让页面一直不断的刷新,这是因为当页面加载完成以后,我们让它刷新一次,那么浏览器就会重新向服务器请求数据, 界面会重新加载, ...

  4. LeetCode 75. Sort Colors (python一次遍历,模拟三路快排)

    LeetCode 75. Sort Colors (python一次遍历,模拟三路快排) 题目分析: 本题需要实现数字只包含0,1,2的排序,并且要求一次遍历. 由于只用把数字隔离开,很容易想到快排的 ...

  5. equal height

    https://css-tricks.com/the-perfect-fluid-width-layout/ http://nicolasgallagher.com/multiple-backgrou ...

  6. boost_1_63_0在Win10上VS2015编译

    装了个最新版的boost库,各种尝试,各种看网上的文章,然而就是没有编译成功.我真是哭晕在厕所. 最后还是自己老老实实啃官方文档.终于编出来了.下面记录下方法. 一·最简单的一种方法. 1.直接打开命 ...

  7. C# dataGridView1 添加数据 和清空数据

    #region MyRegion DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn(); DataGridViewTextBo ...

  8. Jquery插件:提示框

    在实际项目中,很容易有这种需求:当某个操作成功或失败,需要给用户一个提示.当然最简单的做法是调用alert()方法弹窗.但alert()属于JavaScript中BOM部分,每个浏览器的样式不太一样, ...

  9. Delphi中实现文件拷贝的三种方法

    1.调用API函数procedure CopyFile(FromFileName,ToFileName:string);varf1,f2:file;BeginAssignFile(f1,FromFil ...

  10. Centos 7.2 安装和卸载 MySQL 5.7

    一.背景 闲暇之余在虚拟机安装了 Centos 7.2 系统,按照 <简单安装MySQL(RPM方式)> 这篇文章安装 MySQL ,发现由于包依赖的问题安装失败,于是索性在官网查询相关文 ...