SchemaRatingBase.php in Schema.org Metatag 8
File
src/Plugin/metatag/Tag/SchemaRatingBase.php
View source
<?php
namespace Drupal\schema_metatag\Plugin\metatag\Tag;
class SchemaRatingBase extends SchemaNameBase {
use SchemaRatingTrait;
public function form(array $element = []) {
$value = $this
->schemaMetatagManager()
->unserialize($this
->value());
$input_values = [
'title' => $this
->label(),
'description' => $this
->description(),
'value' => $value,
'#required' => isset($element['#required']) ? $element['#required'] : FALSE,
'visibility_selector' => $this
->visibilitySelector(),
];
$form = parent::form($element);
$form = $this
->ratingForm($input_values);
if (empty($this
->multiple())) {
unset($form['pivot']);
}
return $form;
}
public static function testValue() {
$items = [];
$keys = [
'@type',
'ratingValue',
'bestRating',
'worstRating',
'ratingCount',
];
foreach ($keys as $key) {
switch ($key) {
case '@type':
$items[$key] = 'Rating';
break;
default:
$items[$key] = parent::testDefaultValue(2, ' ');
break;
}
}
return $items;
}
}