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

Field profile map specificity and support for Commerce products and users #86

Merged
merged 2 commits into from
Apr 5, 2024

Conversation

mmikkel
Copy link
Member

@mmikkel mmikkel commented Apr 5, 2024

This PR adds the ability to create more specific field profile mappings.

Previously, field profiles were mapped by simple handles only, where the key(s) would be matched to the elements' section or category group handles:

'profileMap' => [
    'news' => 'newsProfile',
],

The above config would result in the newsProfile field profile being used for elements belonging to either a section with the handle news or a category group with that same handle.

This PR retains this behaviour (and expands it to also include Craft Commerce products), but adds the ability to create more specific profile mappings by prefixing keys with either section:, entryType:, categoryGroup:, productType: or user:. As an example:

'profileMap' => [
    'news' => 'newsProfile', // Matches entries, categories and products where either the section, entry type, category group or product type has the handle "news"
    'entryType:news' => 'newsBlockProfile', // Matches entries with an entry type "news" only
    'categoryGroup:news' => 'newsCategoryProfile', // Matches categories in a category group "news" only
    'productType:tShirts' => 'tShirtsProfile', // Matches products with a product type "tShirts" only
    'user:people' => 'userProfile', // Matches users only
],

Profile mappings are matched from highest to lowest specificity, i.e. for entries SEOMate will first look for a matching profile using the "entryType:" or "section:" syntax, before looking at the "unspecific" profiles (i.e. the ones not using the "sourceType:handle" syntax. Similarly for categories, SEOMate will first look for a matching profile using the "categoryGroup:" syntax, before looking at the unspecific profiles.

This PR should be mostly backwards compatible, but might require some adjustments to existing SEOMate config files in rare cases.

This PR also fixes #85, by making the SEOMateHelper::getElementProfile() method more defensive when querying for entry sections.

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.

1 participant