Using Tailor mixin in plugin's model fields file

Hi, I’m wondering if there’s a way to use a mixin inside my Plugin’s model fields yaml file?

I’ve tried doing the following…

# seo_fields.yaml

handle: Content\SEOFields
type: mixin
name: SEO Fields

fields:

  meta_title:
    label: Meta Title
    tab: SEO
    type: text

  meta_description:
    label: Meta Description
    tab: SEO
    type: textarea
# Category fields.yaml
fields:
    title:
        label: Title
        type: text

    _seo_fields:
        type: mixin
        source: Content\SEOFields

But this gives me the error

"The partial '_field_mixin' is not found." on line 97 of 
/var/www/html/modules/system/traits/ViewMaker.php

I’m wondering if there’s some sort of trait or something I can use with the model that would allow me to do something like this.

In the meantime I guess I could just copy the seo_fields definition into my fields - but it would be cool if I could do something like the above some how.

Hey @neil-impelling,

There was a thread about this back in 2022 (link) — not sure if things have changed since, would be worth a look in the core.

Meanwhile, maybe this could work?

// In your Plugin.php boot() method
use Yaml;
use Event;

Event::listen('backend.form.extendFieldsBefore', function ($widget) {
    // Check if you're extending the correct model
    if (!$widget->model instanceof \YourPlugin\Models\Category) {
        return;
    }
    
    // Load your SEO fields YAML (the same one used for Tailor mixin)
    $seoFieldsPath = plugins_path('yourplugin/config/seo_fields.yaml');
    $seoConfig = Yaml::parseFile($seoFieldsPath);
    
    // Extract just the fields portion
    if (isset($seoConfig['fields'])) {
        foreach ($seoConfig['fields'] as $fieldName => $fieldConfig) {
            $widget->addFields($fieldName, $fieldConfig);
        }
    }
});

This way you can maintain a single seo_fields.yaml file that works for both your Tailor mixins and regular backend forms.