You are here

function search_api_page_insert in Search API Pages 7

Inserts a new search page into the database.

Parameters

array $values: An array containing the values to be inserted.

Return value

The newly inserted page's id, or FALSE on error.

1 call to search_api_page_insert()
search_api_page_admin_add_submit in ./search_api_page.admin.inc
Submit callback for search_api_page_admin_add().

File

./search_api_page.module, line 411
Generate search pages using Search API indexes.

Code

function search_api_page_insert(array $values) {
  foreach (array(
    'name',
    'machine_name',
    'index_id',
    'path',
  ) as $var) {
    if (!isset($values[$var])) {
      throw new SearchApiException(t('Property @field has to be set for the new search page.', array(
        '@field' => $var,
      )));
    }
  }
  if (empty($values['description'])) {
    $values['description'] = NULL;
  }
  if (empty($values['options'])) {
    $values['options'] = array();
  }
  $fields = array(
    'name' => $values['name'],
    'machine_name' => $values['machine_name'],
    'description' => $values['description'],
    'enabled' => empty($values['enabled']) ? 0 : 1,
    'index_id' => $values['index_id'],
    'path' => $values['path'],
    'options' => $values['options'],
  );
  if (isset($values['id'])) {
    $fields['id'] = $values['id'];
  }
  $page = entity_create('search_api_page', $fields);
  $page
    ->save();
  return $page->id;
}