You are here

trait MetatagViewsValuesCleanerTrait in Metatag 8

Collection of helper methods when handling raw tag values.

Hierarchy

2 files declare their use of MetatagViewsValuesCleanerTrait
MetatagViewsEditForm.php in metatag_views/src/Form/MetatagViewsEditForm.php
MetatagViewsTranslationForm.php in metatag_views/src/Form/MetatagViewsTranslationForm.php

File

metatag_views/src/MetatagViewsValuesCleanerTrait.php, line 8

Namespace

Drupal\metatag_views
View source
trait MetatagViewsValuesCleanerTrait {

  /**
   * Clears the metatag form state values from illegal elements.
   *
   * @param array $metatags
   *   Array of values to submit.
   *
   * @return array
   *   Filtered metatag array.
   */
  public function clearMetatagViewsDisallowedValues(array $metatags) {

    // Get all legal tags.
    $tags = $this->metatagManager
      ->sortedTags();

    // Return only common elements.
    $metatags = array_intersect_key($metatags, $tags);
    return $metatags;
  }

  /**
   * Removes tags that are empty.
   */
  public function removeEmptyTags($metatags) {
    $metatags = array_filter($metatags, function ($value) {
      if (is_array($value)) {
        return count(array_filter($value)) > 0;
      }
      else {
        return $value !== '';
      }
    });
    return $metatags;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MetatagViewsValuesCleanerTrait::clearMetatagViewsDisallowedValues public function Clears the metatag form state values from illegal elements.
MetatagViewsValuesCleanerTrait::removeEmptyTags public function Removes tags that are empty.