You are here

function domain_taxonomy_save_term in Domain Taxonomy 7

Same name and namespace in other branches
  1. 6 domain_taxonomy.module \domain_taxonomy_save_term()
  2. 7.3 domain_taxonomy.module \domain_taxonomy_save_term()
1 call to domain_taxonomy_save_term()
domain_taxonomy_form_term_submit in ./domain_taxonomy.module

File

./domain_taxonomy.module, line 358

Code

function domain_taxonomy_save_term($term) {

  // Define the $grants array.
  $grants = array();

  // If the form is hidden, we are passed the 'domains_raw' variable.
  // We need to append unique values from this variable to the existing
  // stored values.  See the logic for 'view domain publshing' in domain_form_alter().
  if (!empty($term->domains_raw)) {
    if (!isset($term->domains)) {
      $term->domains = array();
    }
    foreach ($term->domains_raw as $value) {

      // Only add this if it is not present already.
      if (!in_array($value, $term->domains)) {
        $term->domains[$value] = $value;
      }
    }
  }

  // If set, grant access to the core site, otherwise
  // The grant must be explicitly given to a domain.
  if (!empty($term->domain_site)) {
    $grants[] = array(
      'realm' => 'domain_site',
      'gid' => 0,
      'grant_view' => 1,
      'grant_update' => 0,
      'grant_delete' => 0,
      'priority' => 0,
    );
  }

  // Set the domain-specific grants.
  if (!empty($term->domains)) {
    foreach ($term->domains as $key => $value) {

      // We can't use a 0 value in an $options list, so convert -1 to 0.
      if (abs($value) > 0) {
        $key == -1 ? $key = 0 : ($key = $key);
        $grants[] = array(
          'realm' => 'domain_id',
          'gid' => $key,
          'grant_view' => 1,
          'grant_update' => 1,
          'grant_delete' => 1,
          'priority' => 0,
        );
      }
    }
  }

  // At least one option must be present, and it is the default site
  // this prevents null values in the form.
  // If we are enabling the module for the first time, we set the
  // default domain of all existing nodes to the root domain.
  if (empty($grants)) {
    $grants[] = array(
      'realm' => 'domain_id',
      'gid' => 0,
      'grant_view' => 1,
      'grant_update' => 1,
      'grant_delete' => 1,
      'priority' => 0,
    );
  }

  // Store our records in the {domain_access} table.
  _domain_taxonomy_store_grants($term->tid, $grants);
  _domain_taxonomy_update_source($term);
}