Skip to content

Commit

Permalink
Remove redundant "Content Access" and "Entity access by field" search…
Browse files Browse the repository at this point in the history
… api processors
  • Loading branch information
nechai committed Nov 7, 2024
1 parent dc8a3f3 commit f22fe99
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 171 deletions.

This file was deleted.

31 changes: 31 additions & 0 deletions modules/social_features/social_node/social_node.install
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,34 @@ function social_node_install(): void {
function social_node_update_last_removed() : int {
return 11901;
}

/**
* Add new processors to search api indexes with node types.
*/
function social_node_update_11902(): void {
try {
if (\Drupal::moduleHandler()->moduleExists('social_search')) {
/** @var \Drupal\search_api\IndexInterface[] $indexes */
$indexes = \Drupal::entityTypeManager()
->getStorage('search_api_index')
->loadMultiple();

foreach ($indexes as $index) {
if (in_array('node', $index->getEntityTypes())) {
// Remove deprecated processors.
$index->removeProcessor('content_access');
$index->removeProcessor('entity_access_by_field');

$needs_reindex[] = $index->id();
}
}

if (!empty($needs_reindex)) {
social_search_resave_search_indexes($needs_reindex);
}
}
}
catch (InvalidPluginDefinitionException|PluginNotFoundException|EntityStorageException $e) {
\Drupal::logger('social_node')->info($e->getMessage());
}
}
19 changes: 19 additions & 0 deletions modules/social_features/social_node/social_node.module
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* The social node module alterations.
*/

use Drupal\Core\Entity\EntityInterface;
use Drupal\node\NodeInterface;
use Drupal\search_api\SearchApiException;
use Drupal\social_node\Entity\Node;
use Drupal\social_node\SocialNodeForm;
use Drupal\social_node\NodeViewBuilder;
Expand Down Expand Up @@ -65,3 +67,20 @@ function social_node_node_access_records_alter(array &$grants, NodeInterface $no
}
}
}

/**
* Implements hook_ENTITY_TYPE_presave() for "search_api_index".
*/
function social_node_search_api_index_presave(EntityInterface $index): void {
/** @var \Drupal\search_api\IndexInterface $index */
try {
if (!$index->getProcessor('content_access')) {
return;
}

$index->removeProcessor('content_access');
\Drupal::messenger()
->addWarning(t('"Content Access" processor is not allowed for using (replaced by query alters).'));
}
catch (SearchApiException $e) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,6 @@ field_settings:
module:
- profile
- user
node_grants:
label: 'Node access information'
property_path: search_api_node_grants
type: string
indexed_locked: true
type_locked: true
hidden: true
rendered_item:
label: 'Rendered HTML output'
property_path: rendered_item
Expand Down Expand Up @@ -237,9 +230,6 @@ datasource_settings:
default: true
selected: { }
processor_settings:
entity_access_by_field:
weights:
preprocess_query: -30
ignorecase:
all_fields: true
fields:
Expand All @@ -257,9 +247,6 @@ processor_settings:
weights:
preprocess_index: -20
preprocess_query: -20
content_access:
weights:
preprocess_query: -30
language_with_fallback: { }
stopwords:
all_fields: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ field_settings:
label: 'Language (with fallback)'
property_path: language_with_fallback
type: string
node_grants:
label: 'Node access information'
property_path: search_api_node_grants
type: string
indexed_locked: true
type_locked: true
hidden: true
rendered_item:
label: 'Rendered HTML output'
property_path: rendered_item
Expand Down Expand Up @@ -111,9 +104,6 @@ datasource_settings:
default: true
selected: { }
processor_settings:
entity_access_by_field:
weights:
preprocess_query: -30
ignorecase:
plugin_id: ignorecase
all_fields: true
Expand All @@ -125,11 +115,6 @@ processor_settings:
weights:
preprocess_index: -10
preprocess_query: -10
content_access:
plugin_id: content_access
weights:
preprocess_index: -10
preprocess_query: -10
language_with_fallback: { }
stopwords:
plugin_id: stopwords
Expand Down
2 changes: 1 addition & 1 deletion modules/social_features/social_search/social_search.module
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function social_search_views_data_alter(array &$data) {
*
* Make the label/title translatable.
*/
function social_block_view_search_hero_block_alter(array &$build, BlockPluginInterface $block) {
function social_search_block_view_search_hero_block_alter(array &$build, BlockPluginInterface $block) {
$build['#configuration']['label'] = t('Search');
}

Expand Down

0 comments on commit f22fe99

Please sign in to comment.