schemaType, self::ENTITY_TYPES)) { return $fields; } $mainEntity = $this->buildMainEntity($definition); if (!empty($mainEntity)) { $fields['mainEntity'] = $mainEntity; } return $fields; } /** * Build mainEntity from the archive's posts. */ private function buildMainEntity(SchemaDefinition $definition): ?array { // Term archive (e.g., /tattoo-style/american-traditional/) if ($definition->objectType === 'term' && $definition->objectId) { return $this->buildFromTerm($definition); } // Post type archive (e.g., /tattoos/) if ($definition->objectType === 'archive' && $definition->contentType) { return SchemaReferenceBuilder::buildFromArchive($definition->contentType); } return null; } /** * Build mainEntity from a taxonomy term's associated posts. */ private function buildFromTerm(SchemaDefinition $definition): ?array { if (!defined('JVB_TAXONOMY') || !$definition->contentType) { return null; } $slug = jvbNoBase($definition->contentType); $taxConfig = JVB_TAXONOMY[$slug] ?? []; if (empty($taxConfig['for_content'])) { return null; } // Use the first associated post type $postType = $taxConfig['for_content'][0]; $fullType = str_starts_with($postType, BASE) ? $postType : BASE . $postType; return SchemaReferenceBuilder::buildFromTerm( $definition->objectId, $fullType, 10, null, true ); } }