-
Notifications
You must be signed in to change notification settings - Fork 39
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
Feature: Configurable default values for fields #353
base: master
Are you sure you want to change the base?
Feature: Configurable default values for fields #353
Conversation
Add a new configuration option to columns that allows adding default values for fields.
The travis check failed because there is a general issue running tests with PHP 7.0 and stable Dokuwiki due to changes in phpunit. Maybe you should disable this test for now until Dokuwiki has released a new stable version? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally not a bad idea. Needs merge conflict resolving and the logic needs to be double checked.
$val = $col->getType()->getDefaultValue(); | ||
|
||
// multi val data is concatenated | ||
if($col->isMulti()) { | ||
$val = explode($sep, $val); | ||
$val = array_filter($val); | ||
// multi val data is concatenated | ||
if($col->isMulti()) { | ||
$val = explode(',', $val); | ||
$val = array_map('trim', $val); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems the else branch logic changed here. The isMulti() check used to be outside the else, now it is inside?
@@ -82,7 +82,15 @@ public function renderfield($params, Doku_Form $form, $formid) { | |||
} | |||
|
|||
// output the field | |||
$value = new Value($this->column, $this->opt['value']); | |||
$rawvalue = $this->opt['value']; | |||
if (empty($rawvalue)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would overwrite a value of 0
with the default value.
This PR adds a new "default" configuration option to fields that can be used to set a default value. The default is applied whenever no existing schema data is found for a page (for example a new page or a newly assigned schema). This also means that when adding a new field with default to a schema, the default value will not apply to already existing pages using this schema.
In addition, the default is used when adding struct fields to a bureaucracy plugin form.
If you merge this PR, please let me know once you have made a release containing the change available on dokuwiki.org, so that I can add the new option to the documentation at https://www.dokuwiki.org/plugin:struct:type.