function WorkspaceViewsIntegrationTest::getRevPubViewResults
Returns the 'name' values of a view of 'entity_test_revpub' with a filter.
Parameters
string $field: The field to filter on.
string $value: The value to filter for.
Return value
string[] The name of each row the view returned.
File
-
core/
modules/ workspaces/ tests/ src/ Kernel/ WorkspaceViewsIntegrationTest.php, line 244
Class
- WorkspaceViewsIntegrationTest
- Tests the views integration for workspaces.
Namespace
Drupal\Tests\workspaces\KernelCode
protected function getRevPubViewResults(string $field, string $value) : array {
$view = View::create([
'id' => 'test_entity_test_revpub',
'base_table' => 'entity_test_revpub',
'base_field' => 'id',
]);
$executable = Views::executableFactory()->get($view);
$executable->setDisplay('default');
$executable->addHandler('default', 'field', 'entity_test_revpub', 'name', []);
// Views only selects the column when something sorts on it.
$executable->addHandler('default', 'sort', 'entity_test_revpub', 'name', []);
$executable->addHandler('default', 'filter', 'entity_test_revpub', $field, [
'operator' => '=',
'value' => $value,
]);
$executable->execute();
// The rendered value comes from the loaded entity, which is already the
// pending revision, so read the selected column instead.
return array_map(fn($row) => (string) $row->entity_test_revpub_name, $executable->result);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.