localgovdrupal / localgov_search

Default sitewide search implementation for LocalGov Drupal.
GNU General Public License v2.0
0 stars 1 forks source link

Hook install should use the $is_syncing variable #56

Closed andybroomfield closed 1 year ago

andybroomfield commented 1 year ago

I notice that localgov_search is installing the display modes when installed. However it should not do this if it is being enabled on a config sync operation. I noticed on a site I tried to install it on that when deployed I was getting memory limit errors releated to installing localgov_search. I think it's trying to enable it on all content types, which it won't need to do as this was done during the local install.

So I propose changing

function localgov_search_install() {

  // Ensure the sitewide search viewmodes are set on view and index.
  $node_bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo('node');
  foreach ($node_bundles as $bundle => $info) {
    localgov_search_entity_bundle_create('node', $bundle);
  }
}

to

function localgov_search_install($is_syncing) {

  if (!$is_syncing) {
    // Ensure the sitewide search viewmodes are set on view and index.
    $node_bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo('node');
    foreach ($node_bundles as $bundle => $info) {
      localgov_search_entity_bundle_create('node', $bundle);
    }
  }
}

And same for any hook_installed calls.