Skip to content
Snippets Groups Projects
Commit 9cc83bb5 authored by Karen Stevenson's avatar Karen Stevenson Committed by Karen Stevenson
Browse files

Issue #3040897 by KarenS: Add HowTo, FAQ, QA Page schemas (D7)

parent 50386edb
No related branches found
Tags 4.4.0
No related merge requests found
Showing
with 988 additions and 0 deletions
name = "Schema.org HowTo"
description = "Adds Schema.org/HowTo to the JSON LD array. Creates HowTo."
package = SEO
core = 7.x
dependencies[] = schema_metatag
files[] = src/SchemaHowToType.php
files[] = tests/SchemaMetatagHowToTest.test
<?php
/**
* @file
* Metatag integration for the schema_how_to module.
*/
/**
* Implements hook_metatag_info().
*/
function schema_how_to_metatag_info() {
$info['groups']['schema_how_to'] = array(
'label' => t('Schema.org: HowTo'),
'description' => t('See Schema.org definitions for this Schema type at <a href="!url">!url</a>, Google\'s recommendations at <a href="!google_url">!google_url</a>.', ['!url' => 'http://schema.org/HowTo', '!google_url' => 'https://developers.google.com/search/docs/data-types/how-to']),
'form' => array(
'#weight' => 10,
),
);
$weight = 10;
// Basic tags.
$defaults = array(
'class' => 'SchemaNameBase',
'group' => 'schema_how_to',
'form' => array(
'#type' => 'textfield',
),
);
$info['tags']['schema_how_to.@type'] = array(
'class' => 'SchemaHowToType',
'label' => t('@type'),
'description' => t("REQUIRED. The type of how-to."),
'multiple' => TRUE,
'weight' => ++$weight,
) + $defaults;
$info['tags']['schema_how_to.name'] = array(
'label' => t('text'),
'description' => t('REQUIRED BY GOOGLE. The title of the how-to. For example, "How to tie a tie".'),
'weight' => ++$weight,
) + $defaults;
$info['tags']['schema_how_to.step'] = array(
'class' => 'SchemaHowToStepBase',
'label' => t('name'),
'description' => t("REQUIRED BY GOOGLE. An array of HowToStep elements which comprise the full instructions of the how-to."),
'multiple' => TRUE,
'weight' => ++$weight,
) + $defaults;
$info['tags']['schema_how_to.description'] = array(
'label' => t('description'),
'description' => t('RECOMMENDED BY GOOGLE. A description of the how-to.'),
'weight' => ++$weight,
) + $defaults;
$info['tags']['schema_how_to.image'] = array(
'class' => 'SchemaImageBase',
'label' => t('image'),
'description' => t('RECOMMENDED BY GOOGLE. Image of the completed how-to.'),
'image' => TRUE,
'url' => TRUE,
'weight' => ++$weight,
) + $defaults;
$info['tags']['schema_how_to.estimatedCost'] = array(
'class' => 'SchemaMonetaryAmountBase',
'label' => t('estimatedCost'),
'description' => t('RECOMMENDED BY GOOGLE. The estimated cost of the supplies consumed when performing instructions.'),
'weight' => ++$weight,
) + $defaults;
$info['tags']['schema_how_to.supply'] = array(
'label' => t('supply'),
'description' => t("RECOMMENDED BY GOOGLE. A supply consumed when performing instructions or a direction."),
'multiple' => TRUE,
'weight' => ++$weight,
) + $defaults;
$info['tags']['schema_how_to.tool'] = array(
'label' => t('tool'),
'description' => t('RECOMMENDED BY GOOGLE. An object used (but not consumed) when performing instructions or a direction.'),
'multiple' => TRUE,
'weight' => ++$weight,
) + $defaults;
return $info;
}
<?php
/**
* @file
* Contains schema_how_to.module.
*/
/**
* Implements hook_ctools_plugin_api().
*/
function schema_how_to_ctools_plugin_api($owner, $api) {
if ($owner == 'metatag' && $api == 'metatag') {
return array('version' => 1);
}
}
<?php
/**
* Provides a plugin for the '@type' meta tag.
*/
class SchemaHowToType extends SchemaTypeBase {
/**
* {@inheritdoc}
*/
public static function labels() {
return [
'HowTo',
];
}
}
<?php
/**
* Tests that each of the Metatag schema_how_to tags work correctly.
*/
class SchemaMetatagHowToTest extends SchemaMetatagTagsTestBase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Schema Metatag: HowTo',
'description' => 'Test the schema_how_to meta tags.',
'group' => 'Schema Metatag',
'dependencies' => [
'ctools',
'token',
'metatag',
'schema_metatag',
'schema_how_to',
],
);
}
/**
* {@inheritdoc}
*/
public function setUp(array $modules = array()) {
$modules[] = 'schema_how_to';
parent::setUp($modules);
}
/**
* {@inheritdoc}
*/
public $moduleName = 'schema_how_to';
/**
* {@inheritdoc}
*/
public $schemaTags = [
'schema_how_to.@type' => 'SchemaHowToType',
'schema_how_to.name' => 'SchemaNameBase',
'schema_how_to.step' => 'SchemaHowToStepBase',
'schema_how_to.description' => 'SchemaNameBase',
'schema_how_to.image' => 'SchemaImageBase',
'schema_how_to.estimatedCost' => 'SchemaMonetaryAmountBase',
'schema_how_to.supply' => 'SchemaNameBase',
'schema_how_to.tool' => 'SchemaNameBase',
];
}
......@@ -70,6 +70,12 @@ files[] = src/SchemaContactPointBase.php
files[] = src/SchemaContactPointTrait.php
files[] = src/SchemaBrandBase.php
files[] = src/SchemaBrandTrait.php
files[] = src/SchemaHowToStepBase.php
files[] = src/SchemaHowToStepTrait.php
files[] = src/SchemaQuestionBase.php
files[] = src/SchemaQuestionTrait.php
files[] = src/SchemaAnswerBase.php
files[] = src/SchemaAnswerTrait.php
files[] = tests/schema_metatag.base.test
files[] = tests/schema_metatag.helper.test
......
name = "Schema.org QAPage"
description = "Adds Schema.org/QAPage and Schema.org/FAQPage to the JSON LD array. Creates QAPage and FAQPage."
package = SEO
core = 7.x
dependencies[] = schema_metatag
files[] = src/SchemaQAPageType.php
files[] = tests/SchemaMetatagQAPageTest.test
<?php
/**
* @file
* Metatag integration for the schema_qa_page module.
*/
/**
* Implements hook_metatag_info().
*/
function schema_qa_page_metatag_info() {
$info['groups']['schema_qa_page'] = array(
'label' => t('Schema.org: QAPage/FAQPage'),
'description' => t('See Schema.org definitions for this Schema type at <a href="!url">!url</a> and <a href="!url2">!url2</a>, Google\'s recommendations at <a href="!google_url">!google_url</a> and <a href="!google_url2">!google_url2</a>.', [
'!url' => 'http://schema.org/QAPage',
'!url2' => 'http://schema.org/FAQPage',
'!google_url' => 'https://developers.google.com/search/docs/data-types/qapage',
'!google_url2' => 'https://developers.google.com/search/docs/data-types/faqpage',
]),
'form' => array(
'#weight' => 10,
),
);
$weight = 10;
// Basic tags.
$defaults = array(
'class' => 'SchemaNameBase',
'group' => 'schema_qa_page',
'form' => array(
'#type' => 'textfield',
),
);
$info['tags']['schema_qa_page.@type'] = array(
'class' => 'SchemaQAPageType',
'label' => t('@type'),
'description' => t("REQUIRED. The type of object."),
'weight' => ++$weight,
) + $defaults;
$info['tags']['schema_qa_page.mainEntity'] = array(
'class' => 'SchemaQuestionBase',
'label' => t('text'),
'description' => t('REQUIRED BY GOOGLE. An array of Question elements which comprise the list of answered questions that this QAPage or FAQPage is about.'),
'multiple' => TRUE,
'weight' => ++$weight,
) + $defaults;
return $info;
}
<?php
/**
* @file
* Contains schema_qa_page.module.
*/
/**
* Implements hook_ctools_plugin_api().
*/
function schema_qa_page_ctools_plugin_api($owner, $api) {
if ($owner == 'metatag' && $api == 'metatag') {
return array('version' => 1);
}
}
<?php
/**
* Provides a plugin for the '@type' meta tag.
*/
class SchemaQAPageType extends SchemaTypeBase {
/**
* {@inheritdoc}
*/
public static function labels() {
return [
'QAPage',
'FAQPage',
];
}
}
<?php
/**
* Tests that each of the Metatag schema_qa_page tags work correctly.
*/
class SchemaMetatagQAPageTest extends SchemaMetatagTagsTestBase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Schema Metatag: QAPage/FAQPage',
'description' => 'Test the schema_qa_page meta tags.',
'group' => 'Schema Metatag',
'dependencies' => [
'ctools',
'token',
'metatag',
'schema_metatag',
'schema_qa_page',
],
);
}
/**
* {@inheritdoc}
*/
public function setUp(array $modules = array()) {
$modules[] = 'schema_qa_page';
parent::setUp($modules);
}
/**
* {@inheritdoc}
*/
public $moduleName = 'schema_qa_page';
/**
* {@inheritdoc}
*/
public $schemaTags = [
'schema_qa_page.@type' => 'SchemaQAPageType',
'schema_qa_page.mainEntity' => 'SchemaQuestionBase',
];
}
<?php
/**
* Schema.org Answer items should extend this class.
*/
class SchemaAnswerBase extends SchemaNameBase {
use SchemaAnswerTrait;
/**
* {@inheritdoc}
*/
public function getForm(array $options = []) {
$value = SchemaMetatagManager::unserialize($this->value());
$input_values = [
'title' => $this->label(),
'description' => $this->description(),
'value' => $value,
'#required' => isset($options['#required']) ? $options['#required'] : FALSE,
'visibility_selector' => $this->visibilitySelector(),
];
$form['value'] = $this->answerForm($input_values);
if (empty($this->multiple())) {
unset($form['value']['pivot']);
}
// Validation from parent::getForm() got wiped out, so add callback.
$form['value']['#element_validate'][] = 'schema_metatag_element_validate';
return $form;
}
/**
* {@inheritdoc}
*/
public static function testValue() {
$items = [];
$keys = self::answerFormKeys();
foreach ($keys as $key) {
switch ($key) {
case '@type':
$items[$key] = 'Answer';
break;
case 'author':
$items[$key] = SchemaPersonOrgBase::testValue();
break;
default:
$items[$key] = parent::testDefaultValue(1, '');
break;
}
}
return $items;
}
/**
* {@inheritdoc}
*/
public static function processedTestValue($items) {
foreach ($items as $key => $value) {
switch ($key) {
case 'author':
$items[$key] = SchemaPersonOrgBase::processedTestValue($items[$key]);
break;
}
}
return $items;
}
}
<?php
/**
* Schema.org Answer trait.
*/
trait SchemaAnswerTrait {
use SchemaPersonOrgTrait, SchemaPivotTrait {
SchemaPivotTrait::pivotForm insteadof SchemaPersonOrgTrait;
}
/**
* Form keys.
*/
public static function answerFormKeys() {
return [
'@type',
'text',
'url',
'upvoteCount',
'dateCreated',
'author',
];
}
/**
* The form element.
*/
public function answerForm($input_values) {
$input_values += SchemaMetatagManager::defaultInputValues();
$value = $input_values['value'];
// Get the id for the nested @type element.
$visibility_selector = $input_values['visibility_selector'];
$selector = ':input[name="' . $visibility_selector . '[@type]"]';
$visibility = ['invisible' => [$selector => ['value' => '']]];
$selector2 = SchemaMetatagManager::altSelector($selector);
$visibility2 = ['invisible' => [$selector2 => ['value' => '']]];
$visibility['invisible'] = [$visibility['invisible'], $visibility2['invisible']];
$form['#type'] = 'fieldset';
$form['#title'] = $input_values['title'];
$form['#description'] = $input_values['description'];
$form['#tree'] = TRUE;
// Add a pivot option to the form.
$form['pivot'] = $this->pivotForm($value);
$form['pivot']['#states'] = $visibility;
$form['@type'] = [
'#type' => 'select',
'#title' => $this->t('@type'),
'#default_value' => !empty($value['@type']) ? $value['@type'] : '',
'#empty_option' => t('- None -'),
'#empty_value' => '',
'#options' => [
'Answer' => $this->t('Answer'),
],
'#required' => $input_values['#required'],
'#weight' => -10,
];
$form['text'] = [
'#type' => 'textfield',
'#title' => $this->t('text'),
'#default_value' => !empty($value['text']) ? $value['text'] : '',
'#maxlength' => 255,
'#required' => $input_values['#required'],
'#description' => $this->t('REQUIRED BY GOOGLE. The full text of the answer.'),
];
$form['url'] = [
'#type' => 'textfield',
'#title' => $this->t('url'),
'#default_value' => !empty($value['url']) ? $value['url'] : '',
'#maxlength' => 255,
'#required' => $input_values['#required'],
'#description' => $this->t('STRONGLY RECOMMENDED BY GOOGLE. A URL that links directly to this answer.'),
];
$form['upvoteCount'] = [
'#type' => 'textfield',
'#title' => $this->t('upvoteCount'),
'#default_value' => !empty($value['upvoteCount']) ? $value['upvoteCount'] : '',
'#maxlength' => 255,
'#required' => $input_values['#required'],
'#description' => $this->t("RECOMMENDED BY GOOGLE. The total number of votes that this answer has received."),
];
$form['dateCreated'] = [
'#type' => 'textfield',
'#title' => $this->t('dateCreated'),
'#default_value' => !empty($value['dateCreated']) ? $value['dateCreated'] : '',
'#maxlength' => 255,
'#required' => $input_values['#required'],
'#description' => $this->t('RECOMMENDED BY GOOGLE. The date at which the answer was added to the page, in ISO-8601 format.'),
];
$input_values = [
'title' => $this->t('Author'),
'description' => 'RECOMMENDED BY GOOGLE. The author of the answer.',
'value' => !empty($value['author']) ? $value['author'] : [],
'#required' => isset($element['#required']) ? $element['#required'] : FALSE,
'visibility_selector' => $visibility_selector . '[author]',
];
$form['author'] = $this->personOrgForm($input_values);
$keys = static::answerFormKeys();
foreach ($keys as $key) {
if ($key != '@type') {
$form[$key]['#states'] = $visibility;
}
}
return $form;
}
}
<?php
/**
* Schema.org Step items should extend this class.
*/
class SchemaHowToStepBase extends SchemaNameBase {
use SchemaHowToStepTrait;
/**
* {@inheritdoc}
*/
public function getForm(array $options = []) {
$value = SchemaMetatagManager::unserialize($this->value());
$input_values = [
'title' => $this->label(),
'description' => $this->description(),
'value' => $value,
'#required' => isset($options['#required']) ? $options['#required'] : FALSE,
'visibility_selector' => $this->visibilitySelector(),
];
$form['value'] = $this->howToStepForm($input_values);
if (empty($this->multiple())) {
unset($form['value']['pivot']);
}
// Validation from parent::getForm() got wiped out, so add callback.
$form['value']['#element_validate'][] = 'schema_metatag_element_validate';
return $form;
}
/**
* {@inheritdoc}
*/
public static function testValue() {
$items = [];
$keys = self::howToStepFormKeys();
foreach ($keys as $key) {
switch ($key) {
case '@type':
$items[$key] = 'HowToStep';
break;
case 'image':
$items[$key] = SchemaImageBase::testValue();
break;
default:
$items[$key] = parent::testDefaultValue(1, '');
break;
}
}
return $items;
}
/**
* {@inheritdoc}
*/
public static function processedTestValue($items) {
foreach ($items as $key => $value) {
switch ($key) {
case 'image':
$items[$key] = SchemaImageBase::processedTestValue($items[$key]);
break;
}
}
return $items;
}
}
<?php
/**
* Schema.org HowToStep trait.
*/
trait SchemaHowToStepTrait {
use SchemaImageTrait, SchemaPivotTrait {
SchemaPivotTrait::pivotForm insteadof SchemaImageTrait;
}
/**
* Form keys.
*/
public static function howToStepFormKeys() {
return [
'@type',
'name',
'text',
'url',
'image',
];
}
/**
* The form element.
*/
public function howToStepForm($input_values) {
$input_values += SchemaMetatagManager::defaultInputValues();
$value = $input_values['value'];
// Get the id for the nested @type element.
$visibility_selector = $input_values['visibility_selector'];
$selector = ':input[name="' . $visibility_selector . '[@type]"]';
$visibility = ['invisible' => [$selector => ['value' => '']]];
$selector2 = SchemaMetatagManager::altSelector($selector);
$visibility2 = ['invisible' => [$selector2 => ['value' => '']]];
$visibility['invisible'] = [$visibility['invisible'], $visibility2['invisible']];
$form['#type'] = 'fieldset';
$form['#title'] = $input_values['title'];
$form['#description'] = $input_values['description'];
$form['#tree'] = TRUE;
// Add a pivot option to the form.
$form['pivot'] = $this->pivotForm($value);
$form['pivot']['#states'] = $visibility;
$form['@type'] = [
'#type' => 'select',
'#title' => $this->t('@type'),
'#default_value' => !empty($value['@type']) ? $value['@type'] : '',
'#empty_option' => t('- None -'),
'#empty_value' => '',
'#options' => [
'HowToStep' => $this->t('HowToStep'),
],
'#required' => $input_values['#required'],
'#weight' => -10,
];
$form['name'] = [
'#type' => 'textfield',
'#title' => $this->t('name'),
'#default_value' => !empty($value['name']) ? $value['name'] : '',
'#maxlength' => 255,
'#required' => $input_values['#required'],
'#description' => $this->t("RECOMMENDED BY GOOGLE. The word or short phrase summarizing the step (for example, \"Attach wires to post\" or \"Dig\"). Don't use non-descriptive text."),
];
$form['text'] = [
'#type' => 'textfield',
'#title' => $this->t('text'),
'#default_value' => !empty($value['text']) ? $value['text'] : '',
'#maxlength' => 255,
'#required' => $input_values['#required'],
'#description' => $this->t("REQUIRED BY GOOGLE. The full instruction text of this step."),
];
$form['url'] = [
'#type' => 'textfield',
'#title' => $this->t('url'),
'#default_value' => !empty($value['url']) ? $value['url'] : '',
'#maxlength' => 255,
'#required' => $input_values['#required'],
'#description' => $this->t('RECOMMENDED BY GOOGLE. A URL that directly links to the step (if one is available). For example, an anchor link fragment.'),
];
// Add nested objects.
$input_values = [
'title' => $this->t('image'),
'description' => 'RECOMMENDED BY GOOGLE. An image of the step.',
'value' => !empty($value['image']) ? $value['image'] : [],
'#required' => isset($element['#required']) ? $element['#required'] : FALSE,
'visibility_selector' => $visibility_selector . '[image]',
];
$form['image'] = $this->imageForm($input_values);
// Add visibility settings to hide fields when the type is empty.
$keys = static::howToStepFormKeys();
foreach ($keys as $key) {
if ($key != '@type') {
$form[$key]['#states'] = $visibility;
}
}
return $form;
}
}
<?php
/**
* Schema.org Question items should extend this class.
*/
class SchemaQuestionBase extends SchemaNameBase {
use SchemaQuestionTrait;
/**
* {@inheritdoc}
*/
public function getForm(array $options = []) {
$value = SchemaMetatagManager::unserialize($this->value());
$input_values = [
'title' => $this->label(),
'description' => $this->description(),
'value' => $value,
'#required' => isset($options['#required']) ? $options['#required'] : FALSE,
'visibility_selector' => $this->visibilitySelector(),
];
$form['value'] = $this->questionForm($input_values);
if (empty($this->multiple())) {
unset($form['value']['pivot']);
}
// Validation from parent::getForm() got wiped out, so add callback.
$form['value']['#element_validate'][] = 'schema_metatag_element_validate';
return $form;
}
/**
* {@inheritdoc}
*/
public static function testValue() {
$items = [];
$keys = self::questionFormKeys();
foreach ($keys as $key) {
switch ($key) {
case '@type':
$items[$key] = 'Question';
break;
case 'author':
$items[$key] = SchemaPersonOrgBase::testValue();
break;
case 'acceptedAnswer':
case 'suggestedAnswer':
$items[$key] = SchemaAnswerBase::testValue();
break;
default:
$items[$key] = parent::testDefaultValue(1, '');
break;
}
}
return $items;
}
/**
* {@inheritdoc}
*/
public static function processedTestValue($items) {
foreach ($items as $key => $value) {
switch ($key) {
case 'author':
$items[$key] = SchemaPersonOrgBase::processedTestValue($items[$key]);
break;
case 'acceptedAnswer':
case 'suggestedAnswer':
$items[$key] = SchemaAnswerBase::processedTestValue($items[$key]);
break;
}
}
return $items;
}
}
<?php
/**
* Schema.org Question trait.
*/
trait SchemaQuestionTrait {
use SchemaAnswerTrait, SchemaPersonOrgTrait, SchemaPivotTrait {
SchemaPersonOrgTrait::personOrgForm insteadof SchemaAnswerTrait;
SchemaPersonOrgTrait::personOrgFormKeys insteadof SchemaAnswerTrait;
SchemaPersonOrgTrait::imageForm insteadof SchemaAnswerTrait;
SchemaPersonOrgTrait::imageFormKeys insteadof SchemaAnswerTrait;
SchemaPivotTrait::pivotForm insteadof SchemaAnswerTrait;
SchemaPivotTrait::pivotForm insteadof SchemaPersonOrgTrait;
}
/**
* Form keys.
*/
public static function questionFormKeys() {
return [
'@type',
'name',
'text',
'upvoteCount',
'answerCount',
'acceptedAnswer',
'suggestedAnswer',
'dateCreated',
'author',
];
}
/**
* The form element.
*/
public function questionForm($input_values) {
$input_values += SchemaMetatagManager::defaultInputValues();
$value = $input_values['value'];
// Get the id for the nested @type element.
$visibility_selector = $input_values['visibility_selector'];
$selector = ':input[name="' . $visibility_selector . '[@type]"]';
$visibility = ['invisible' => [$selector => ['value' => '']]];
$selector2 = SchemaMetatagManager::altSelector($selector);
$visibility2 = ['invisible' => [$selector2 => ['value' => '']]];
$visibility['invisible'] = [$visibility['invisible'], $visibility2['invisible']];
$form['#type'] = 'fieldset';
$form['#title'] = $input_values['title'];
$form['#description'] = $input_values['description'];
$form['#tree'] = TRUE;
// Add a pivot option to the form.
$form['pivot'] = $this->pivotForm($value);
$form['pivot']['#states'] = $visibility;
$form['@type'] = [
'#type' => 'select',
'#title' => $this->t('@type'),
'#default_value' => !empty($value['@type']) ? $value['@type'] : '',
'#empty_option' => t('- None -'),
'#empty_value' => '',
'#options' => [
'Question' => $this->t('Question'),
],
'#required' => $input_values['#required'],
'#weight' => -10,
];
$form['name'] = [
'#type' => 'textfield',
'#title' => $this->t('name'),
'#default_value' => !empty($value['name']) ? $value['name'] : '',
'#maxlength' => 255,
'#required' => $input_values['#required'],
'#description' => $this->t('REQUIRED BY GOOGLE. The full text of the short form of the question. For example, "How many teaspoons in a cup?".'),
];
$form['text'] = [
'#type' => 'textfield',
'#title' => $this->t('text'),
'#default_value' => !empty($value['text']) ? $value['text'] : '',
'#maxlength' => 255,
'#required' => $input_values['#required'],
'#description' => $this->t('RECOMMENDED BY GOOGLE. The full text of the long form of the question.'),
];
$form['upvoteCount'] = [
'#type' => 'textfield',
'#title' => $this->t('upvoteCount'),
'#default_value' => !empty($value['upvoteCount']) ? $value['upvoteCount'] : '',
'#maxlength' => 255,
'#required' => $input_values['#required'],
'#description' => $this->t("RECOMMENDED BY GOOGLE. The total number of votes that this question has received."),
];
$form['answerCount'] = [
'#type' => 'textfield',
'#title' => $this->t('answerCount'),
'#default_value' => !empty($value['answerCount']) ? $value['answerCount'] : '',
'#maxlength' => 255,
'#required' => $input_values['#required'],
'#description' => $this->t("REQUIRED BY GOOGLE. The total number of answers to the question. This may also be 0 for questions with no answers."),
];
$form['dateCreated'] = [
'#type' => 'textfield',
'#title' => $this->t('dateCreated'),
'#default_value' => !empty($value['dateCreated']) ? $value['dateCreated'] : '',
'#maxlength' => 255,
'#required' => $input_values['#required'],
'#description' => $this->t('RECOMMENDED BY GOOGLE. The date at which the question was added to the page, in ISO-8601 format.'),
];
// Add nested objects.
$input_values = [
'title' => $this->t('acceptedAnswer'),
'description' => 'A top answer to the question. There can be zero or more of these per question. Either acceptedAnswer OR suggestedAnswer is REQUIRED BY GOOGLE.',
'value' => !empty($value['acceptedAnswer']) ? $value['acceptedAnswer'] : [],
'#required' => isset($element['#required']) ? $element['#required'] : FALSE,
'visibility_selector' => $visibility_selector . '[acceptedAnswer]',
];
$form['acceptedAnswer'] = $this->answerForm($input_values);
$input_values = [
'title' => $this->t('suggestedAnswer'),
'description' => 'One possible answer, but not accepted as a top answer (acceptedAnswer). There can be zero or more of these per Question. Either acceptedAnswer OR suggestedAnswer is REQUIRED BY GOOGLE.',
'value' => !empty($value['suggestedAnswer']) ? $value['suggestedAnswer'] : [],
'#required' => isset($element['#required']) ? $element['#required'] : FALSE,
'visibility_selector' => $visibility_selector . '[suggestedAnswer]',
];
$form['suggestedAnswer'] = $this->answerForm($input_values);
$input_values = [
'title' => $this->t('Author'),
'description' => 'RECOMMENDED BY GOOGLE. The author of the question.',
'value' => !empty($value['author']) ? $value['author'] : [],
'#required' => isset($element['#required']) ? $element['#required'] : FALSE,
'visibility_selector' => $visibility_selector . '[author]',
];
$form['author'] = $this->personOrgForm($input_values);
// Add visibility settings to hide fields when the type is empty.
$keys = static::questionFormKeys();
foreach ($keys as $key) {
if ($key != '@type') {
$form[$key]['#states'] = $visibility;
}
}
return $form;
}
}
......@@ -70,6 +70,9 @@ class SchemaMetatagTagsTest extends SchemaMetatagTagsTestBase {
'schema_metatag_test.contactPoint' => 'SchemaContactPointBase',
'schema_metatag_test.speakable' => 'SchemaSpeakableBase',
'schema_metatag_test.idReference' => 'SchemaIdReferenceBase',
'schema_metatag_test.step' => 'SchemaHowToStepBase',
'schema_metatag_test.question' => 'SchemaQuestionBase',
'schema_metatag_test.answer' => 'SchemaAnswerBase',
];
}
<?php
/**
* @file
* Metatag integration for the tests.
*/
/**
* Implements hook_metatag_info().
*/
......@@ -229,5 +234,26 @@ function schema_metatag_test_metatag_info() {
'weight' => ++$weight,
) + $defaults;
$info['tags']['schema_metatag_test.step'] = array(
'class' => 'SchemaHowToStepBase',
'label' => t('step'),
'description' => '',
'weight' => ++$weight,
) + $defaults;
$info['tags']['schema_metatag_test.question'] = array(
'class' => 'SchemaQuestionBase',
'label' => t('question'),
'description' => '',
'weight' => ++$weight,
) + $defaults;
$info['tags']['schema_metatag_test.answer'] = array(
'class' => 'SchemaAnswerBase',
'label' => t('answer'),
'description' => '',
'weight' => ++$weight,
) + $defaults;
return $info;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment