Commit 531ddaec authored by Bryce Gilhome's avatar Bryce Gilhome Committed by Josh Fabean
Browse files

Issue #3284979 by bgilhome: Allow overriding available slots per instance

parent a268f86d
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -114,3 +114,16 @@ function bookable_calendar_update_8105() {
  \Drupal::entityDefinitionUpdateManager()
    ->installFieldStorageDefinition('checked_in', 'booking_contact', 'booking_contact', $field_storage_definition);
}

/**
 * Add Slots field to Opening Instance
 */
function bookable_calendar_update_8106() {
  $field_storage_definition = BaseFieldDefinition::create('integer')
    ->setLabel(t('Slots'))
    ->setDescription(t('The number of available slots for this instance. If empty (NB not zero), will use calendar\'s defaults.'))
    ->setCardinality(1)
    ->setDefaultValue(NULL);
  \Drupal::entityDefinitionUpdateManager()
    ->installFieldStorageDefinition('slots', 'bookable_calendar_opening_inst', 'bookable_calendar_opening_inst', $field_storage_definition);
}
+13 −1
Original line number Diff line number Diff line
@@ -154,6 +154,18 @@ class BookableCalendarOpeningInstance extends ContentEntityBase implements Booka
      ->setClass('\Drupal\bookable_calendar\MaxSlotsItemList')
      ->setDisplayConfigurable('view', TRUE);

    $fields['slots'] = BaseFieldDefinition::create('integer')
      ->setLabel(t('Slots'))
      ->setDescription(t('The number of available slots for this instance. If empty (NB not zero), will use calendar\'s defaults.'))
      ->setCardinality(1)
      ->setDisplayOptions('form', [
        'type' => 'integer',
        'weight' => 10,
      ])
      ->setSetting('min', 0)
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);

    return $fields;
  }

@@ -185,7 +197,7 @@ class BookableCalendarOpeningInstance extends ContentEntityBase implements Booka
  }

  public function maxSlotsAvailable() {
    return (int) $this->getParentCalendar()->slots_per_opening->value;
    return (int) $this->slots->isEmpty() ? $this->getParentCalendar()->slots_per_opening->value : $this->slots->value;
  }

  public function maxPartySize() {