'target_bundles' => NULL,
// Add sorting.
'sort' =>
[ 'field' => 'field_text.value',
'direction' => 'DESC',
],
];
$handler =
$this->container->
get('plugin.manager.entity_reference_selection'
)->
getInstance($selection_options);
// Not only assert the result, but make sure the keys are sorted as
// expected.
$result =
$handler->
getReferenceableEntities();
$expected_result =
[ $nodes['published2'
]->
id() =>
$node_labels['published2'
],
$nodes['published1'
]->
id() =>
$node_labels['published1'
],
];
$this->
assertSame($expected_result,
$result['article'
], 'Query sorted by field returned expected values.'
);
// Assert sort by base field.
$selection_options['sort'
] =
[ 'field' => 'nid',
'direction' => 'ASC',
];