LinkRegister.php in RNG - Events and Registrations 8.2
File
src/Plugin/views/field/LinkRegister.php
View source
<?php
namespace Drupal\rng\Plugin\views\field;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\views\Plugin\views\field\LinkBase;
use Drupal\views\ResultRow;
use Drupal\rng\Entity\RegistrationType;
class LinkRegister extends LinkBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['registration_type'] = [
'default' => '',
];
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$registration_types = [];
foreach (RegistrationType::loadMultiple() as $registration_type) {
$registration_types[$registration_type
->id()] = $registration_type
->label();
}
$form['registration_type'] = [
'#type' => 'select',
'#title' => $this
->t('Registration type'),
'#default_value' => $this->options['registration_type'],
'#options' => $registration_types,
'#empty_option' => $this
->t('- Display all registration types -'),
];
}
protected function getUrlInfo(ResultRow $row) {
$event = $this
->getEntity($row);
$route_parameters[$event
->getEntityTypeId()] = $event
->id();
$registration_type = $this->options['registration_type'];
if ($registration_type && RegistrationType::load($registration_type)) {
$route = 'rng.event.' . $event
->getEntityTypeId() . '.register';
$route_parameters['registration_type'] = $registration_type;
}
else {
$route = 'rng.event.' . $event
->getEntityTypeId() . '.register.type_list';
}
return Url::fromRoute($route, $route_parameters);
}
protected function getDefaultLabel() {
return $this
->t('Register');
}
}
Classes
Name |
Description |
LinkRegister |
Field handler to present a link to register for an event. |