You are here

function paragraphs_bundle_save in Paragraphs 7

Function to create or update an paragraphs bundle.

Parameters

object $bundle: The object of the bundle to create/update.

Return value

int SAVED_UPDATED when updated, SAVED_NEW when created.

Throws

Exception

2 calls to paragraphs_bundle_save()
paragraphs_admin_bundle_form_submit in ./paragraphs.admin.inc
Submit handler for paragraphs_admin_bundle_form().
paragraphs_features_revert in ./paragraphs.features.inc
Implements hook_features_revert().
1 string reference to 'paragraphs_bundle_save'
paragraphs_bundle_copy_info in ./paragraphs.module
Implements hook_bundle_copy_info().

File

./paragraphs.module, line 983
Paragraphs hooks and common functions.

Code

function paragraphs_bundle_save($bundle) {
  $is_existing = (bool) db_query_range('SELECT 1 FROM {paragraphs_bundle} WHERE bundle = :bundle', 0, 1, array(
    ':bundle' => $bundle->bundle,
  ))
    ->fetchField();
  $fields = array(
    'bundle' => (string) $bundle->bundle,
    'name' => (string) $bundle->name,
    'label' => (string) $bundle->label,
    'description' => (string) $bundle->description,
    'locked' => (int) $bundle->locked,
  );
  if ($is_existing) {
    db_update('paragraphs_bundle')
      ->fields($fields)
      ->condition('bundle', $bundle->bundle)
      ->execute();
    $status = SAVED_UPDATED;
  }
  else {
    db_insert('paragraphs_bundle')
      ->fields($fields)
      ->execute();
    $status = SAVED_NEW;
  }
  paragraphs_bundle_load(NULL, TRUE);
  entity_info_cache_clear();
  variable_set('menu_rebuild_needed', TRUE);
  return $status;
}