You are here

public function Bundle::save in Entity Construction Kit (ECK) 7.3

Same name and namespace in other branches
  1. 7.2 eck.classes.inc \Bundle::save()

Save the entity type.

Overrides DBObject::save

File

./eck.classes.inc, line 533
Classes for all the different objects used in ECK.

Class

Bundle

Code

public function save() {

  // Lets do some checks before the bundle is saved.
  if (isset($this->entity_type) && isset($this->name)) {
    $save = TRUE;

    // Lets set the machine name.
    $this
      ->createMachineName();

    // If this bundle is_new we need to check that it does not exist.
    // @todo we just need to change the field in the db to be unique.
    if ($this->is_new) {
      $bundle = Bundle::loadByMachineName($this->machine_name);
      if ($bundle && !$bundle->is_new) {
        $save = FALSE;
      }
    }
    if (!isset($this->label)) {
      $this
        ->createLabel();
    }
    if ($save) {
      parent::save();
      global $_eck_bundles_cache;
      $cache_enabled = isset($_eck_bundles_cache) ? TRUE : FALSE;
      if ($cache_enabled) {
        $_eck_bundles_cache
          ->reset();
      }
      variable_set('eck_clear_caches', TRUE);
    }
    else {

      // @todo throw some error.
    }
  }
  else {

    // If the name an entity type are not set, we can not save the bundle.
    // @todo throw soem error or exception.
  }
}