View source
<?php
class BiblioContributor extends Entity {
protected function defaultLabel() {
$wrapper = entity_metadata_wrapper('biblio_contributor', $this);
return $wrapper->biblio_contributor_name
->value();
}
public function label() {
$label = $this
->defaultLabel();
return $label;
}
protected function defaultUri() {
return array(
'path' => 'biblio/contributor/' . $this
->identifier(),
);
}
}
class BiblioContributorController extends EntityAPIController {
public function create(array $values = array()) {
global $user;
if (!isset($values['type'])) {
throw new Exception('Attempted to create a Biblio contributor without a type');
}
$default_values = array(
'cid' => '',
'title' => '',
'description' => '',
'created' => REQUEST_TIME,
'changed' => REQUEST_TIME,
'uid' => $user->uid,
'md5' => '',
);
$values = array_merge($default_values, $values);
$contributor = parent::create($values);
return $contributor;
}
public function buildContent($entity, $view_mode = 'full', $langcode = NULL, $content = array()) {
$wrapper = entity_metadata_wrapper('biblio_contributor', $entity);
$content['author'] = array(
'#markup' => t('Created by: !author', array(
'!author' => $wrapper->uid->name
->value(array(
'sanitize' => TRUE,
)),
)),
);
$content['description'] = array(
'#theme' => 'field',
'#weight' => 0,
'#title' => t('Description'),
'#access' => TRUE,
'#label_display' => 'above',
'#view_mode' => 'full',
'#language' => LANGUAGE_NONE,
'#field_name' => 'field_fake_description',
'#field_type' => 'text',
'#entity_type' => 'biblio_contributor',
'#bundle' => $entity->type,
'#items' => array(
array(
'value' => $entity->description,
),
),
'#formatter' => 'text_default',
0 => array(
'#markup' => check_plain($entity->description),
),
);
return parent::buildContent($entity, $view_mode, $langcode, $content);
}
}