SchemaCountryTrait.php in Schema.org Metatag 8
File
src/Plugin/metatag/Tag/SchemaCountryTrait.php
View source
<?php
namespace Drupal\schema_metatag\Plugin\metatag\Tag;
trait SchemaCountryTrait {
use SchemaPivotTrait;
protected abstract function schemaMetatagManager();
public function countryForm($input_values) {
$input_values += $this
->schemaMetatagManager()
->defaultInputValues();
$value = $input_values['value'];
$selector = ':input[name="' . $input_values['visibility_selector'] . '[@type]"]';
$visibility = [
'invisible' => [
$selector => [
'value' => '',
],
],
];
$selector2 = $this
->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;
$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' => [
'Country' => $this
->t('Country'),
],
'#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("The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code."),
'#states' => $visibility,
];
return $form;
}
}