You are here

function search_api_page_edit in Search API Pages 7

Changes a page's settings.

Parameters

$id: The edited page's ID.

array $fields: The new field values to set.

Return value

1 if fields were changed, 0 if the fields already had the desired values.

2 calls to search_api_page_edit()
search_api_page_admin_edit_submit in ./search_api_page.admin.inc
Submit callback for search_api_page_admin_edit().
search_api_page_search_api_index_update in ./search_api_page.module
Implements hook_search_api_index_update().

File

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

Code

function search_api_page_edit($id, array $fields) {
  $page = search_api_page_load($id, TRUE);
  $changeable = array(
    'name' => 1,
    'description' => 1,
    'path' => 1,
    'options' => 1,
    'enabled' => 1,
  );
  foreach ($fields as $field => $value) {
    if (isset($changeable[$field]) || $value === $page->{$field}) {
      $page->{$field} = $value;
      $new_values = TRUE;
    }
  }

  // If there are no new values, just return 0.
  if (empty($new_values)) {
    return 0;
  }
  $page
    ->save();
  return 1;
}