function SearchHooks::blockPresave

Implements hook_ENTITY_TYPE_presave() for block entities.

Attributes

#[Hook('block_presave')]

File

core/modules/search/src/Hook/SearchHooks.php, line 128

Class

SearchHooks
Hook implementations for search.

Namespace

Drupal\search\Hook

Code

public function blockPresave(BlockInterface $block) : void {
  // @see \Drupal\search\Plugin\Block\SearchBlock
  if ($block->getPluginId() === 'search_form_block') {
    $settings = $block->get('settings');
    if ($settings['page_id'] === '') {
      @trigger_error('Saving a search block with an empty page ID is deprecated in drupal:11.1.0 and removed in drupal:12.0.0. To use the default search page, use NULL. See https://www.drupal.org/node/3463132', E_USER_DEPRECATED);
      $settings['page_id'] = NULL;
      $block->set('settings', $settings);
    }
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.