DefaultController.php in Feeds extensible parsers 8
File
src/Controller/DefaultController.php
View source
<?php
namespace Drupal\feeds_ex\Controller;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Controller\ControllerBase;
class DefaultController extends ControllerBase {
public function encodingAutocomplete($string = '') {
$matches = [];
if (!strlen($string) || Unicode::getStatus() != Unicode::STATUS_MULTIBYTE) {
drupal_json_output($matches);
return;
}
$added = array_map('trim', explode(',', $string));
$string = array_pop($added);
$lower_added = array_map('drupal_strtolower', $added);
$prefix = '';
$encodings = [];
foreach (mb_list_encodings() as $suggestion) {
if (in_array(mb_strtolower($suggestion), $lower_added)) {
$prefix .= $suggestion . ', ';
continue;
}
$encodings[] = $suggestion;
}
foreach ($encodings as $delta => $encoding) {
if (stripos($encoding, $string) !== 0) {
continue;
}
$matches[$prefix . $encoding] = Html::escape($encoding);
unset($encodings[$delta]);
}
foreach ($encodings as $encoding) {
if (stripos($encoding, $string) !== FALSE) {
$matches[$prefix . $encoding] = Html::escape($encoding);
}
}
$matches = array_slice($matches, 0, 10, TRUE);
drupal_json_output($matches);
}
}