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

Taxonomy field with max_items: 1 prevents saving when the field is empty #1101

Closed
miktirr opened this Issue Nov 10, 2016 · 1 comment

Comments

Projects
None yet
4 participants
@miktirr
Copy link

miktirr commented Nov 10, 2016

Expected behaviour

If a taxonomy field has a max_items setting that is set to 1, the field can be saved with only one taxonomy term or without a taxonomy term (i.e. as empty) in CP.

Actual behaviour

Trying to save when the field is empty throws ”There was a problem saving the data. Please check your logs.” and in the logs there is:

[2016-11-03 08:22:40] production.ERROR: ErrorException: Undefined offset: 0 in [...]/statamic/bundles/Relate/RelateFieldtype.php:29

NB

Saving empty fields works if the max_items is set as max_items: "1" (not max_items: 1). But this seems at least inconsistent with the max_files setting for assets.

Server configuration

Web server:
Apache

PHP version:
7.0.12

Statamic version:
2.1.17

@jackwakefield

This comment has been minimized.

Copy link

jackwakefield commented Dec 21, 2016

A temporary fix is changing line 28 in statamic/bundles/Relate/RelateFieldtype.php from

if ($this->getFieldConfig('max_items') === 1 && is_array($data)) {

to

if ($this->getFieldConfig('max_items') === 1 && is_array($data) && array_key_exists(0, $data)) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.