title.inc in Entity Construction Kit (ECK) 7.2
File
plugins/property_behavior/title.inc
View source
<?php
$plugin = array(
'label' => "Title",
'entity_view' => 'eck_title_property_entity_view',
'entity_info' => 'eck_title_property_entity_info',
'default_widget' => 'eck_title_property_widget',
);
function eck_title_property_widget($property, $vars) {
$entity = $vars['entity'];
$title = _eck_title_property_extract_title($entity, $property);
return array(
'#type' => 'textfield',
'#title' => $vars['properties'][$property]['label'],
'#maxlength' => 255,
'#default_value' => $title,
'#required' => TRUE,
);
}
function eck_title_property_entity_view($property, $vars) {
$entity = $vars['entity'];
$title = _eck_title_property_extract_title($entity, $property);
if (empty($title)) {
$entity_id = entity_id($entity
->entityType(), $entity);
$title = "{$entity->entityType()} : {$entity_id}";
}
$uri = entity_uri($entity
->entityType(), $entity);
if ($uri['path'] == current_path()) {
drupal_set_title($title);
}
}
function eck_title_property_entity_info($property, $var) {
$info = $var;
unset($info['label callback']);
$info['entity keys']['label'] = $property;
return $info;
}
function _eck_title_property_extract_title($entity, $property) {
$title = "";
if (isset($entity->{$property})) {
$title = $entity->{$property};
}
return $title;
}