Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(forms): automatically support sticky forms
fixes #11141
- Loading branch information
Showing
79 changed files
with
1,071 additions
and
725 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Elgg\Forms; | ||
|
||
/** | ||
* Prepare sticky form fields | ||
* | ||
* @since 5.0 | ||
*/ | ||
class PrepareFields { | ||
|
||
/** | ||
* Generic sticky form fields handler | ||
* | ||
* @param \Elgg\Event $event 'form:prepare:fields', 'all' | ||
* | ||
* @return array|null | ||
*/ | ||
public function __invoke(\Elgg\Event $event): ?array { | ||
if (!(bool) $event->getParam('sticky_enabled')) { | ||
return null; | ||
} | ||
|
||
$form_name = $event->getParam('sticky_form_name'); | ||
if (empty($form_name) || !elgg_is_sticky_form($form_name)) { | ||
return null; | ||
} | ||
|
||
$ignored_fields = (array) $event->getParam('sticky_ignored_fields'); | ||
$body_vars = $event->getValue(); | ||
|
||
// merge the sticky values into the fields | ||
$sticky_vars = elgg_get_sticky_values($form_name); | ||
foreach ($sticky_vars as $key => $value) { | ||
if (in_array($key, $ignored_fields)) { | ||
// this shouldn't happen, but just in case | ||
continue; | ||
} | ||
$body_vars[$key] = $value; | ||
} | ||
|
||
// clear the sticky values | ||
elgg_clear_sticky_form($form_name); | ||
|
||
return $body_vars; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.