You are here

public static function SchemaQuestionBase::testValue in Schema.org Metatag 8

Provide a test input value for the property that will validate.

Tags like @type that contain values other than simple strings, for instance a list of allowed options, should extend this method and return a valid value.

Value must be static so the test can retrieve the value without instantiating the class.

Return value

mixed Return the test value, either a string or array, depending on the property.

Overrides SchemaNameBase::testValue

File

src/Plugin/metatag/Tag/SchemaQuestionBase.php, line 39

Class

SchemaQuestionBase
Schema.org Question items should extend this class.

Namespace

Drupal\schema_metatag\Plugin\metatag\Tag

Code

public static function testValue() {
  $items = [];
  $keys = [
    '@type',
    'name',
    'text',
    'upvoteCount',
    'answerCount',
    'acceptedAnswer',
    'suggestedAnswer',
    'dateCreated',
    'author',
  ];
  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;
}