public function MaestroEngineEntityIdentifierEntityLabel::render in Maestro 8.2
Same name and namespace in other branches
- 3.x src/Plugin/views/field/MaestroEngineEntityIdentifierEntityLabel.php \Drupal\maestro\Plugin\views\field\MaestroEngineEntityIdentifierEntityLabel::render()
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/ MaestroEngineEntityIdentifierEntityLabel.php, line 54
Class
- MaestroEngineEntityIdentifierEntityLabel
- Field handler to display the entity label for the entity POINTED TO from the entity identifiers .
Namespace
Drupal\maestro\Plugin\views\fieldCode
public function render(ResultRow $values) {
$result = '';
$urlToEntity = '';
$item = $values->_entity;
// This will ONLY work for maestro entity identifiers.
if ($item
->getEntityTypeId() == 'maestro_entity_identifiers') {
$entity_manager = \Drupal::entityTypeManager();
$entity = $entity_manager
->getStorage($item->entity_type
->getString())
->load($item->entity_id
->getString());
if (isset($entity)) {
$result = $entity
->label();
$urlToEntity = $entity
->access('view') ? $entity
->toUrl('canonical', [
'query' => [
'maestro' => 1,
],
])
->toString() : '';
}
else {
$result = '';
}
}
else {
return '';
}
if ($this->options['link_to_entity'] && $result && $urlToEntity) {
return [
'#markup' => '<a href="' . $urlToEntity . '" class="maestro_who_completed_field">' . $result . '</a>',
];
}
else {
return $result;
}
}