entityreference.inc in Reference Table Formatter 7
File
plugins/reference_types/entityreference.inc
View source
<?php
$plugin = array(
'handler' => array(
'class' => 'reference_table_formatter_entityreference',
),
);
class reference_table_formatter_entityreference extends reference_table_formatter_base_type {
public function get_bundles() {
if ($this->field['settings']['handler'] == 'base' && isset($this->field['settings']['handler_settings']['target_bundles']) && count($this->field['settings']['handler_settings']['target_bundles']) > 0) {
return array_keys($this->field['settings']['handler_settings']['target_bundles']);
}
else {
$info = entity_get_info($this
->entity_name());
return array_keys($info['bundles']);
}
}
public function entity_name() {
return $this->field['settings']['target_type'];
}
function renderable_properties() {
$entity_name = $this
->entity_name();
$common_properties = array(
'node' => array(
'title',
),
'user' => array(
'name',
),
'taxonomy_term' => array(
'name',
),
);
return isset($common_properties[$entity_name]) ? $common_properties[$entity_name] : array();
}
function load_entity_from_item($item) {
$loaded_entities = entity_load($this
->entity_name(), array(
$item['target_id'],
));
return array_shift($loaded_entities);
}
function get_entity_property_label($info) {
$bundles = $this
->get_bundles();
if (count($bundles) == 1 && $this
->entity_name() == 'node') {
$type = node_type_load($bundles[0]);
return $type->title_label;
}
else {
return parent::get_entity_property_label($info);
}
}
}