You are here

public function MetatagViewsTranslationForm::form in Metatag 8

Add the translation form element for meta tags available in the source.

1 call to MetatagViewsTranslationForm::form()
MetatagViewsTranslationForm::buildForm in metatag_views/src/Form/MetatagViewsTranslationForm.php
Form constructor.

File

metatag_views/src/Form/MetatagViewsTranslationForm.php, line 196

Class

MetatagViewsTranslationForm
Defines a form for translating meta tags for views.

Namespace

Drupal\metatag_views\Form

Code

public function form(array $element, array $translated_values) {
  $translated_values = $this
    ->clearMetatagViewsDisallowedValues($translated_values);

  // Only offer form elements for tags present in the source language.
  $source_values = $this
    ->removeEmptyTags($this->baseData);

  // Add the outer fieldset.
  $element += [
    '#type' => 'details',
  ];
  $element += $this->tokenService
    ->tokenBrowser([
    'view',
  ]);
  foreach ($source_values as $tag_id => $value) {
    $tag = $this->tagPluginManager
      ->createInstance($tag_id);
    $tag
      ->setValue($translated_values[$tag_id]);
    $form_element = $tag
      ->form($element);
    $element[$tag_id] = [
      '#theme' => 'config_translation_manage_form_element',
      'source' => [
        '#type' => 'item',
        '#title' => $form_element['#title'],
        '#markup' => $value,
      ],
      'translation' => $form_element,
    ];
  }
  return $element;
}