You are here

function custom_search_configurable_language_create in Custom Search 8

Implements hook_entity_create().

File

./custom_search.module, line 33
Bring customizations to the default search box.

Code

function custom_search_configurable_language_create(EntityInterface $entity) {
  if ($entity
    ->id()) {

    // Add default config for Advanced search fieldset settings.
    $search_pages = \Drupal::entityTypeManager()
      ->getStorage('search_page')
      ->loadMultiple();
    foreach ($search_pages as $page) {
      $pageId = $page
        ->id();
      $languageId = $entity
        ->id();
      $advanced_languages = \Drupal::config('custom_search.settings.results')
        ->get($pageId . '.advanced.languages');
      $advanced_languages[$languageId] = $languageId;
      \Drupal::configFactory()
        ->getEditable('custom_search.settings.results')
        ->set($pageId . '.advanced.languages', $advanced_languages)
        ->save();
    }
  }
}