backdrop-contrib / resource_timeslots

Provides a field type to reserve timeslots for configurable resources using a Fullcalendar calendar widget
GNU General Public License v2.0
1 stars 1 forks source link

Are previous dates allowed...? #17

Open PepeMty opened 2 years ago

PepeMty commented 2 years ago

Hello. I'm looking for a functionality that I really don't know if it's possible. I built this small booking system for a mountain lodge rental, Sometimes the stay can't be created but a few days later. Thing is this module doesn't allow to enter dates previous of today. Is there a way the library can be configured...? Or some sort of work around...? Can somebody point me in the right direction...? Thanks in advance...! Warm regards from way too sunny México. José

indigoxela commented 2 years ago

Sometimes the stay can't be created but a few days later.

That's a bit of an edge case...

No, it's not configurable to allow new reservations in the past. You can only override that with coding, either php or js. I'm not sure if you want to do that. I can provide examples, if that helps (using Backdrop hooks).

PepeMty commented 2 years ago

Hey, indigoxela...! I really appreciate your prompt reply. Examples...? Yes, please, I'll give it a try. :) José

indigoxela commented 2 years ago

Hi @PepeMty,

sure here's a small php example - a custom module called "mymodule":

The mymodule.info file:

name = My Module
description = My description here.
type = module
backdrop = 1.x

dependencies[] = resource_timeslots

The actual code in mymodule.module:

<?php
/**
 * @file
 * Main module code.
 */

/**
 * Implements hook_form_FORM_ID_alter().
 */
function mymodule_form_field_ui_field_edit_form_alter(&$form, &$form_state) {
  if ($form['#field']['type'] == 'resource_timeslot') {
    // Override the widget settings admin form to also allow past days.
    $form['instance']['widget']['settings']['min_avail_delay_days']['#min'] = -7;
  }
}

Rename as you need (replace all "mymodule" with something better, create a directory with the same name in the modules folder of your Backdrop install, put both files in there, then enable it.

Then (as an admin) you can go to admin/structure/types/manage/YOUR_NODE_TYPE/fields/YOUR_FIELD And set the value of "Min availability delay" to a negative value (= past).

After that the calendar widget allows to set values in the past.

Hope this helps.

PepeMty commented 2 years ago

Thank you, indigoxela...! Later today I'll check this code of yours and report back.

Thanks again. :)

José

PepeMty commented 2 years ago

@indigoxela Tons of thanks...! Your code worked as a charm.

José