You are here

public function FeedsExTextEncoder::configFormValidate in Feeds extensible parsers 7

Validates the encoding configuration form.

Parameters

array &$values: The form values.

Overrides FeedsExEncoderInterface::configFormValidate

File

src/Text/Utility.php, line 122
Contains FeedsExEncoderInterface and FeedsExTextEncoder.

Class

FeedsExTextEncoder
Generic text encoder.

Code

public function configFormValidate(array &$values) {
  if (!$this->isMultibyte) {
    return;
  }

  // Normalize encodings. Make them exactly as they are defined in
  // mb_list_encodings(), but maintain user-defined order.
  $encodings = array_map('strtolower', array_map('trim', explode(',', $values['source_encoding'])));
  $values['source_encoding'] = array();
  foreach (mb_list_encodings() as $encoding) {

    // Maintain order.
    $pos = array_search(strtolower($encoding), $encodings);
    if ($pos !== FALSE) {
      $values['source_encoding'][$pos] = $encoding;
    }
  }
  ksort($values['source_encoding']);

  // Make sure there's some value set.
  if (!$values['source_encoding']) {
    $values['source_encoding'][] = 'auto';
  }
}