diff --git a/src/Entity/Registrant.php b/src/Entity/Registrant.php index 98e77b9..dbe05cb 100644 --- a/src/Entity/Registrant.php +++ b/src/Entity/Registrant.php @@ -3,10 +3,12 @@ namespace Drupal\rng\Entity; use Drupal\Core\Entity\ContentEntityBase; +use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\rng\Exception\InvalidRegistrant; /** @@ -183,12 +185,15 @@ public function label() { '@type' => $identity->getEntityTypeId(), '@id' => $identity->label(), ]); - } + } $registration = $this->getRegistration(); $pattern = $this->type->entity->label_pattern; if (!empty($pattern)) { $label = \Drupal::token()->replace($pattern,['registrant'=>$this, 'registration'=>$registration]); if (!empty(trim($label))) { + if (strstr($label, '[') != FALSE) { + return t(' '); + } return $label; } } @@ -228,7 +233,28 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setRevisionable(TRUE) ->setReadOnly(TRUE); + $fields['status'] = BaseFieldDefinition::create('boolean') + ->setLabel(new TranslatableMarkup('Confirmed')) + ->setRevisionable(TRUE) + ->setTranslatable(TRUE) + ->setDefaultValue(TRUE) + ->setDisplayConfigurable('form', TRUE); + return $fields; } + /** + * @inheritDoc + */ + public function getEvent() { + return $this->get('event')->entity; + } + + /** + * @inheritDoc + */ + public function setEvent(ContentEntityInterface $event) { + $this->set('event', ['entity' => $event]); + return $this; + } } diff --git a/src/Entity/RegistrantInterface.php b/src/Entity/RegistrantInterface.php index 641a6d4..0e91786 100644 --- a/src/Entity/RegistrantInterface.php +++ b/src/Entity/RegistrantInterface.php @@ -29,6 +29,25 @@ public function getRegistration(); */ public function setRegistration(RegistrationInterface $registration); + /** + * Get associated content entity. + * + * @return ContentEntityInterface|null + * The parent event, if set. + */ + public function getEvent(); + + /** + * Set the event for this registrant. + * + * @param \Drupal\Core\Entity\ContentEntityInterface $event + * + * @return \Drupal\rng\Entity\RegistrantInterface + * Returns registratant for chaining. + */ + public function setEvent(ContentEntityInterface $event); + + /** * Get associated identity. * diff --git a/src/EventMeta.php b/src/EventMeta.php index 8b07a21..6453c4b 100644 --- a/src/EventMeta.php +++ b/src/EventMeta.php @@ -738,4 +738,29 @@ public function getDateString() { return date('F j', strtotime($start)) . ' - ' . date('j, Y', strtotime($end)); } + + /** + * @inheritDoc + */ + public function isPastEvent($use_end_date = FALSE) { + $event_type = $this->getEventType(); + $event = $this->getEvent(); + if ($use_end_date) { + $end_field = $event_type->getEventEndDateField(); + $count = $event->get($end_field)->count(); + $end_value = $event->get($end_field)->get($count - 1); + if (!empty($end_value->end_value)) { + $compare_date = $end_value->end_value; + } + else { + $compare_date = $end_value->value; + } + } + else { + $start_field = $event_type->getEventStartDateField(); + $compare_date = $event->get($start_field)->value; + } + return strtotime($compare_date) < time(); + + } } diff --git a/src/EventMetaInterface.php b/src/EventMetaInterface.php index 99dc8a9..252a900 100644 --- a/src/EventMetaInterface.php +++ b/src/EventMetaInterface.php @@ -373,6 +373,17 @@ public function addDefaultAccess(); */ public function createDefaultEventMessages(); + /** + * Check whether the event date is in the past. + * + * @param bool $use_end_date + * Set to TRUE to check whether end date is in the past. FALSE checks start date. + * + * @return bool + * Whether the event start or end date is in the past. + */ + public function isPastEvent($use_end_date = FALSE); + /** * Format the dates of this event. * diff --git a/src/Form/EventTypeForm.php b/src/Form/EventTypeForm.php index f669a98..face22c 100644 --- a/src/Form/EventTypeForm.php +++ b/src/Form/EventTypeForm.php @@ -94,6 +94,7 @@ public function __construct(EntityTypeManagerInterface $entity_manager, EntityTy public static function create(ContainerInterface $container) { return new static( $container->get('entity_type.manager'), + $container->get('entity_type.bundle.info'), $container->get('module_handler'), $container->get('entity_display.repository'), $container->get('rng.configuration'), diff --git a/src/Plugin/Action/CourierTemplateCollection.php b/src/Plugin/Action/CourierTemplateCollection.php index 0807239..0ceb180 100644 --- a/src/Plugin/Action/CourierTemplateCollection.php +++ b/src/Plugin/Action/CourierTemplateCollection.php @@ -153,7 +153,9 @@ public function execute($context = NULL) { $collection->setTokenValue('registration', $registration); foreach ($registration->getRegistrants() as $registrant) { $identity = $registrant->getIdentity(); - $this->courierManager->sendMessage($collection, $identity, $options); + if ($identity) { + $this->courierManager->sendMessage($collection, $identity, $options); + } } } } diff --git a/src/Plugin/views/field/EventDateStringField.php b/src/Plugin/views/field/EventDateStringField.php index 206a8c0..9845184 100644 --- a/src/Plugin/views/field/EventDateStringField.php +++ b/src/Plugin/views/field/EventDateStringField.php @@ -193,7 +193,7 @@ public function submitOptionsForm(&$form, FormStateInterface $form_state) { public function render(ResultRow $values) { // Make sure we are looking at the correct entity. $object = $this->getEntity($values); - if ($object->getEntityTypeId() != $this->configuration['entity_type']) { + if (empty($object) || $object->getEntityTypeId() != $this->configuration['entity_type']) { return; } $event_meta = $this->eventManager->getMeta($object);