You are here

function custom_search_install in Custom Search 8

Same name and namespace in other branches
  1. 6 custom_search.install \custom_search_install()
  2. 7 custom_search.install \custom_search_install()

Implements hook_install().

File

./custom_search.install, line 13
Install, update, and uninstall functions for the Custom Search module.

Code

function custom_search_install() {

  // Enable current node types and languages in advanced results.
  $types = node_type_get_names();
  foreach ($types as $type => $name) {
    $types[$type] = $type;
  }
  $enabled_languages = \Drupal::languageManager()
    ->getLanguages();
  $languages = [];
  foreach ($enabled_languages as $lid => $l) {
    $languages[$lid] = $lid;
  }
  $languages[Language::LANGCODE_NOT_SPECIFIED] = Language::LANGCODE_NOT_SPECIFIED;
  $languages[Language::LANGCODE_NOT_APPLICABLE] = Language::LANGCODE_NOT_APPLICABLE;

  // Set default settings for all search pages.
  $search_pages = \Drupal::entityTypeManager()
    ->getStorage('search_page')
    ->loadMultiple();
  foreach ($search_pages as $page) {
    if ($page
      ->getPlugin()
      ->getPluginId() == 'node_search') {
      $pageId = $page
        ->id();
      \Drupal::configFactory()
        ->getEditable('custom_search.settings.results')
        ->set($pageId, [
        'path' => $page
          ->getPath(),
        'search' => TRUE,
        'advanced' => [
          'visibility' => TRUE,
          'collapsible' => TRUE,
          'collapsed' => TRUE,
          'criteria' => [
            'or' => 'or',
            'phrase' => 'phrase',
            'negative' => 'negative',
          ],
          'types' => $types,
          'languages' => $languages,
        ],
        'info' => [
          'type' => 'type',
          'user' => 'user',
          'date' => 'date',
          'comment' => 'comment',
        ],
        'filter' => [
          'position' => 'disabled',
          'label' => t('Filter the results'),
          'any' => t('- Any -'),
        ],
      ])
        ->save();
    }
  }

  // Change module weight.
  module_set_weight('custom_search', 50);
}