You are here

function custom_search_entity_bundle_create in Custom Search 8

Implements hook_entity_bundle_create().

File

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

Code

function custom_search_entity_bundle_create($entity_type, $bundle) {
  if ($entity_type == 'node') {

    // Add default config for Results settings.
    $search_pages = \Drupal::entityTypeManager()
      ->getStorage('search_page')
      ->loadMultiple();
    foreach ($search_pages as $page) {
      $pageId = $page
        ->id();
      $advanced_types = \Drupal::config('custom_search.settings.results')
        ->get($pageId . '.advanced.types');
      $advanced_types[$bundle] = $bundle;
      \Drupal::configFactory()
        ->getEditable('custom_search.settings.results')
        ->set($pageId . '.advanced.types', $advanced_types)
        ->save();
    }
  }
}