作者:老葛,北京亚艾元软件有限责任公司,http://www.yaiyuan.com
我们将'metadata controller class'设置为了Breadcrumb2MetadataController,对于这个类型,我们将它放到了breadcrumb2.info.inc文件中了。来看一下它的代码:
<?php
/**
* @file
* Provides Entity metadata integration.
*/
/**
* Extend the defaults.
*/
class Breadcrumb2MetadataController extends EntityDefaultMetadataController {
public function entityPropertyInfo() {
$info = parent::entityPropertyInfo();
$properties = &$info[$this->type]['properties'];
return $info;
}
}
我们这里面,这个类是空类,里面其实没有自己的实现。我们是模仿profile2的,它的这个元数据控制器类,是这样定义的:
class Profile2MetadataController extends EntityDefaultMetadataController {
public function entityPropertyInfo() {
$info = parent::entityPropertyInfo();
$properties = &$info[$this->type]['properties'];
$properties['label'] = array(
'label' => t('Label'),
'description' => t('The profile label.'),
'setter callback' => 'entity_property_verbatim_set',
'setter permission' => 'administer profiles',
'schema field' => 'label',
);
…
return $info;
}
}
/**
* Implements hook_entity_property_info_alter().
*/
function profile2_entity_property_info_alter(&$info) {
…
}
我们的面包屑里面,除了bid,不包含其它属性,同时只有一个bundle,我们这里可能就不需要定义这个元数据控制器类,只需要使用Entity API提供的默认的EntityDefaultMetadataController即可。
另外需要注意的是,在这个info.inc文件里面可以定义实现钩子hook_entity_property_info_alter。如果这个钩子实现可以放在这里的话,那么也可以在这里实现hook_entity_property_info,这是我的猜测。这样做的目的也是为了减小module文件的大小。