trait MetatagViewsValuesCleanerTrait in Metatag 8
Collection of helper methods when handling raw tag values.
Hierarchy
- trait \Drupal\metatag_views\MetatagViewsValuesCleanerTrait
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_viewsView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MetatagViewsValuesCleanerTrait:: |
public | function | Clears the metatag form state values from illegal elements. | |
MetatagViewsValuesCleanerTrait:: |
public | function | Removes tags that are empty. |