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 with Number and + converted to int and cannot be added to a content type #2201

Closed
develth opened this issue Dec 1, 2020 · 7 comments · Fixed by #2203
Closed

Taxonomy with Number and + converted to int and cannot be added to a content type #2201

develth opened this issue Dec 1, 2020 · 7 comments · Fixed by #2203

Comments

@develth
Copy link
Contributor

develth commented Dec 1, 2020

I have a taxonmy option called '66+', when adding it at the Backend to the Content-Type, i get an Error:

Argument 2 passed to Bolt\Repository\TaxonomyRepository::factory() must be of the type string, int given, called in /var/www/bolt/vendor/bolt/core/src/Controller/Backend/ContentEditController.php on line 482

When debugging in Frontend, i recognized that the value is already set as int by vue.

value='["50-65",66]'

Details

Question Answer
Relevant Bolt Version 4.1.8
Install type Composer install
BC Break no
PHP version 7.4
Web server Nginx
For UX/UI issues Firefox Developer Edition 84.0b4

Reproduction

Add Taxonmy like

offerAges:
  name: Age-Groups
  singular_name: Age-Group
  slug: ages
  singular_slug: age
  behaves_like: categories
  multiple: true
  options: [ "8-10", "10-14", "14-16", "16-18", "18-20", "20-29", "30-49", "50-65", "66+" ]
  required: true

Steps to reproduce

Add Taxonmy to Content-Type

Expected result

Should save '66+', not 66.

Actual result

Error, because converted to integer

@develth develth changed the title Taxonomy with + converted to int and cannot be saved Taxonomy with Number and + converted to int and cannot be saved Dec 1, 2020
@develth develth changed the title Taxonomy with Number and + converted to int and cannot be saved Taxonomy with Number and + converted to int and cannot be added to a content type Dec 1, 2020
@bobdenotter
Copy link
Member

bobdenotter commented Dec 1, 2020

Moving to the correct repository -> bolt/core

Nevermind! It's already in the correct one.. We'll take a look!

@develth
Copy link
Contributor Author

develth commented Dec 1, 2020

Also happens with a

"66-∞"

@develth
Copy link
Contributor Author

develth commented Dec 1, 2020

When change to object with string definition it works:
options: { 8to10: "8-10", 10to14: "10-14", 14to16: "14-16", 16to18: "16-18", 18to20: "18-20", 20to29: "20-29", 30to40: "30-49", 50to65: "50-65", age66AndOlder: "66+" }

@I-Valchev
Copy link
Member

@develth I've had a look and, in fact, there's a reason why we do it this way.

$optionKey = Str::slug($optionKey);

This line makes sure that, unless a key is set, the key is slugified. In the example you provide, 66+ becomes 66 because of how cucur/slugify works. Removing that line, while not breaking straightaway, does not show saved taxonomies with keys that are not slugs. The main reason taxonomies are slugs is that it is the right approach to be able to fetch them from the config, e.g.

https://github.com/bolt/core/blob/master/templates/content/_taxonomies.html.twig

The "fix" for this is to make sure that the key is always the string "66" rather than the int 66. In both cases it is without the +, because it's sugified.

@develth
Copy link
Contributor Author

develth commented Dec 1, 2020

Thanks for the clarification about that behaviour.
Make sure that there is a string instead of a int would be the best 'fix'

@I-Valchev
Copy link
Member

@develth no worries, thanks for bringing this up! It's a pretty interesting "edge case" 😅

@I-Valchev
Copy link
Member

Let's close this one.

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 a pull request may close this issue.

3 participants