Skip to content

Commit

Permalink
Set default dates on availability update form
Browse files Browse the repository at this point in the history
  • Loading branch information
acrollet committed May 10, 2018
1 parent f489a6c commit e28ae84
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Form/UpdateAvailabilityForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\bee\Form;

use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\node\NodeInterface;
Expand All @@ -21,6 +22,13 @@ public function getFormId() {
*/
public function buildForm(array $form, FormStateInterface $form_state, NodeInterface $node = NULL) {
$bee_settings = \Drupal::config('node.type.' . $node->bundle())->get('bee');
$today = new \DateTime();

$tomorrow = clone($today);
$tomorrow->modify('+1 day');

$one_hour_later = clone($today);
$one_hour_later->modify('+1 hour');

$form['node'] = [
'#type' => 'hidden',
Expand All @@ -46,12 +54,14 @@ public function buildForm(array $form, FormStateInterface $form_state, NodeInter
'#type' => ($bee_settings['bookable_type'] == 'daily') ? 'date' : 'datetime',
'#title' => t('Start'),
'#date_increment' => 3600,
'#default_value' => ($bee_settings['bookable_type'] == 'daily') ? $today->format('Y-m-d') : new DrupalDateTime($today->format('Y-m-d H:00')),
'#required' => TRUE,
];

$form['availability']['end_date'] = [
'#type' => ($bee_settings['bookable_type'] == 'daily') ? 'date' : 'datetime',
'#title' => t('End'),
'#default_value' => ($bee_settings['bookable_type'] == 'daily') ? $tomorrow->format('Y-m-d') : new DrupalDateTime($one_hour_later->format('Y-m-d H:00')),
'#date_increment' => 3600,
'#required' => TRUE,
'#suffix' => '</div>',
Expand Down

0 comments on commit e28ae84

Please sign in to comment.