You are here

public function MetatagViewsEditForm::form in Metatag 8

File

metatag_views/src/Form/MetatagViewsEditForm.php, line 113

Class

MetatagViewsEditForm
Class MetatagViewsEditForm.

Namespace

Drupal\metatag_views\Form

Code

public function form(array $values, array $element, array $token_types = [], array $included_groups = NULL, array $included_tags = NULL, $verbose_help = FALSE) {

  // Add the outer fieldset.
  $element += [
    '#type' => 'details',
  ];
  $element += $this->tokenService
    ->tokenBrowser($token_types, $verbose_help);
  $groups_and_tags = $this
    ->sortedGroupsWithTags();
  $first = TRUE;
  foreach ($groups_and_tags as $group_id => $group) {

    // Only act on groups that have tags and are in the list of included
    // groups (unless that list is null).
    if (isset($group['tags']) && (is_null($included_groups) || in_array($group_id, $included_groups))) {

      // Create the fieldset.
      $element[$group_id]['#type'] = 'details';
      $element[$group_id]['#title'] = $group['label'];
      $element[$group_id]['#description'] = $group['description'];
      $element[$group_id]['#open'] = $first;
      $first = FALSE;
      foreach ($group['tags'] as $tag_id => $tag) {

        // Only act on tags in the included tags list, unless that is null.
        if (is_null($included_tags) || in_array($tag_id, $included_tags)) {

          // Make an instance of the tag.
          $tag = $this->tagPluginManager
            ->createInstance($tag_id);

          // Set the value to the stored value, if any.
          $tag_value = isset($values[$tag_id]) ? $values[$tag_id] : NULL;
          $tag
            ->setValue($tag_value);

          // Create the bit of form for this tag.
          $element[$group_id][$tag_id] = $tag
            ->form($element);
        }
      }
    }
  }
  return $element;
}