ListBooleanHandler::expand()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 4
nc 6
nop 1
1
<?php
2
3
namespace Drupal\Driver\Fields\Drupal7;
4
5
/**
6
 * ListBoolean field handler for Drupal 7.
7
 */
8
class ListBooleanHandler extends AbstractHandler {
9
10
  /**
11
   * {@inheritdoc}
12
   */
13
  public function expand($values) {
14
    $return = [];
15
    $allowed_values = $this->fieldInfo['settings']['allowed_values'];
16
    // If values are blank then use keys as value.
17
    foreach ($allowed_values as $key => $value) {
18
      if ($value == '') {
19
        $allowed_values[$key] = $key;
20
      }
21
    }
22
    $allowed_values = array_flip($allowed_values);
23
    foreach ($values as $value) {
24
      $return[$this->language][] = ['value' => $allowed_values[$value]];
25
    }
26
    return $return;
27
  }
28
29
}
30