Skip to content

Commit

Permalink
Added FlexForm::setSubmitMethod() to customize form submit action [#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed Jan 26, 2021
1 parent a4481bf commit 0918419
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# v1.7.4
## mm/dd/2021

1. [](#new)
* Added `FlexForm::setSubmitMethod()` to customize form submit action
1. [](#bugfix)
* Fixed `bin/gpm uninstall` script not working because of bad typehint [#3172](https://github.com/getgrav/grav/issues/3172)
* Fixed `login: visibility_requires_access` not working [#3176](https://github.com/getgrav/grav/issues/3176)
* Fixed `login: visibility_requires_access` not working in pages [#3176](https://github.com/getgrav/grav/issues/3176)
* Fixed cannot change image format [#3173](https://github.com/getgrav/grav/issues/3173)

# v1.7.3
Expand Down
19 changes: 17 additions & 2 deletions system/src/Grav/Framework/Flex/FlexForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class FlexForm implements FlexObjectFormInterface, JsonSerializable
private $object;
/** @var string */
private $flexName;
/** @var callable|null */
private $submitMethod;

/**
* @param array $options Options to initialize the form instance:
Expand Down Expand Up @@ -213,6 +215,14 @@ public function getName(): string
return $this->flexName;
}

/**
* @param callable|null $submitMethod
*/
public function setSubmitMethod(?callable $submitMethod): void
{
$this->submitMethod = $submitMethod;
}

/**
* @param string $type
* @param string $name
Expand Down Expand Up @@ -504,8 +514,13 @@ protected function doSubmit(array $data, array $files)
/** @var FlexObject $object */
$object = clone $this->getObject();

$object->update($data, $files);
$object->save();
$method = $this->submitMethod;
if ($method) {
$method($data, $files, $object);
} else {
$object->update($data, $files);
$object->save();
}

$this->setObject($object);
$this->reset();
Expand Down

0 comments on commit 0918419

Please sign in to comment.