You are here

function fieldable_panels_panes_update_7108 in Fieldable Panels Panes (FPP) 7

Adding Fieldable Panels Panes Type table and saving existing bundles.

File

./fieldable_panels_panes.install, line 331
Fieldable Panels Panes install file.

Code

function fieldable_panels_panes_update_7108() {
  ctools_include('export');
  $messages = array();
  if (!db_table_exists('fieldable_panels_pane_type')) {

    // Copied from fieldable_panels_panes_schema() because the schema should not
    // be directly used during hook_update_N.
    $schema['fieldable_panels_pane_type'] = array(
      'description' => 'Entity bundle table for panel pane content.',
      'fields' => array(
        'name' => array(
          'description' => 'The machine-readable name of this type.',
          'type' => 'varchar',
          'length' => 255,
          'not null' => TRUE,
          'default' => '',
        ),
        'title' => array(
          'description' => 'The human-readable name of this type.',
          'type' => 'varchar',
          'length' => 255,
          'not null' => TRUE,
          'default' => '',
          'translatable' => TRUE,
        ),
        'description' => array(
          'description' => 'A brief description of this type.',
          'type' => 'text',
          'size' => 'big',
          'not null' => TRUE,
        ),
      ),
      'export' => array(
        'admin_title' => 'title',
        'admin_description' => 'description',
        'api' => array(
          'owner' => 'fieldable_panels_panes',
          'api' => 'fieldable_panels_pane_type',
          'minimum_version' => 1,
          'current_version' => 1,
        ),
      ),
      'primary key' => array(
        'name',
      ),
    );

    // Add the new table for storing bundles.
    db_create_table('fieldable_panels_pane_type', $schema['fieldable_panels_pane_type']);
  }

  // Store possible existing bundles provided by other modules.
  $bundles = array();
  $entity_info = entity_get_info('fieldable_panels_pane');

  // The default bundle is not defined. This could happen if the module was
  // updated and cache cleared before update was run as entity info's cache
  // will no longer contain the old default.
  if (empty($entity_info['bundles']['fieldable_panels_pane'])) {
    $t = get_t();
    $entity_info['bundles']['fieldable_panels_pane'] = array(
      'label' => $t('Panels pane'),
    );
  }
  foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
    $bundles[] = $bundle_info['label'];
    $item = ctools_export_crud_new('fieldable_panels_pane_type');
    $item->name = $bundle_name;
    $item->title = $bundle_info['label'];
    ctools_export_crud_save('fieldable_panels_pane_type', $item);
  }
  if (!empty($bundles)) {
    $messages[] = format_plural(count($bundles), 'Added existing bundle %bundle_names to database.', 'Added existing bundles %bundle_names to database.', array(
      '%bundle_names' => implode(', ', $bundles),
    ));
  }
  return implode('<br />', $messages);
}