You are here

function skinr_skin_save in Skinr 7.2

Same name and namespace in other branches
  1. 8.2 skinr.module \skinr_skin_save()

Save a skin object.

Parameters

$skin: A skin object.

Return value

TRUE on success, FALSE on failure.

22 calls to skinr_skin_save()
SkinrApiTestCase::testSkinrImplementsCache in tests/skinr.test
Tests skinr_implements() caching and auto-loading.
SkinrApiTestCase::testSkinrSkinDefaults in tests/skinr.test
Test default skin configurations (in code).
SkinrApiTestCase::testSkinrSkinHooks in tests/skinr.test
Test hook invocations for CRUD operations on skin configurations.
SkinrApiTestCase::testSkinrSkinLoadSave in tests/skinr.test
Test skinr_skin_save() against invalid entries.
SkinrContextDisplayTestCase::testSkinrContextDisplayed in skinr_context/tests/skinr_context.test

... See full list

File

./skinr.module, line 633
Handles core Skinr functionality.

Code

function skinr_skin_save(&$skin) {

  // Make sure we're getting valid data.
  if (!skinr_skin_validate($skin)) {
    return FALSE;
  }

  // Load the stored skin configuration object, if any.
  if (!empty($skin->sid)) {
    if (!isset($skin->original)) {

      // Load an uncached version of the skin configuration object.
      $skin->original = skinr_skin_load_unchanged($skin->sid);
    }
  }

  // Let modules modify the node before it is saved to the database.
  module_invoke_all('skinr_skin_presave', $skin);
  if (!empty($skin->sid)) {

    // Record exists, so let's update.
    $status = drupal_write_record('skinr_skins', $skin, 'sid');
    module_invoke_all('skinr_skin_update', $skin);
  }
  else {

    // Assign it a UUID if none is set.
    if (empty($skin->uuid)) {
      if (!module_exists('uuid')) {
        module_load_include('inc', 'skinr', 'skinr.uuid');
      }
      $skin->uuid = uuid_generate();
    }

    // Insert a new record.
    $status = drupal_write_record('skinr_skins', $skin);
    module_invoke_all('skinr_skin_insert', $skin);
  }

  // Clear internal properties.
  unset($skin->original);

  // Clear the static loading cache.
  // @todo Once we have a more granular reset for skinr_skin_load_multiple(), we
  //   need to use it here.
  drupal_static_reset('skinr_skin_load_multiple');

  // Clear preprocess cache.
  cache_clear_all('skinr_preprocess:' . $skin->module . ':' . $skin->element . ':', 'cache', TRUE);
  return $status;
}