You are here

function path_breadcrumbs_save in Path Breadcrumbs 7

Same name and namespace in other branches
  1. 7.3 path_breadcrumbs.module \path_breadcrumbs_save()
  2. 7.2 path_breadcrumbs.module \path_breadcrumbs_save()

Save path breadcrumbs.

1 call to path_breadcrumbs_save()
path_breadcrumbs_edit_form_submit in ./path_breadcrumbs.module
Submit callback for path_breadcrumbs_form.

File

./path_breadcrumbs.module, line 343

Code

function path_breadcrumbs_save($new_data, $path_breadcrumb = NULL) {

  // Remove spaces and empty lines in breadcrumb titles.
  $titles_output = array();
  $titles = explode("\r\n", $new_data->titles);
  foreach ($titles as $title) {
    if ($trimmed_title = trim($title)) {
      $titles_output[] = $trimmed_title;
    }
  }

  // Remove spaces and empty lines in breadcrumb titles.
  $paths_output = array();
  $paths = explode("\r\n", $new_data->paths);
  foreach ($paths as $path) {
    if ($trimmed_path = trim($path)) {
      $paths_output[] = $trimmed_path;
    }
  }

  // Build insert data.
  $insert_data = array(
    'name' => $new_data->name,
    'path' => $new_data->path,
    'titles' => serialize(implode("\r\n", $titles_output)),
    'paths' => serialize(implode("\r\n", $paths_output)),
    'home' => $new_data->home,
  );
  if ($path_breadcrumb) {

    // Update path breadcrumbs.
    db_update('path_breadcrumbs')
      ->fields($insert_data)
      ->condition('path_id', $path_breadcrumb->path_id)
      ->execute();
  }
  else {

    // Create new path breadcrumbs.
    $path_id = db_insert('path_breadcrumbs')
      ->fields($insert_data)
      ->execute();
  }
  return isset($path_id) ? $path_id : $path_breadcrumb->path_id;
}