Skip to content

Commit

Permalink
Issue #3114193 by dhirendra.mishra, freelock: cant register to an event
Browse files Browse the repository at this point in the history
  • Loading branch information
freelock authored and freelock committed Jul 3, 2020
1 parent bdd1314 commit ab2294f
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 3 deletions.
28 changes: 27 additions & 1 deletion src/Entity/Registrant.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
19 changes: 19 additions & 0 deletions src/Entity/RegistrantInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
25 changes: 25 additions & 0 deletions src/EventMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

}
}
11 changes: 11 additions & 0 deletions src/EventMetaInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
1 change: 1 addition & 0 deletions src/Form/EventTypeForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
4 changes: 3 additions & 1 deletion src/Plugin/Action/CourierTemplateCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/views/field/EventDateStringField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ab2294f

Please sign in to comment.