protected function applySorting(array $auxDate, array &$data): void
    {
        // Sort array
        switch ($this->get('sortBy')) {
            default:
            case 'name_asc':
                uksort($this->images, 'basename_natcasecmp');
                break;

            case 'name_desc':
                uksort($this->images, 'basename_natcasercmp');
                break;

            case 'date_asc':
                array_multisort($this->images, SORT_NUMERIC, $auxDate, SORT_ASC);
                break;

            case 'date_desc':
                array_multisort($this->images, SORT_NUMERIC, $auxDate, SORT_DESC);
                break;

            // Deprecated since Contao 4.0, to be removed in Contao 5.0
            case 'meta':
                // @codingStandardsIgnoreStart
                @trigger_error(
                    'The "meta" key in ContentGallery::compile() has been deprecated and will no longer work in Contao 5.0.',
                    E_USER_DEPRECATED
                );
            // @codingStandardsIgnoreEnd

            // no break here. Handle meta the same as custom.
            case 'custom':
                $this->applyCustomSorting();
                break;

            case 'random':
                shuffle($this->images);
                $data['isRandomOrder'] = true;
                break;
        }

        $this->images = array_values($this->images);
    }