function eck_update_7000 in Entity Construction Kit (ECK) 7
Same name and namespace in other branches
- 7.3 eck.install \eck_update_7000()
- 7.2 eck.install \eck_update_7000()
Update 7000
File
- ./
eck.install, line 137 - This install file creates a table for the this module to store information about entities. Well, the only information that it needs to store is a name and a label for each entity created, the rest of the information is generated by the functions.
Code
function eck_update_7000() {
// To implement bundles (types), I have decided to have one table that will
// hold all of the types information. So for this update we need to create the
// table, and add all of the current entities with their types to the table,
// so we can unify the implementations of bundles in code.
$schema = array(
'description' => "The base table for entities types information",
'fields' => array(
'id' => array(
'description' => "The primary identifier for a(n) entity type",
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'entity' => array(
'description' => "The entity this type belongs to",
'type' => 'varchar',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
),
'type' => array(
'description' => "The type (bundle) name that will be used",
'type' => 'varchar',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
),
'label' => array(
'description' => "A human readable name for the bundle (not that the type is not human readable)",
'type' => 'varchar',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
),
),
'primary key' => array(
'id',
),
'indexes' => array(
'entity_type' => array(
'entity',
'type',
),
),
);
db_create_table('eck_types', $schema);
// Now we add a type (bundle) to the table for each entity in the eck table.
$results = db_select('eck', 't')
->fields('t')
->execute();
foreach ($results as $record) {
$nid = db_insert('eck_types')
->fields(array(
'entity' => $record->name,
'type' => $record->name,
'label' => $record->label,
))
->execute();
// Also we want to add a field to all the enity tables for the type, and
// populated with the current type.
db_add_field("eck_{$record->name}", 'type', array(
'description' => 'The type of the entity',
'type' => 'varchar',
'default' => '',
'length' => 255,
'not null' => TRUE,
'initial' => $record->name,
));
}
}