public function SearchApiFlag::render in Flag Search API 8
Renders the field.
Parameters
\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.
Return value
string|\Drupal\Component\Render\MarkupInterface The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.
Overrides FieldPluginBase::render
File
- src/
Plugin/ views/ field/ SearchApiFlag.php, line 21
Class
- SearchApiFlag
- Displays a flag link.
Namespace
Drupal\flag_search_api\Plugin\views\fieldCode
public function render(ResultRow $values) {
// Extract the entity type id and entity id from the search api id.
$entity_info = explode(':', $values->search_api_id)[1];
list($entity_type_id, $entity_id) = explode('/', $entity_info);
// Remove the 'flag_' prefix of the field name to get the flag ID.
$flag_id = substr($this->field, 5);
// Generate flag link.
$flag_link = [
'#lazy_builder' => [
'flag.link_builder:build',
[
$entity_type_id,
$entity_id,
$flag_id,
],
],
'#create_placeholder' => TRUE,
];
return $flag_link;
}