Skip to content

Commit

Permalink
Update UserFormWidgetController.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennisprins93 authored Jul 24, 2024
1 parent 0e214af commit 95a1a6b
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/Controller/UserFormWidgetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,13 @@ public function Link($action = null)
$this->setWidgetAndElementFromUrl($this->getRequest()->getURL());
}

return Controller::join_links(Director::baseURL(), self::$url_segment, $this->widget->ID, $this->element->ID, $action);
return Controller::join_links(Director::baseURL(), self::$url_segment, $this->widget->ID, $this->element?->ID ?: 0, $action);
}

public function Form()
{
$form = parent::Form();

/** @var SiteTree $page */
$page = $this->element->getPage();
$form->Fields()->push(HiddenField::create('_PageUrl', '_PageUrl', $page->Link()));

if (!$this->widget) {
$this->widget = UserFormWidget::get()->byID($this->getRequest()->param('WidgetID'));
}
Expand All @@ -104,6 +100,7 @@ public function Form()
}

if ($this->element) {
$form->Fields()->push(HiddenField::create('_PageUrl', '_PageUrl', $this->element->getPage()->Link()));
$form->Fields()->push(HiddenField::create('ElementID', 'ElementID', $this->element->ID));
$form->Actions()->dataFieldByName('action_process')->addExtraClass($this->element->SubmitButtonColor);
}
Expand Down Expand Up @@ -155,7 +152,7 @@ public function process($data, $form)
}

/** @var ?Link $successLink */
$successLink = $this->element->Widget()->SuccessPage();
$successLink = $this->element ? $this->element->Widget()->SuccessPage() : $this->widget->SuccessPage();

return $this->redirect($successLink->getLinkURL());
}
Expand Down

0 comments on commit 95a1a6b

Please sign in to comment.