public function CertificateController::viewEntity in Opigno certificate 3.x
Same name and namespace in other branches
- 8 src/Controller/CertificateController.php \Drupal\opigno_certificate\Controller\CertificateController::viewEntity()
Callback to view the opigno_certificate entity attached to any entity.
1 string reference to 'CertificateController::viewEntity'
File
- src/
Controller/ CertificateController.php, line 50
Class
- CertificateController
- Defines a controller to render a single opigno_certificate.
Namespace
Drupal\opigno_certificate\ControllerCode
public function viewEntity($entity_type, $entity_id, $view_mode = 'full') {
try {
$entity = $this->entityTypeManager
->getStorage($entity_type)
->load($entity_id);
} catch (PluginNotFoundException|InvalidPluginDefinitionException $e) {
watchdog_exception('opigno_certificate_exception', $e);
$entity = NULL;
}
if (!$entity instanceof ContentEntityInterface || !$entity
->hasField('field_certificate')) {
return [];
}
$opigno_certificate = $entity
->get('field_certificate')->entity;
if (!$opigno_certificate instanceof OpignoCertificateInterface) {
return [];
}
// We're going to render the opigno_certificate,
// but the opigno_certificate will need pull
// information from the entity that references it. So set the
// 'referencing_entity' computed field to the entity being displayed.
$opigno_certificate
->set('referencing_entity', $entity);
return $this
->view($opigno_certificate, $view_mode);
}