Jake Vanderwerf
2026-02-09 2d0b98416804d8a132895720c9c33e6061bd6752
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
namespace JVBase\managers\SEO\schemas\resolvers;
 
use JVBase\managers\SEO\schemas\SchemaDefinition;
use JVBase\managers\SEO\SchemaReferenceBuilder;
use JVBase\meta\Meta;
 
if (!defined('ABSPATH')) {
    exit;
}
 
/**
 * Resolver for LocalBusiness and its children (TattooParlor, FoodEstablishment, etc.)
 *
 * Auto-enrichment:
 * - Adds `employee` from associated content types (artists for a shop)
 * - Adds `makesOffer` from linked post types (services, styles)
 * - Resolves location from term meta if objectType is 'term'
 */
class LocalBusinessResolver extends BaseResolver
{
    public function getAutoFields(SchemaDefinition $definition): array
    {
        $fields = [];
 
        if (!$definition->objectId || !$definition->contentType) {
            return $fields;
        }
 
        $taxConfig = $this->getTaxonomyConfig($definition->contentType);
 
        if (empty($taxConfig)) {
            return $fields;
        }
 
        // Auto-include employees from associated content types
        if (!empty($taxConfig['for_content'])) {
            $employees = $this->buildEmployeeRefs($definition, $taxConfig['for_content']);
            if (!empty($employees)) {
                $fields['employee'] = $employees;
            }
        }
 
        return $fields;
    }
 
    /**
     * Build Person references for employees from associated post types.
     *
     * For a tattoo shop term, this finds all artists (posts) tagged with this shop.
     */
    private function buildEmployeeRefs(SchemaDefinition $definition, array $postTypes): array
    {
        $allRefs = [];
 
        foreach ($postTypes as $postType) {
            $fullType = str_starts_with($postType, BASE) ? $postType : BASE . $postType;
 
            $refs = SchemaReferenceBuilder::buildFromTerm(
                $definition->objectId,
                $fullType,
                10,
                null,
                true
            );
 
            if (!empty($refs)) {
                $allRefs = array_merge($allRefs, $refs);
            }
        }
 
        return $allRefs;
    }
 
    /**
     * Get taxonomy config from JVB_TAXONOMY constant.
     */
    private function getTaxonomyConfig(string $contentType): array
    {
        if (!defined('JVB_TAXONOMY')) {
            return [];
        }
 
        $slug = jvbNoBase($contentType);
 
        return JVB_TAXONOMY[$slug] ?? [];
    }
}