/**
  * Returns a readonly span containing the correct value.
  *
  * @param array $properties
  *
  * @return string
  */
 public function Field($properties = array())
 {
     $source = ArrayLib::flatten($this->getSource());
     $values = $this->getValueArray();
     // Get selected values
     $mapped = array();
     foreach ($values as $value) {
         if (isset($source[$value])) {
             $mapped[] = $source[$value];
         }
     }
     // Don't check if string arguments are matching against the source,
     // as they might be generated HTML diff views instead of the actual values
     if ($this->value && is_string($this->value) && empty($mapped)) {
         $mapped = array(trim($this->value));
         $values = array();
     }
     if ($mapped) {
         $attrValue = implode(', ', array_values($mapped));
         $attrValue = Convert::raw2xml($attrValue);
         $inputValue = implode(', ', array_values($values));
     } else {
         $attrValue = '<i>(' . _t('FormField.NONE', 'none') . ')</i>';
         $inputValue = '';
     }
     $properties = array_merge($properties, array('AttrValue' => DBField::create_field('HTMLFragment', $attrValue), 'InputValue' => $inputValue));
     return parent::Field($properties);
 }
 public function testFlatten()
 {
     $options = array('1' => 'one', '2' => 'two');
     $expected = $options;
     $this->assertEquals($expected, ArrayLib::flatten($options));
     $options = array('1' => array('2' => 'two', '3' => 'three'), '4' => 'four');
     $expected = array('2' => 'two', '3' => 'three', '4' => 'four');
     $this->assertEquals($expected, ArrayLib::flatten($options));
 }