Skip to content
Snippets Groups Projects
Commit fb598450 authored by endless_wander's avatar endless_wander Committed by Owen Bush
Browse files

Issue #3419642 by endless_wander, Sandeep_k, owenbush: "Registration Type"...

Issue #3419642 by endless_wander, Sandeep_k, owenbush: "Registration Type" field is not available in views
parent 4c2f09e2
No related branches found
No related tags found
No related merge requests found
......@@ -76,6 +76,16 @@ function recurring_events_registration_views_data_alter(array &$data) {
],
];
$data['eventseries_field_data']['eventseries_registration_type'] = [
'title' => t('Registration Type'),
'field' => [
'title' => t('Registration Type'),
'help' => t('The type of registration allowed for the series.'),
'id' => 'eventseries_registration_type',
'click sortable' => TRUE,
],
];
// We do not want people adding the event_registration__ fields to views as
// they will not work. Instead for any fields necessary we create them above.
foreach ($data['eventseries_field_data'] as $field_name => $field) {
......
<?php
namespace Drupal\recurring_events_registration\Plugin\views\field;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\recurring_events_registration\RegistrationCreationService;
/**
* Field handler to show the type of registration for event series.
*
* @ingroup views_field_handlers
*
* @ViewsField("eventseries_registration_type")
*/
class EventSeriesRegistrationType extends FieldPluginBase {
/**
* The registration creation service.
*
* @var \Drupal\recurring_events_registration\RegistrationCreationService
*/
protected $registrationCreationService;
/**
* Constructs a new EventSeriesRegistrationType object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin ID for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\recurring_events_registration\RegistrationCreationService $registration_creation_service
* The registration creation service.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, RegistrationCreationService $registration_creation_service) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->registrationCreationService = $registration_creation_service;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('recurring_events_registration.creation_service')
);
}
/**
* {@inheritdoc}
*/
public function query() {
// Leave empty to avoid a query on this field.
}
/**
* {@inheritdoc}
*/
public function render(ResultRow $values) {
$series = $values->_entity;
$this->registrationCreationService->setEventSeries($series);
$registration_type = $this->registrationCreationService->getRegistrationType();
if (empty($registration_type)) {
return $this->t('N/A');
}
return $registration_type;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment