Completed
Push — master ( 9f3a36...d17503 )
by Jonathan
8s
created

ListTextHandler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B expand() 0 24 5
1
<?php
2
3
/**
4
 * @file
5
 * Contains \Drupal\Driver\Fields\Drupal7\ListTextHandler.
6
 */
7
8
namespace Drupal\Driver\Fields\Drupal7;
9
10
/**
11
 * ListText field handler for Drupal 7.
12
 */
13
class ListTextHandler extends AbstractHandler {
14
15
  /**
16
   * {@inheritdoc}
17
   */
18
  public function expand($values) {
19
    $return = array();
20
    if (!empty($this->fieldInfo['settings']['allowed_values_function'])) {
21
      $cacheable = TRUE;
22
      $callback = $this->fieldInfo['settings']['allowed_values_function'];
23
      $allowed_values = call_user_func($callback, $this->fieldInfo, $this, $this->entityType, $this->entity, $cacheable);
24
    }
25
    else {
26
      $allowed_values = array();
27
      $options = array_flip($this->fieldInfo['settings']['allowed_values']);
28
      foreach ($values as $value) {
29
        if (array_key_exists($value, $options)) {
30
          $allowed_values[$value] = $options[$value];
31
        }
32
        else {
33
          $allowed_values[$value] = $value;
34
        }
35
      }
36
    }
37
    foreach ($values as $value) {
38
      $return[$this->language][] = array('value' => $allowed_values[$value]);
39
    }
40
    return $return;
41
  }
42
43
}
44