Skip to content

Instantly share code, notes, and snippets.

@indytechcook
Created September 7, 2012 15:03
Show Gist options
  • Save indytechcook/3666939 to your computer and use it in GitHub Desktop.
Save indytechcook/3666939 to your computer and use it in GitHub Desktop.
drupal custom block schema
<?php
/**
* @file
* Block Custom installation routines
*/
/**
* Implements hook_schema().
*/
function block_custom_schema() {
$schema['block_custom'] = array(
'description' => 'Stores Custom BLock items.',
'fields' => array(
'bid' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique Block item ID.',
'unsigned' => TRUE,
),
'vid' => array(
'type' => 'int',
'not null' => TRUE,
'description' => 'Revision ID',
'default' => 0,
'unsigned' => TRUE,
),
'delta' => array(
'description' => "The Custom Block's {block}.delta.",
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
),
'label' => array(
'description' => 'The Displays in the Admin page.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'title' => array(
'description' => 'The human-readable name of this block.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'type' => array(
'description' => 'The {block_custom_type}.type of this block.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'view_mode' => array(
'description' => 'The View mode to use as the block.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => 'default',
),
'data' => array(
'type' => 'text',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE,
'description' => 'A serialized array of additional data related to this block.',
),
),
'foreign keys' => array(
'type' => array(
'table' => 'block_custom_type',
'columns' => array('type' => 'type'),
),
'block_custom_revision' => array(
'table' => 'block_custom_revision',
'columns' => array('vid' => 'vid'),
)
),
'primary key' => array('bid'),
'unique keys' => array(
'vid' => array('vid'),
'delta' => array('delta'),
),
);
$schema['block_custom_revision'] = array(
'description' => 'Stores Custom Block Revisions.',
'fields' => array(
'bid' => array(
'description' => 'The {block} this version belongs to.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'vid' => array(
'description' => 'The primary identifier for this version.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'uid' => array(
'description' => 'The author of the revision.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'delta' => array(
'description' => "The bean's {block}.delta.",
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
),
'label' => array(
'description' => 'The Displays in the Admin page.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'title' => array(
'description' => 'The human-readable name of this bean.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'type' => array(
'description' => 'The {block_custom_type}.type of this bean.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'view_mode' => array(
'description' => 'The View mode to use as the bean.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => 'default',
),
'data' => array(
'type' => 'text',
'not null' => FALSE,
'size' => 'big',
'serialize' => TRUE,
'description' => 'A serialized array of additional data related to this block.',
),
'log' => array(
'description' => t('A log message associated with the revision.'),
'type' => 'text',
'size' => 'big',
),
'created' => array(
'description' => 'The Unix timestamp when the entity was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'changed' => array(
'description' => 'The Unix timestamp when the entity was most recently saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'foreign keys' => array(
'type' => array(
'table' => 'block_custom_type',
'columns' => array('type' => 'type'),
),
'version_block' => array(
'table' => 'block_custom',
'columns' => array('bid' => 'bid'),
)
),
'primary key' => array('vid'),
'indexes' => array(
'bid' => array('bid', 'vid'),
),
);
$schema['block_custom_type'] = array(
'description' => 'Stores information about all defined block types.',
'fields' => array(
'name' => array(
'description' => 'The machine-readable name of this block type.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
),
'label' => array(
'description' => 'The human-readable name of this block type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'description' => array(
'description' => 'The description of this block type.',
'type' => 'text',
'size' => 'big',
),
),
'primary key' => array('name'),
);
return $schema;
}
/**
* Implements hook_uninstall().
*/
function block_custom_uninstall() {
drupal_load('module', 'block_custom');
// Bypass entity_load() as we cannot use it here.
foreach (block_custom_get_types() as $block_type) {
field_attach_delete_bundle('block_custom', $block_type->type);
}
}
/**
* Implements hook_disable().
*/
function block_custom_disable() {
// Remove all of the currently placed blocks
// Delete any blocks
// @see block_custom_block_delete_submit()
db_delete('block')
->condition('module', 'block_custom')
->execute();
db_delete('block_role')
->condition('module', 'block_custom')
->execute();
// @see node_form_block_custom_block_delete_submit()
db_delete('block_node_type')
->condition('module', 'block_custom')
->execute();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment