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

ListTextHandler::expand()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
c 5
b 0
f 0
dl 0
loc 24
rs 8.5125
cc 5
eloc 17
nc 4
nop 1
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