brotkrueml / schema

TYPO3 extension providing an API and view helpers for schema.org markup

Home Page:https://extensions.typo3.org/extension/schema

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for multiple subtypes in TypoScript cObject

Patta opened this issue · comments

Is your feature request related to a problem? Please describe.

Want to use typoscript to define multiple offers, e.g. for an event.

This should be generated (detailed properties omitted):

<script type="application/ld+json">
    {
        "@context": "https://schema.org/",
        "@type": "Event",
        "offers": [{
            "@type": "Offer",
            "name": "Ticket 1",
            "price":"80",
            "priceCurrency":"EUR"
        },{
            "@type": "Offer",
            "name": "Ticket 2",
            "price":"120",
            "priceCurrency":"EUR"
        }]
    }
</script>

Describe the solution you'd like

I have tried that, but it does not work:

page.20 = SCHEMA
page.20 {
    type = Event
    properties {
        name = Testevent

        offers = SCHEMA
        offers {
            1 {
                type = Offer
                properties {
                    name = Ticket 1
                    price = 80
                    priceCurrency = EUR
                }
            }
            2 {
                type = Offer
                properties {
                    name = Ticket 2
                    price = 120
                    priceCurrency = EUR
                }
            }
        }
    }
}

That neither, offer 2 overwrites offer 1:

page.20 = SCHEMA
page.20 {
    type = Event
    properties {
        name = Testevent

        offers = SCHEMA
        offers {
            type = Offer
            properties {
                name = Ticket 1
                price = 80
                priceCurrency = EUR
            }
        }
        offers = SCHEMA
        offers {
            type = Offer
            properties {
                name = Ticket 2
                price = 120
                priceCurrency = EUR
            }
        }
    }
}

That neither, typeerror (Brotkrueml\Schema\TypoScript\PropertiesAdder::addProperty(): Argument #2 ($name) must be of type string, int given, called in /var/www/html/vendor/brotkrueml/schema/Classes/TypoScript/PropertiesAdder.php on line 54)

page.20 = SCHEMA
page.20 {
    type = Event
    properties {
        name = Testevent

        offers = SCHEMA
        offers {
            type = Offer
            properties {
                1 = SCHEMA
                1 {
                    type = Offer
                    properties {
                        name = Ticket 1
                        price = 80
                        priceCurrency = EUR
                    }
                }
                2 = SCHEMA
                2 {
                    type = Offer
                    properties {
                        name = Ticket 2
                        price = 120
                        priceCurrency = EUR
                    }
                }
            }
        }
    }
}

Describe alternatives you've considered

Conversation with @brotkrueml at slack channel:
https://typo3.slack.com/archives/CV36M73D5/p1694073471419259

Additional context

Class "TypoScriptToSchema" is the starting point.

@Patta Thanks for the feature request. AFAIK the structured data is added to the schema manager immediately when the cObj is executed. So there seems to be some quite work to be done to get it in. An idea: return schema type models back as long as the cObj is a sub-cObj. Then it has to be determined when the outer-most SCHEMA cObj is reached to add it to the schema manager.

I am now adding the event schema markup with fluid viewhelpers and data from typoscript constants. I think its only needed to add the typoscript subtype limitation to the typoscript documentation.

closing the issue as it is no longer relevant to me. thank you for your work!