You are here

public function ContentTypeGroup::save in Content type groups 7.2

Same name and namespace in other branches
  1. 7 content_type_groups.module \ContentTypeGroup::save()

Creates or updates the current content type group.

Return value

ContentTypeGroup Current ContentTypeGroup object (for chaining)

File

./content_type_groups.class.inc, line 63

Class

ContentTypeGroup
Utility class to handle content type groups

Code

public function save() {
  $transaction = db_transaction();
  try {

    // Add/update the group info
    $result = db_merge(self::$table_groups)
      ->key(array(
      'type' => $this->type,
    ))
      ->fields(array(
      'name' => $this->name,
    ))
      ->execute();
    if ($result) {

      // Delete all types for this group
      db_delete(self::$table_types)
        ->condition('group_type', $this->type)
        ->execute();

      // Insert the new types for this group
      foreach ($this->content_types as $content_type => $type_data) {
        db_insert(self::$table_types)
          ->fields(array(
          'group_type' => $this->type,
          'content_type' => $content_type,
          'weight' => $type_data['weight'],
        ))
          ->execute();
      }
    }
  } catch (Exception $e) {
    $transaction
      ->rollback();
    watchdog_exception('content type groups', $e);
    throw $e;
  }
  return $this;
}