custom_search-8.x-1.x-dev/custom_search.install

custom_search.install
<?php

/**
 * @file
 * Install, update, and uninstall functions for the Custom Search module.
 */

use Drupal\Core\Language\Language;

/**
 * Implements hook_install().
 */
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);

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc