Roomのテストデータ(dsvフォーマット):
ルームナンバー: room_number
rid,room_number,type 1,1001,シングル 2,1002,シングル 3,1003,シングル 4,2001,ダブル 5,3001,ダブル
/**
* Implement hook_schema()
*/
function entity_example_schema(){
$schema['room']=array(
'description' => 'Rooms',
'fields' => array(
'rid' => array(
'type' => 'serial',
'description' => 'Room Id'
),
'type' => array(
'type' => 'varchar',
'length' => '255',
'description' => 'Room Type'
),
'room_number' => array(
'type' => 'varchar',
'length' => '25',
'description' => 'Room Number'
),
),
'primary key' => array('rid'),
);
return $schema;
}
/**
* Implements hook_entity_info().
*/
/**
* Implements hook_entity_info().
*/
function entity_example_entity_info()
{
$services['room'] = array(
'label' => t('Room'), // エンティティ名
'entity class' => 'Entity', // デフォルトクラスの使用
'controller class' => 'EntityAPIController',// デフォルトクラスの使用
'base table' => 'room', // DB上のテーブル名
'fieldable' => TRUE, // 余分のフィールド追加可能
'entity keys' => array( // ルームIDをエンティティのキー.
'id' => 'rid',
'label' => 'room_number', // コールバック関数が優先
),
'view modes' => array(
'full' => array(
'label' => t('Default'),
'custom settings' => FALSE,
),
),
'bundles' => array(), // bundleはこのエンティティ自身
// 'label callback' => 'room_label', // 指定しないとラベルの取得ができない
'access callback' => 'room_access' , // default:'value user_access'動作しない
'module' => 'entity_example',
'metadata controller class' => 'EntityExampleMetadataController',
);
return $services;
}
/**
* Extend the defaults.
*/
class EntityExampleMetadataController extends EntityDefaultMetadataController {
public function entityPropertyInfo() {
$info = parent::entityPropertyInfo();
$properties = &$info[$this->type]['properties'];
$properties['type'] = array(
'label' => t('Room type'),
'schema field' => 'type',
'getter callback' => 'entity_property_getter_method',
'setter callback' => 'entity_property_verbatim_set',
'required' => TRUE,
'description' => t('Room type of the room'),
);
$properties['room_number'] = array(
'label' => t('Room Number'),
'schema field' => 'room_number',
'getter callback' => 'entity_property_getter_method',
'setter callback' => 'entity_property_verbatim_set',
'required' => TRUE,
'description' => t('The number of the room'),
)
return $info;
}
}
function room_access($op, $room = NULL, $account = NULL) {
// 全員アクセス可能にする
return TRUE;
}
| 添付 | サイズ |
|---|---|
| entity_example.zip (1.87 KB) | 1.87 KB |