You are here

function minisite_site_save_asset in Mini site 7

Save minisite asset into database.

1 string reference to 'minisite_site_save_asset'
minisite_site_save in ./minisite.module
Save and extract minisite.

File

./minisite.module, line 117
Module file.

Code

function minisite_site_save_asset($entity_type, $entity, $field_name, $langcode, $item, $minisite_info) {
  $entity_uri = entity_uri($entity_type, $entity);
  $entity_path = $entity_uri['path'];
  $entity_path_alias = drupal_get_path_alias($entity_path, $langcode);
  list($entity_id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);

  // Prepare keys.
  $keys = array(
    'entity_type' => $entity_type,
    'bundle' => $bundle,
    'entity_id' => $entity_id,
    'revision_id' => $vid,
    'minisite_field_name' => $field_name,
    'minisite_fid' => $item['fid'],
    'language' => $langcode,
    'source' => $minisite_info['minisite_extract_path'] . '/' . $minisite_info['minisite_base_path'],
  );

  // Prepare fields.
  $fields = array(
    'alias' => $entity_path_alias,
    'alias_status' => isset($item['alias_status']) ? $item['alias_status'] : 0,
  );

  // Save minisite landing page information.
  db_merge('minisite_asset')
    ->key($keys)
    ->fields($fields)
    ->execute();

  // Save minisite assets information.
  if (isset($item['alias_status']) && $item['alias_status'] == 1) {
    foreach ($minisite_info['minisite_listing'] as $minisite_file) {
      if (strpos(strtolower($minisite_file), '.html') !== FALSE || strpos(strtolower($minisite_file), '.htm') !== FALSE) {
        $keys['source'] = $minisite_info['minisite_extract_path'] . '/' . $minisite_file;
        $search = $minisite_info['minisite_base_path'];
        $replace = $entity_path_alias;
        $fields['alias'] = str_replace($search, $replace, $minisite_file);
        db_merge('minisite_asset')
          ->key($keys)
          ->fields($fields)
          ->execute();
      }
    }
  }
}