Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

andreasferber
Copy link

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.

Add a new configuration option to columns that allows adding default
values for fields.
@andreasferber
Copy link
Author

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?

Copy link
Member

@splitbrain splitbrain left a 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.

Comment on lines +217 to +223
$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);
}
Copy link
Member

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)) {
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants