You are here

public function SchemaImageTrait::imageForm in Schema.org Metatag 8

The form element.

5 calls to SchemaImageTrait::imageForm()
SchemaBrandTrait::brandForm in src/Plugin/metatag/Tag/SchemaBrandTrait.php
The form elements.
SchemaHowToStepTrait::howToStepForm in src/Plugin/metatag/Tag/SchemaHowToStepTrait.php
The form element.
SchemaImageBase::form in src/Plugin/metatag/Tag/SchemaImageBase.php
Generate a form element for this meta tag.
SchemaPersonOrgTrait::personOrgForm in src/Plugin/metatag/Tag/SchemaPersonOrgTrait.php
The form element.
SchemaProgramMembershipTrait::programMembershipForm in src/Plugin/metatag/Tag/SchemaProgramMembershipTrait.php
The form element.

File

src/Plugin/metatag/Tag/SchemaImageTrait.php, line 23

Class

SchemaImageTrait
Schema.org Image trait.

Namespace

Drupal\schema_metatag\Plugin\metatag\Tag

Code

public function imageForm($input_values) {
  $input_values += $this
    ->schemaMetatagManager()
    ->defaultInputValues();
  $value = $input_values['value'];

  // Get the id for the nested @type element.
  $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;

  // 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' => [
      'ImageObject' => $this
        ->t('ImageObject'),
    ],
    '#required' => $input_values['#required'],
    '#weight' => -10,
  ];
  $form['representativeOfPage'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('representative Of Page'),
    '#empty_option' => t('False'),
    '#empty_value' => '',
    '#options' => [
      'True' => 'True',
    ],
    '#default_value' => !empty($value['representativeOfPage']) ? $value['representativeOfPage'] : '',
    '#required' => $input_values['#required'],
    '#description' => $this
      ->t('Whether this image is representative of the content of the page.'),
    '#states' => $visibility,
  ];
  $form['url'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('url'),
    '#default_value' => !empty($value['url']) ? $value['url'] : '',
    '#maxlength' => 255,
    '#required' => $input_values['#required'],
    '#description' => $this
      ->t('Absolute URL of the image, i.e. [node:field_name:image_preset_name:url].'),
    '#states' => $visibility,
  ];
  $form['width'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('width'),
    '#default_value' => !empty($value['width']) ? $value['width'] : '',
    '#maxlength' => 255,
    '#required' => $input_values['#required'],
    '#states' => $visibility,
  ];
  $form['height'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('height'),
    '#default_value' => !empty($value['height']) ? $value['height'] : '',
    '#maxlength' => 255,
    '#required' => $input_values['#required'],
    '#states' => $visibility,
  ];
  return $form;
}