Provide the ability to maintain a link between quick forms and the entities that they create.
This commit is contained in:
parent
2e11d737f6
commit
707295d2a8
|
@ -4,6 +4,41 @@
|
|||
* Farm quick install.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_schema().
|
||||
*/
|
||||
function farm_quick_schema() {
|
||||
$schema['farm_quick_entity'] = array(
|
||||
'description' => 'Entities created via quick forms.',
|
||||
'fields' => array(
|
||||
'entity_type' => array(
|
||||
'description' => 'Entity type.',
|
||||
'type' => 'varchar',
|
||||
'length' => 32,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'entity_id' => array(
|
||||
'description' => 'Entity ID.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'quick_form_id' => array(
|
||||
'description' => 'Quick form ID.',
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'entity_type' => array('entity_type'),
|
||||
'entity_id' => array('entity_id'),
|
||||
'quick_form_id' => array('quick_form_id'),
|
||||
),
|
||||
);
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
|
@ -12,3 +47,40 @@ function farm_quick_uninstall() {
|
|||
// Delete variables.
|
||||
variable_del('farm_quick_forms_enabled');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the {farm_quick_entity} table.
|
||||
*/
|
||||
function farm_quick_update_7000(&$sandbox) {
|
||||
|
||||
// Create the {farm_quick_entity} table.
|
||||
$schema = array(
|
||||
'description' => 'Entities created via quick forms.',
|
||||
'fields' => array(
|
||||
'entity_type' => array(
|
||||
'description' => 'Entity type.',
|
||||
'type' => 'varchar',
|
||||
'length' => 32,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'entity_id' => array(
|
||||
'description' => 'Entity ID.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'quick_form_id' => array(
|
||||
'description' => 'Quick form ID.',
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'entity_type' => array('entity_type'),
|
||||
'entity_id' => array('entity_id'),
|
||||
'quick_form_id' => array('quick_form_id'),
|
||||
),
|
||||
);
|
||||
db_create_table('farm_quick_entity', $schema);
|
||||
}
|
||||
|
|
|
@ -194,3 +194,50 @@ function farm_quick_configure_form($form, &$form_state) {
|
|||
function farm_quick_configure_form_submit(&$form, &$form_state) {
|
||||
menu_rebuild();
|
||||
}
|
||||
|
||||
/**
|
||||
* Link an entity to a quick form.
|
||||
*
|
||||
* @param string $quick_form_id
|
||||
* The quick form ID.
|
||||
* @param string $entity_type
|
||||
* The entity type.
|
||||
* @param $entity
|
||||
* The entity.
|
||||
*/
|
||||
function farm_quick_entity_link($quick_form_id, $entity_type, $entity) {
|
||||
|
||||
// If no quick form ID is provided, bail.
|
||||
if (empty($quick_form_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the entity ID.
|
||||
$id = entity_id($entity_type, $entity);
|
||||
|
||||
// If the ID could not be found, bail.
|
||||
if (empty($id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Save it to the {farm_quick_entity} table.
|
||||
$record = array(
|
||||
'entity_type' => $entity_type,
|
||||
'entity_id' => $id,
|
||||
'quick_form_id' => $quick_form_id
|
||||
);
|
||||
drupal_write_record('farm_quick_entity', $record);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_delete().
|
||||
*/
|
||||
function farm_quick_entity_delete($entity, $type) {
|
||||
|
||||
// When an entity is deleted, delete associated records in
|
||||
// {farm_quick_entity}.
|
||||
$id = entity_id($type, $entity);
|
||||
if (!empty($id)) {
|
||||
db_query('DELETE FROM {farm_quick_entity} WHERE entity_type = :entity_type AND entity_id = :entity_id', array(':entity_type' => $type, ':entity_id' => $id));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue