TaxonomyHandler   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 0
cbo 0
dl 0
loc 31
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B expand() 0 24 6
1
<?php
2
3
namespace Drupal\Driver\Fields\Drupal6;
4
5
use Drupal\Driver\Fields\FieldHandlerInterface;
6
7
/**
8
 * Provides a custom field handler to make it easier to include taxonomy terms.
9
 */
10
class TaxonomyHandler implements FieldHandlerInterface {
11
12
  /**
13
   * {@inheritdoc}
14
   */
15
  public function expand($values) {
16
    $result = [];
17
    $values = (array) $values;
18
    foreach ($values as $entry) {
19
      $terms = explode(',', $entry);
20
      foreach ($terms as $term) {
21
        // Try to split things out in order to find optional specified vocabs.
22
        $term_name_or_tid = '';
23
        $parts = explode(':', $term);
24
        if (count($parts) == 1) {
25
          $term_name_or_tid = $term;
26
        }
27
        elseif (count($parts) == 2) {
28
          $term_name_or_tid = $term;
29
        }
30
        if ($term_list = taxonomy_get_term_by_name($term_name_or_tid)) {
31
          $term = reset($term_list);
32
          $result[] = $term;
33
        }
34
      }
35
    }
36
37
    return $result;
38
  }
39
40
}
41