Entity Reference Selection
To 'alter' what shows in an entity reference selection
Reference https://drupal.stackexchange.com/questions/298105/can-i-create-non-default-entityreferenceselection
In src/Plugin/EntityReferenceSelection
<?php
namespace Drupal\YOUR_MODULE\Plugin\EntityReferenceSelection;
use Drupal\node\Plugin\EntityReferenceSelection\NodeSelection;
/**
* Provides a query for a node entity reference selection.
*
* @EntityReferenceSelection(
* id = "YOUR_MODULE_REFERENCE_SELECTION_ID",
* label = @Translation("Filter nodes with a specific field value."),
* entity_types = {"node"},
* group = "YOUR_MODULE_REFERENCE_SELECTION_GROUP",
* weight = 1
* )
*/
class YourModuleEntityReferenceSelection extends NodeSelection {
/**
* {@inheritdoc}
*/
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
$query = parent::buildEntityQuery($match, $match_operator);
$query->condition('field_featured', 1', '=');
return $query;
}
}