You are here

public function TextEncoder::configFormValidate in Feeds extensible parsers 8

Validates the encoding configuration form.

Parameters

array &$values: The form values.

Overrides EncoderInterface::configFormValidate

File

src/Encoder/TextEncoder.php, line 75

Class

TextEncoder
Generic text encoder.

Namespace

Drupal\feeds_ex\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'] = [];
  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';
  }
}