Loading bookable_calendar.install +12 −0 Original line number Diff line number Diff line Loading @@ -126,3 +126,15 @@ function bookable_calendar_update_8108() { function bookable_calendar_update_8109() { \Drupal::service('config.installer')->installDefaultConfig('module', 'bookable_calendar'); } /** * Add title to Bookable Calendar Opening Instances. */ function bookable_calendar_update_8110() { $field_storage_definition = BaseFieldDefinition::create('string') ->setLabel(t('Title')) ->setDescription(t('Title of the Opening Instance')) ->setDefaultValue(NULL); \Drupal::entityDefinitionUpdateManager() ->installFieldStorageDefinition('title', 'bookable_calendar_opening_inst', 'bookable_calendar_opening_inst', $field_storage_definition); } src/Entity/BookableCalendarOpeningInstance.php +20 −1 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\bookable_calendar\BookableCalendarOpeningInstanceInterface; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\bookable_calendar\DateFormatter; /** * Defines the bookable calendar opening instance entity class. Loading Loading @@ -39,7 +40,7 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface; * admin_permission = "administer bookable calendar opening instance", * entity_keys = { * "id" = "id", * "label" = "id", * "label" = "title", * "uuid" = "uuid", * }, * links = { Loading @@ -61,6 +62,9 @@ class BookableCalendarOpeningInstance extends ContentEntityBase implements Booka $fields = parent::baseFieldDefinitions($entity_type); $fields['title'] = BaseFieldDefinition::create('string') ->setLabel(t('Title')) ->setDescription(t('Title of the Opening Instance')); $fields['booking'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Booking')) ->setDescription(t('Each booking that references this instance.')) Loading Loading @@ -171,9 +175,24 @@ class BookableCalendarOpeningInstance extends ContentEntityBase implements Booka ->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('view', TRUE); return $fields; } /** * Instance is created set the title based on the date. * * {@inheritdoc} */ public function preSave(EntityStorageInterface $storage, $update = TRUE) { parent::preSave($storage, $update); $date = $this->date; $formatted_date = DateFormatter::formatDateToBooking($date->value, $date->end_value); $this->set('title', $this->getParentCalendar()->label() . ': ' . $formatted_date); } /** * Instance is created update the parent opening to have this one saved. * Loading Loading
bookable_calendar.install +12 −0 Original line number Diff line number Diff line Loading @@ -126,3 +126,15 @@ function bookable_calendar_update_8108() { function bookable_calendar_update_8109() { \Drupal::service('config.installer')->installDefaultConfig('module', 'bookable_calendar'); } /** * Add title to Bookable Calendar Opening Instances. */ function bookable_calendar_update_8110() { $field_storage_definition = BaseFieldDefinition::create('string') ->setLabel(t('Title')) ->setDescription(t('Title of the Opening Instance')) ->setDefaultValue(NULL); \Drupal::entityDefinitionUpdateManager() ->installFieldStorageDefinition('title', 'bookable_calendar_opening_inst', 'bookable_calendar_opening_inst', $field_storage_definition); }
src/Entity/BookableCalendarOpeningInstance.php +20 −1 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\bookable_calendar\BookableCalendarOpeningInstanceInterface; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\bookable_calendar\DateFormatter; /** * Defines the bookable calendar opening instance entity class. Loading Loading @@ -39,7 +40,7 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface; * admin_permission = "administer bookable calendar opening instance", * entity_keys = { * "id" = "id", * "label" = "id", * "label" = "title", * "uuid" = "uuid", * }, * links = { Loading @@ -61,6 +62,9 @@ class BookableCalendarOpeningInstance extends ContentEntityBase implements Booka $fields = parent::baseFieldDefinitions($entity_type); $fields['title'] = BaseFieldDefinition::create('string') ->setLabel(t('Title')) ->setDescription(t('Title of the Opening Instance')); $fields['booking'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Booking')) ->setDescription(t('Each booking that references this instance.')) Loading Loading @@ -171,9 +175,24 @@ class BookableCalendarOpeningInstance extends ContentEntityBase implements Booka ->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('view', TRUE); return $fields; } /** * Instance is created set the title based on the date. * * {@inheritdoc} */ public function preSave(EntityStorageInterface $storage, $update = TRUE) { parent::preSave($storage, $update); $date = $this->date; $formatted_date = DateFormatter::formatDateToBooking($date->value, $date->end_value); $this->set('title', $this->getParentCalendar()->label() . ': ' . $formatted_date); } /** * Instance is created update the parent opening to have this one saved. * Loading