diff --git a/modules/recurring_events_registration/recurring_events_registration.views.inc b/modules/recurring_events_registration/recurring_events_registration.views.inc index 4ab9143c6c61ca72692f05a1e6eff4dc69c7f39c..2995d1a4dfa609a15ab176d944f944346f603d28 100644 --- a/modules/recurring_events_registration/recurring_events_registration.views.inc +++ b/modules/recurring_events_registration/recurring_events_registration.views.inc @@ -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) { diff --git a/modules/recurring_events_registration/src/Plugin/views/field/EventSeriesRegistrationType.php b/modules/recurring_events_registration/src/Plugin/views/field/EventSeriesRegistrationType.php new file mode 100644 index 0000000000000000000000000000000000000000..858cad31029734827ad2e16f7a2c0f1457c91656 --- /dev/null +++ b/modules/recurring_events_registration/src/Plugin/views/field/EventSeriesRegistrationType.php @@ -0,0 +1,78 @@ +<?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; + } + +}