provide filter condition in autocomplet field in drupal form using property
<?php
namespace Drupal\test_module_name\Plugin\EntityReferenceSelection;
use Drupal\node\Plugin\EntityReferenceSelection\NodeSelection;
/**
* Provides specific access control for the node entity type.
*
* @EntityReferenceSelection(
* id = "default:node_by_field",
* label = @Translation("Node by field selection"),
* entity_types = {"node"},
* group = "default",
* weight = 3
* )
*/
class NodeByFieldSelection extends NodeSelection {
/**
* {@inheritdoc}
*/
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
$query = parent::buildEntityQuery($match, $match_operator);
$handler_settings = $this->configuration['handler_settings'];
if (!isset($handler_settings['filter'])) {
return $query;
}
$filter_settings = $handler_settings['filter'];
foreach ($filter_settings as $field_name => $value) {
$query->condition($field_name, $value, '=');
}
return $query;
}
}