You are here

function flexiform_update_7003 in Flexiform 7

Add the base_entity and base_entity_bundle.

File

./flexiform.install, line 210
Sets up the base table for our entity and a table to store information about the entity types.

Code

function flexiform_update_7003() {
  db_add_field('flexiform', 'base_entity', array(
    'description' => 'The base entity type of the form.',
    'type' => 'varchar',
    'length' => 128,
    'not null' => TRUE,
    'default' => '',
  ), array(
    'indexes' => array(
      'base_entity' => array(
        'base_entity',
      ),
    ),
  ));
  db_add_field('flexiform', 'base_entity_bundle', array(
    'description' => 'The base entity type of the form.',
    'type' => 'varchar',
    'length' => 128,
    'not null' => TRUE,
    'default' => '',
  ));
  db_change_field('flexiform', 'fields', 'elements', array(
    'type' => 'text',
    'not null' => FALSE,
    'size' => 'big',
    'serialize' => TRUE,
    'description' => 'A serialized array of elements related to this flexiform.',
  ));

  // Update existing flexiform configurations.
  db_update('flexiform')
    ->fields(array(
    'base_entity' => 'flexiform_submission',
  ))
    ->expression('base_entity_bundle', 'form')
    ->execute();
  foreach (entity_load('flexiform') as $flexiform) {
    $flexiform->entities['base_entity'] = $flexiform->entities['this_submission'];
    $flexiform->entities['base_entity']['getter'] = 'base_entity';
    $flexiform->entities['base_entity']['namespace'] = 'base_entity';
    foreach ($flexiform->elements as $entity_namespace => $elements) {
      if ($entity_namespace == 'this_submission') {
        $flexiform->elements['base_entity'] = $elements;
        unset($flexiform->elements['this_submission']);
        foreach ($flexiform->elements['base_entity'] as &$element) {
          $element['entity_namespace'] = 'base_entity';
        }
      }
    }
    $flexiform
      ->save();
  }
}