You are here

public static function Utility::matches in Search API 8

Checks whether a certain value matches the configuration.

This unifies checking for matches with the common configuration pattern of having one "All except those selected"/"Only the selected" option ("default") and a list of options to select.

Parameters

mixed $value: The value to check.

array $settings: The settings to check against, as an associative array with the following keys:

  • default: Boolean defining the default for not-selected items. TRUE means "All except those selected", FALSE means "Only the selected". Defaults to TRUE.
  • selected: A numerically indexed array of the selected options. Defaults to an empty array.

Return value

bool TRUE if the value matches according to the configuration, FALSE otherwise.

2 calls to Utility::matches()
ContentEntityTrackingManager::filterValidItemIds in src/Plugin/search_api/datasource/ContentEntityTrackingManager.php
Filters a set of datasource-specific item IDs.
ContentEntityTrackingManager::getIndexesForEntity in src/Plugin/search_api/datasource/ContentEntityTrackingManager.php
Retrieves all indexes that are configured to index the given entity.

File

src/Utility/Utility.php, line 246

Class

Utility
Contains utility methods for the Search API.

Namespace

Drupal\search_api\Utility

Code

public static function matches($value, array $settings) {
  $settings += [
    'default' => TRUE,
    'selected' => [],
  ];
  return in_array($value, $settings['selected']) != $settings['default'];
}