function search_api_exclude_form_node_form_alter in Search API exclude 8
Same name and namespace in other branches
- 7 search_api_exclude.module \search_api_exclude_form_node_form_alter()
Implements hook_form_BASE_FORM_ID_alter(). +
File
- ./
search_api_exclude.module, line 19 - Allows users to exclude specific nodes from indexing by Search API.
Code
function search_api_exclude_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id) {
/** @var \Drupal\node\NodeInterface $node */
$node = $form_state
->getFormObject()
->getEntity();
$type = NodeType::load($node
->bundle());
if (!$type
->getThirdPartySetting('search_api_exclude', 'enabled', FALSE)) {
return;
}
$form['search_api_exclude'] = [
'#type' => 'details',
'#title' => t('Search API Exclude'),
'#group' => 'advanced',
'#tree' => TRUE,
'#open' => $node
->get('sae_exclude')
->getString(),
];
$form['search_api_exclude']['exclude'] = [
'#type' => 'checkbox',
'#title' => t('Prevent this node from being indexed.'),
'#default_value' => $node
->get('sae_exclude')
->getString(),
];
$form['#entity_builders'][] = 'search_api_exclude_form_node_form_builder';
}