Problem/Motivation
author details is rendering as string instead of object, when we added FaqPage details in Schema.org: QAPage, FAQPage section with pivot option
Steps to reproduce
1. Goto Schema.org: QAPage, FAQPage section
2. Select FaqPag in @type dropdown
3. Select Question in @type of MainEntry
4. Select Pivot in pivot
5. add multiple questions separated by configured separator in name field
6. add multiple text separated by configured separator in text field
7. filled Author details in author field
and
8. Select answer in @type in acceptedAnswer
9. add multiple values separated by configured separator in text field
10. filled Author details in author field
and
11. Select answer in @type in suggestedAnswer
12. add multiple values separated by configured separator in text field
13. filled Author details in author field
Current Result
{
"@type": "FAQPage",
"@id": "https://abc.com/#faqtest",
"mainEntity": [
{
"@type": "Question",
"name": "full text of short form of question. This is question 1",
"text": "This is the full text of a long form of question 1",
"answerCount": "4",
"acceptedAnswer": {
"@type": "Answer",
"text": "This is the full text of answer 1",
"url": "https://abc.com",
"author": "Organization"
},
"author": "Organization"
},
{
"@type": "Question",
"name": "This is the full text of a short form of question 2",
"text": "This is the full text of a long form of question 2",
"answerCount": "4",
"acceptedAnswer": {
"@type": "Answer",
"text": "This is the full text of answer 2",
"url": "https://abc.com",
"author": "https://abc.com/#organization"
},
"author": "https://abc.com"
},
{
"@type": "Question",
"name": "This is the full text of a short form of question 3",
"text": "This is the full text of a long form of question 3",
"answerCount": "4",
"acceptedAnswer": {
"@type": "Answer",
"text": "This is the full text of answer 3",
"url": "https://abc.com",
"author": "XYZ"
},
"author": "XYZ"
},
{
"@type": "Question",
"name": "This is the full text of a short form of question 4?",
"text": "This is the full text of a long form of question 4?",
"answerCount": "4",
"acceptedAnswer": {
"@type": "Answer",
"text": "This is the full text of answer 4.",
"url": "https://abc.com",
"author": "https://abc.com"
},
"author": "https://abc.com"
}
]
},Expected Result
{
"@type": "FAQPage",
"@id": "https://abc.com/#faqtest",
"mainEntity": [
{
"@type": "Question",
"name": "full text of short form of question. This is question 1",
"text": "This is the full text of a long form of question 1",
"answerCount": "4",
"acceptedAnswer": {
"@type": "Answer",
"text": "This is the full text of answer 1",
"url": "https://abc.com",
"author": {
"@type": "Organization",
"@id": "https://abc.com/#organization",
"name": "XYZ",
"url": "https://abc.com"
}
},
"author": {
"@type": "Organization",
"@id": "https://abc.com",
"name": "XYZ",
"url": "https://abc.com"
}
},
{
"@type": "Question",
"name": "This is the full text of a short form of question 2",
"text": "This is the full text of a long form of question 2",
"answerCount": "4",
"acceptedAnswer": {
"@type": "Answer",
"text": "This is the full text of answer 2",
"url": "https://abc.com",
"author": {
"@type": "Organization",
"@id": "https://abc.com/#organization",
"name": "XYZ",
"url": "https://abc.com"
}
},
"author": {
"@type": "Organization",
"@id": "https://abc.com",
"name": "XYZ",
"url": "https://abc.com"
}
},
{
"@type": "Question",
"name": "This is the full text of a short form of question 3",
"text": "This is the full text of a long form of question 3",
"answerCount": "4",
"acceptedAnswer": {
"@type": "Answer",
"text": "This is the full text of answer 3",
"url": "https://abc.com",
"author": {
"@type": "Organization",
"@id": "https://abc.com/#organization",
"name": "XYZ",
"url": "https://abc.com"
}
},
"author": {
"@type": "Organization",
"@id": "https://abc.com",
"name": "XYZ",
"url": "https://abc.com"
}
},
{
"@type": "Question",
"name": "This is the full text of a short form of question 4?",
"text": "This is the full text of a long form of question 4?",
"answerCount": "4",
"acceptedAnswer": {
"@type": "Answer",
"text": "This is the full text of answer 4.",
"url": "https://abc.com",
"author": {
"@type": "Organization",
"@id": "https://abc.com/#organization",
"name": "XYZ",
"url": "https://abc.com"
}
},
"author": {
"@type": "Organization",
"@id": "https://abc.com",
"name": "XYZ",
"url": "https://abc.com"
}
}
]
},
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | schema_metatag_issue_3587378.patch | 1.17 KB | aadesh.verma |
Issue fork schema_metatag-3587378
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
aadesh.verma commentedComment #3
aadesh.verma commentedComment #5
aadesh.verma commentedI have created this patch and its working fine for me.
Comment #8
vaish commentedThis issue affects any property type that has another property with sub-properties nested 2 or more levels deep. I believe this is currently only Question property type which is responsible for QAPage and FAQPage. Question contains Answer, while Answer contains Author. All other property types I checked are not that deeply nested.
Pivot form element is added to the property form only if
multipleis set to TRUE on the metatag . In the case of Question property type we have metatagSchemaQAPageMainEntitywith multiple set to TRUE. While building the form for the Question property, when we get to the Answer, its parent (Question) will be checked for the value of multiple and Pivot form will be added as expected. However, because Author's parent is Answer and Answer doesn't have "multiple" value set at all, pivot form element won't be added to the Author element.If I enable Pivot on the Answer, then I will also want to enable Pivot on the Answer's Author. But Pivot form element is not present for the Author making this impossible and resulting in the incorrect output as illustrated in the issue description.
Solution is to ensure Pivot form element is added to all sub-properties of the parent that has Pivot element. This can be done by passing
multivalue to sub-properties while generating the form. Passing makes sense only if sub-property has its own sub-properties. MR following soon.Comment #10
vaish commentedComment #11
vaish commentedComment #12
vaish commentedI realized that Forms are currently not tested at all so I wasn't sure if it would makes sense to add only one covering this particular issue.
Instead, I added one more unit test for pivot() method that covers more complex case with nested array.
This test depends on unit tests being fixed in #3606525: Data provider methods must be static in PHPUnit 10 and newer