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

Taxonomize Entries #4098

Closed
michaelr0 opened this issue Aug 9, 2021 · 3 comments
Closed

Taxonomize Entries #4098

michaelr0 opened this issue Aug 9, 2021 · 3 comments

Comments

@michaelr0
Copy link
Contributor

michaelr0 commented Aug 9, 2021

Hey there,

It looks like Entires can only be searched with whereTaxonomy(), if the taxonomy has been configured on the collection.

I would have expected this to also work for taxonomy terms that have come from a blueprint field.

I've tried to see how much effort it would be to get this working on https://github.com/michaelr0/statamic-cms/tree/feature/taxonomize-fields but I've hit a roadblock that I haven't been able to figure out.

So I guess the first question is, should blueprint taxonomy terms also be used to filter Entries that have X taxonomy term?

If so, then does anyone have any ideas on what might be up with my changes?

I've tried to create taxonomies, taxonomiesFromCollection and taxonomiesFromEntry methods on the Entry class.

The taxonomize method on the EntryRepository has been changed to reference $entry->taxonomies()
Where I was hoping to use

$this->taxonomiesFromCollection()->merge($this->taxonomiesFromEntry());

Tests work if I just return taxonomiesFromCollection, but If I return the merged one or just the entries one, then the tests fail. As far as I've been able to tell, the two methods return the same kind of data, in fact taxonomiesFromEntry() seems like it returns the taxonomies from the collection as well (if you disable the check I've put in place), however this doesn't seem to work.

@dadaxr
Copy link
Contributor

dadaxr commented Feb 14, 2023

any news on this one ?

@jasonvarga
Copy link
Member

Taxonomizing entries is only available when the field matches the taxonomy.

Maybe this will be changed in statamic/ideas#839

You could query using whereJsonContains on other fields.

Entry::query()->where('collection', 'blog')->whereJsonContains('terms_field', ['one', 'two'])->get();

This will find entries where terms_field contains one, two, or both one and two.

@dadaxr
Copy link
Contributor

dadaxr commented Feb 15, 2023

Just for the record, I have a case where a collection "term field" does not match the taxonomy : ie It was created directly from the collection blueprint and not from the taxonomy setting page. Why that ? A little bit of context would help I guess :

I have a "cooking recipes" site dealing with "timing". I of course have a "recipe" collection with 2 fields:
"preration_time" and "cooking_time" , those 2 fields are linked to the same taxonomy : "timing".

Because I have two of them, I can't define the "recipe" collection in the "timing" taxonomy (which ends in creating only one "timing" field)...

As we can only set only one preparation_time and one cooking_time, I was lucky, because I could use the basic ->where('preparation_time', 'XXX') in my view model (like with basic fields)

If multiple "time" values were allowed (like multiple "prepration_time"; just imagine for one sec ;) ), I would indeed be able to query them using whereJsonContains(), thanks for that because I never thought of using it for that.

Just for my informattion : I guess it's less efficient than whereTaxonomy() (when the later can be used)?

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

No branches or pull requests

4 participants