diff --git a/src/Plugin/Field/FieldWidget/WidgetBase.php b/src/Plugin/Field/FieldWidget/WidgetBase.php index cc59173..b5828e4 100644 --- a/src/Plugin/Field/FieldWidget/WidgetBase.php +++ b/src/Plugin/Field/FieldWidget/WidgetBase.php @@ -172,6 +172,13 @@ abstract class WidgetBase extends CoreWidgetBase { return $element; } + /** + * Remove accents before sorting. + */ + private function removeAccents($string) { + return strtolower(trim(preg_replace('~[^0-9a-z]+~i', '-', preg_replace('~&([a-z]{1,2})(acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i', '$1', htmlentities($string, ENT_QUOTES, 'UTF-8'))), ' ')); + } + /** * Adds the available options to the select or other element. * @@ -184,10 +191,16 @@ abstract class WidgetBase extends CoreWidgetBase { private function sortOptions($options) { if ($direction = $this->getSetting('sort_options')) { if ($direction === 'ASC') { - uasort($options, 'strcasecmp'); + uasort($options, function ($a, $b) { + $a = $this->removeAccents($a); + $b = $this->removeAccents($b); + return 1 * strcasecmp($a, $b); + }); } elseif ($direction === 'DESC') { uasort($options, function ($a, $b) { + $a = $this->removeAccents($a); + $b = $this->removeAccents($b); return -1 * strcasecmp($a, $b); }); }