You are here

function search_by_page_paths_edit_form in Search by Page 8

Returns a form for editing a path item.

See also

search_by_page_paths_edit_form_submit()

1 string reference to 'search_by_page_paths_edit_form'
_search_by_page_paths_edit in search_by_page_paths/search_by_page_paths.module
Edits or adds new path.

File

search_by_page_paths/search_by_page_paths.module, line 349
Module file for Search by Page Paths, a sub-module for Search by Page.

Code

function search_by_page_paths_edit_form($form, &$form_state, $edit = array()) {
  global $language;
  $edit = array_merge(array(
    'pid' => 0,
    'page_path' => '',
    'title' => '',
    'page_type' => 'Page',
    'snippet' => 'yes',
    'environment' => 0,
    'role' => AccountInterface::ANONYMOUS_ROLE,
    'languages' => array(),
  ), $edit);
  $edit['environment'] = intval($edit['environment']);
  $form['path'] = array(
    '#type' => 'textfield',
    '#title' => t('Page to index'),
    '#default_value' => $edit['page_path'],
    '#size' => 45,
    '#description' => t('Specify a page on your site that you want to index. Do not include the language prefix, if any. To index the home page, enter its native path, as it is entered on the Site Information settings page.'),
    '#field_prefix' => search_by_page_path_field_prefix(),
    '#required' => TRUE,
  );
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title of page'),
    '#default_value' => $edit['title'],
    '#size' => 45,
    '#description' => t('Title to display in search results for this page'),
    '#required' => TRUE,
  );
  $form['type'] = array(
    '#type' => 'textfield',
    '#title' => t('Type of page'),
    '#default_value' => $edit['page_type'],
    '#size' => 45,
    '#description' => t('Type to display in search results for this page, if the theme displays item types'),
    '#required' => TRUE,
  );
  $form['snippet'] = array(
    '#type' => 'textarea',
    '#title' => t('Snippet'),
    '#default_value' => $edit['snippet'],
    '#cols' => 45,
    '#rows' => 5,
    '#description' => t('Enter "yes" (without the quotes, in English) to show a "snippet" of this page in search results, extracted from the page (it should show a portion of the page that contains the search results). Enter "no" (without the quotes, in English) to omit the snippet entirely. Or, enter any other text to use that custom text as the snippet for search results display.'),
    '#required' => TRUE,
  );
  if (\Drupal::moduleHandler()
    ->moduleExists('locale')) {
    $form['texthelp'] = array(
      '#type' => 'markup',
      '#markup' => '<p>' . t("Enter the title, type, and snippet above in your site's default language. If you have a multi-lingual site with the Internationalization project's String Translation module installed and enabled, you can use Drupal's translation interface to translate them.") . '</p>',
    );
    $form['languages'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Languages'),
      '#description' => t('Indicate which languages this page can be viewed in. It will be indexed in each language for searching.'),
      '#options' => locale_language_list('name'),
      '#default_value' => $edit['languages'],
    );
  }
  else {
    $form['languages'] = array(
      '#type' => 'value',
      '#value' => array(
        $language->language => TRUE,
      ),
    );
  }
  $form['role'] = array(
    '#type' => 'radios',
    '#title' => t('Role for indexing'),
    '#options' => user_roles(),
    '#default_value' => $edit['role'],
    '#weight' => 4,
    '#description' => t("When Search by Page indexes this page for searching, the page will be viewed from the perspective and permissions of a user with this role."),
  );
  if ($edit['pid']) {
    $form['pid'] = array(
      '#type' => 'value',
      '#value' => $edit['pid'],
    );
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Update indexed page'),
    );
  }
  else {
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Create new indexed page'),
    );
  }
  $form['submit']['#weight'] = 5;
  $form['environment'] = array(
    '#type' => 'value',
    '#value' => $edit['environment'],
  );
  $form['cancel'] = array(
    '#type' => 'markup',
    '#markup' => "<p>" . l(t('Cancel'), 'admin/config/search/search_by_page/edit/' . $edit['environment'] . '/paths') . "</p>",
    '#weight' => 6,
  );
  return $form;
}