Skip to content

Attempt to fix multi value handling with placeholders #740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions helper/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,25 @@ public function initialize($args)
*/
protected function setVal($value)
{
global $INPUT;

if (!$this->column) {
$value = '';
//don't validate placeholders here
} elseif ($this->replace($value) == $value) {
$validator = new ValueValidator();
$this->error = !$validator->validateValue($this->column, $value);
if ($this->error) {
foreach ($validator->getErrors() as $error) {
msg(hsc($error), -1);
} else {

// This method is called at parsing time, and again on action submit
// we really only want to validate the value on action submit
//
// At parsing time, the value might still be a placeholder. Ideally
// bureaucracy would already handle this. But well...
if($INPUT->post->has('bureaucracy')) {
$validator = new ValueValidator();

$this->error = !$validator->validateValue($this->column, $value);
if ($this->error) {
foreach ($validator->getErrors() as $error) {
msg(hsc($error), -1);
}
}
}
}
Expand Down Expand Up @@ -154,12 +164,23 @@ public function replacementMultiValueCallback($matches)
* Returns a Value object for the current column.
* Special handling for Page and Lookup literal form values.
*
* Used for rendering the field only.
*
* @return Value
*/
protected function createValue()
{
// input value or appropriately initialized empty value
$preparedValue = $this->opt['value'] ?? ($this->column->isMulti() ? [] : '');
// The value in bureaucracy is always a string, if unset init it.
$preparedValue = $this->opt['value'] ?? '';

// apply placeholder replacements
$preparedValue = $this->replace($preparedValue);

// Validating here is actually not a validation, that will happen again in setVal() when
// the form is submitted. instead, here we're using it's data cleanup functionality on the value.
$validator = new ValueValidator();
$validator->validateValue($this->column, $preparedValue);
/** @var string|array $preparedValue is now an array or a string */

// page fields might need to be JSON encoded depending on usetitles config
if (
Expand Down
Loading