public function EventSubscriber::alterConfiguration in Opigno certificate 8
Same name and namespace in other branches
- 3.x src/EventSubscriber/EventSubscriber.php \Drupal\opigno_certificate\EventSubscriber\EventSubscriber::alterConfiguration()
Sets paper orientation depending to certificate paper_orientation field.
File
- src/
EventSubscriber/ EventSubscriber.php, line 22
Class
- EventSubscriber
- Class EventSubscriber.
Namespace
Drupal\opigno_certificate\EventSubscriberCode
public function alterConfiguration(GenericEvent $event) {
$route_name = \Drupal::routeMatch()
->getRouteName();
if ($route_name == 'certificate.entity.pdf') {
$route_params = \Drupal::routeMatch()
->getParameters();
$type = $route_params
->get('entity_type');
if ($type == 'group') {
$id = $route_params
->get('entity_id');
$group = Group::load($id);
if ($group) {
$certificate_id = $group
->get('field_certificate')->target_id;
$certificate = OpignoCertificate::load($certificate_id);
if ($certificate && $certificate
->hasField('paper_orientation')) {
$orientation = $certificate
->get('paper_orientation')->value;
$configuration = $event
->getArgument('configuration');
$configuration['default_paper_orientation'] = $configuration['orientation'] = !empty($orientation) ? $orientation : 'portrait';
$event
->setArgument('configuration', $configuration);
}
}
}
}
}