Skip to content
Snippets Groups Projects
Commit 595c4820 authored by Owen Bush's avatar Owen Bush
Browse files

Got entity to update

parent 1af09720
No related branches found
No related tags found
No related merge requests found
...@@ -470,7 +470,8 @@ class EventSeries extends EditorialContentEntityBase implements EventInterface { ...@@ -470,7 +470,8 @@ class EventSeries extends EditorialContentEntityBase implements EventInterface {
* The date object for the weekly start date. * The date object for the weekly start date.
*/ */
public function getWeeklyStartDate() { public function getWeeklyStartDate() {
return $this->get('weekly_recurring_date')->start_date->setTime(0, 0, 0); $user_timezone = new \DateTimeZone(drupal_get_user_timezone());
return $this->get('weekly_recurring_date')->start_date->setTimezone($user_timezone)->setTime(0, 0, 0);
} }
/** /**
...@@ -480,7 +481,8 @@ class EventSeries extends EditorialContentEntityBase implements EventInterface { ...@@ -480,7 +481,8 @@ class EventSeries extends EditorialContentEntityBase implements EventInterface {
* The date object for the weekly end date. * The date object for the weekly end date.
*/ */
public function getWeeklyEndDate() { public function getWeeklyEndDate() {
return $this->get('weekly_recurring_date')->end_date->setTime(0, 0, 0); $user_timezone = new \DateTimeZone(drupal_get_user_timezone());
return $this->get('weekly_recurring_date')->end_date->setTimezone($user_timezone)->setTime(0, 0, 0);
} }
/** /**
...@@ -524,7 +526,8 @@ class EventSeries extends EditorialContentEntityBase implements EventInterface { ...@@ -524,7 +526,8 @@ class EventSeries extends EditorialContentEntityBase implements EventInterface {
* The date object for the monthly start date. * The date object for the monthly start date.
*/ */
public function getMonthlyStartDate() { public function getMonthlyStartDate() {
return $this->get('monthly_recurring_date')->start_date->setTime(0, 0, 0); $user_timezone = new \DateTimeZone(drupal_get_user_timezone());
return $this->get('monthly_recurring_date')->start_date->setTimezone($user_timezone)->setTime(0, 0, 0);
} }
/** /**
...@@ -534,7 +537,8 @@ class EventSeries extends EditorialContentEntityBase implements EventInterface { ...@@ -534,7 +537,8 @@ class EventSeries extends EditorialContentEntityBase implements EventInterface {
* The date object for the monthly end date. * The date object for the monthly end date.
*/ */
public function getMonthlyEndDate() { public function getMonthlyEndDate() {
return $this->get('monthly_recurring_date')->end_date->setTime(0, 0, 0); $user_timezone = new \DateTimeZone(drupal_get_user_timezone());
return $this->get('monthly_recurring_date')->end_date->setTimezone($user_timezone)->setTime(0, 0, 0);
} }
/** /**
......
...@@ -7,9 +7,8 @@ use Drupal\Core\Form\FormStateInterface; ...@@ -7,9 +7,8 @@ use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\recurring_events\EventCreationService; use Drupal\recurring_events\EventCreationService;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\OpenModalDialogCommand;
use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityInterface;
/** /**
* Form controller for the eventseries entity create form. * Form controller for the eventseries entity create form.
...@@ -18,6 +17,13 @@ use Drupal\Core\Entity\EntityStorageInterface; ...@@ -18,6 +17,13 @@ use Drupal\Core\Entity\EntityStorageInterface;
*/ */
class EventSeriesForm extends ContentEntityForm { class EventSeriesForm extends ContentEntityForm {
/**
* The current step of the form.
*
* @var int
*/
protected $step = 0;
/** /**
* The event creation service. * The event creation service.
* *
...@@ -64,12 +70,12 @@ class EventSeriesForm extends ContentEntityForm { ...@@ -64,12 +70,12 @@ class EventSeriesForm extends ContentEntityForm {
*/ */
public function buildForm(array $form, FormStateInterface $form_state) { public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state); $form = parent::buildForm($form, $form_state);
$form['#attached']['library'][] = 'core/drupal.dialog.ajax';
$editing = ($form_state->getBuildInfo()['form_id'] == 'eventseries_edit_form'); $editing = ($form_state->getBuildInfo()['form_id'] == 'eventseries_edit_form');
/* @var $entity \Drupal\recurring_events\Entity\EventSeries */ /* @var $entity \Drupal\recurring_events\Entity\EventSeries */
$entity = $this->entity; $entity = $this->entity;
$original = $this->storage->loadUnchanged($entity->id());
$form['custom_date']['#states'] = [ $form['custom_date']['#states'] = [
'visible' => [ 'visible' => [
...@@ -108,16 +114,51 @@ class EventSeriesForm extends ContentEntityForm { ...@@ -108,16 +114,51 @@ class EventSeriesForm extends ContentEntityForm {
]; ];
if ($editing) { if ($editing) {
$form['actions']['verify'] = [ $form['#entity_builders'][] = '::updateRecurringDates';
'#type' => 'submit', if ($this->step === 1) {
'#value' => $this->t('Verify Changes'), $diff_array = $this->creationService->buildDiffArray($original, $form_state);
'#ajax' => [
'wrapper' => 'eventseries-edit-form', if (!empty($diff_array)) {
'callback' => [$this, 'ajaxVerifyChanges'], $this->step = 0;
'method' => 'replace', $form['diff'] = [
'effect' => 'fade', '#type' => 'container',
], '#weight' => -10,
]; ];
$form['diff']['diff_title'] = [
'#type' => '#markup',
'#prefix' => '<h2>',
'#markup' => $this->t('Confirm Date Changes'),
'#suffix' => '</h2>',
];
$form['diff']['diff_message'] = [
'#type' => '#markup',
'#prefix' => '<p>',
'#markup' => $this->t('Recurrence configuration has been changed, as a result all instances will be removed and recreated. This action cannot be undone.'),
'#suffix' => '</p>',
];
$form['diff']['table'] = [
'#type' => 'table',
'#header' => [
$this->t('Data'),
$this->t('Stored'),
$this->t('Overridden'),
],
'#rows' => $diff_array,
];
$form['diff']['confirm'] = [
'#type' => 'submit',
'#value' => $this->t('Confirm Date Changes'),
'#submit' => [
'::submitForm',
'::save',
],
];
}
}
} }
return $form; return $form;
...@@ -127,56 +168,21 @@ class EventSeriesForm extends ContentEntityForm { ...@@ -127,56 +168,21 @@ class EventSeriesForm extends ContentEntityForm {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function validateForm(array &$form, FormStateInterface $form_state) { public function validateForm(array &$form, FormStateInterface $form_state) {
// TODO: Add validation.
parent::validateForm($form, $form_state); parent::validateForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function ajaxVerifyChanges(array &$form, FormStateInterface $form_state) {
/* @var $entity \Drupal\recurring_events\Entity\EventSeries */ /* @var $entity \Drupal\recurring_events\Entity\EventSeries */
$entity = $this->entity; $entity = $this->entity;
$original = $this->storage->loadUnchanged($entity->id()); $original = $this->storage->loadUnchanged($entity->id());
// Determine if there have been changes to the saved eventseries. $editing = ($form_state->getBuildInfo()['form_id'] == 'eventseries_edit_form');
$diff_array = $this->creationService->buildDiffArray($original, $form_state); $trigger = $form_state->getTriggeringElement();
if (!empty($diff_array)) {
$build = [];
$build['message'] = [
'#type' => '#markup',
'#prefix' => '<p>',
'#markup' => $this->t('Recurrence configuration has been changed, as a result all instances will be removed and recreated. This action cannot be undone.'),
'#suffix' => '</p>',
'#weight' => -9,
];
$build['diff'] = [
'#type' => 'table',
'#header' => [
$this->t('Data'),
$this->t('Stored'),
$this->t('Overridden'),
],
'#rows' => $diff_array,
'#weight' => -8,
];
}
else {
$build = [];
$build['message'] = [
'#type' => '#markup',
'#prefix' => '<p>',
'#markup' => $this->t('No recurrence configuration has changed. No existing instances will be affected by this update.'),
'#suffix' => '</p>',
'#weight' => -9,
];
}
$response = new AjaxResponse(); if ($trigger['#id'] !== 'edit-confirm' && $editing) {
$title = $this->t('Check Recurrence Modifications'); if ($this->creationService->checkForRecurConfigChanges($original, $form_state)) {
$response->addCommand(new OpenModalDialogCommand($title, $build, ['width' => '700'])); $this->step = 1;
return $response; $form_state->setRebuild(TRUE);
}
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment