SchemaOfferBase.php in Schema.org Metatag 7
File
src/SchemaOfferBase.php
View source
<?php
class SchemaOfferBase extends SchemaNameBase {
use SchemaOfferTrait;
public function getForm(array $options = []) {
$value = $this
->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
->offerForm($input_values);
if (empty($this
->multiple())) {
unset($form['value']['pivot']);
}
$form['value']['#element_validate'][] = 'schema_metatag_element_validate';
return $form;
}
public static function testValue() {
$items = [];
$keys = [
'@type',
'@id',
'price',
'priceCurrency',
'lowPrice',
'highPrice',
'offerCount',
'url',
'availability',
'availabilityStarts',
'availabilityEnds',
'itemCondition',
'validFrom',
'category',
'eligibleRegion',
'ineligibleRegion',
'priceValidUntil',
];
foreach ($keys as $key) {
switch ($key) {
case '@type':
$items[$key] = 'Offer';
break;
case 'eligibleRegion':
case 'ineligibleRegion':
$items[$key] = SchemaCountryBase::testValue();
break;
default:
$items[$key] = parent::testDefaultValue(2, ' ');
break;
}
}
return $items;
}
public static function processedTestValue($items) {
foreach ($items as $key => $value) {
switch ($key) {
case 'eligibleRegion':
case 'ineligibleRegion':
$items[$key] = SchemaCountryBase::processedTestValue($items[$key]);
break;
}
}
return $items;
}
}