Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / metatag / metatag_views / src / MetatagViewsValuesCleanerTrait.php
1 <?php
2
3 namespace Drupal\metatag_views;
4
5 /**
6  * Collection of helper methods when handling raw tag values.
7  */
8 trait MetatagViewsValuesCleanerTrait {
9
10   /**
11    * Clears the metatag form state values from illegal elements.
12    *
13    * @param array $metatags
14    *   Array of values to submit.
15    *
16    * @return array
17    *   Filtered metatag array.
18    */
19   public function clearMetatagViewsDisallowedValues(array $metatags) {
20     // Get all legal tags.
21     $tags = $this->metatagManager->sortedTags();
22
23     // Return only common elements.
24     $metatags = array_intersect_key($metatags, $tags);
25
26     return $metatags;
27   }
28
29   /**
30    * Removes tags that are empty.
31    */
32   public function removeEmptyTags($metatags) {
33     $metatags = array_filter($metatags, function ($value) {
34       if (is_array($value)) {
35         return count(array_filter($value)) > 0;
36       }
37       else {
38         return $value !== '';
39       }
40     });
41     return $metatags;
42   }
43
44 }