public function MaestroEngineEntityIdentifierEditLink::render in Maestro 3.x
Same name and namespace in other branches
- 8.2 src/Plugin/views/field/MaestroEngineEntityIdentifierEditLink.php \Drupal\maestro\Plugin\views\field\MaestroEngineEntityIdentifierEditLink::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/ MaestroEngineEntityIdentifierEditLink.php, line 54
Class
- MaestroEngineEntityIdentifierEditLink
- Field handler to generate an edit link to the entity if possible based on user perms.
Namespace
Drupal\maestro\Plugin\views\fieldCode
public function render(ResultRow $values) {
$editUrlToEntity = '';
$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)) {
$queueID = 0;
if (isset($this->view->args[1])) {
$queueID = $this->view->args[1];
}
$editUrlToEntity = $entity
->access('update') !== FALSE ? $entity
->toUrl('edit-form', [
'query' => [
'maestro' => 1,
],
])
->toString() : '';
}
else {
$result = '';
}
}
else {
return '';
}
if ($this->options['edit_text'] && $editUrlToEntity) {
return [
'#markup' => '<a href="' . $editUrlToEntity . '" class="maestro_who_completed_field">' . $this->options['edit_text'] . '</a>',
];
}
else {
return '';
}
}