Search

A couple of questions of curiosity in terms of how Symphony chooses to order Select Box field lists -

  • In my install I notice Select Box field items are listed reverse (descending) alphabetically (or at least that what they appear to be; they may also be sorted by descending System ID since I created them alphabetically.) Is there a way to force the sort of select boxes to something else like ascending alphabetically?

  • When I set a Select Box field to show in the main entries list I can't discern any consistent pattern to how it is choosing displaying the field content. It doesn't appear to be alphabetical or otherwise (see image 02). Is there any way to elect that these are also displayed alphabetically?

Best, Clayton

I don't have a definitive answer, but since you asked:

<xsl:sort select="clayton" />

It's kind of odd that it is in reverse, but I don't think it is possible to have the select box refer to the section's sort.

> <xsl:sort select="clayton" />

Thanks! Surprisingly, that did wonders for some old childhood issues, but the select boxes still look amiss ;)

> I don't think it is possible to have the select box refer to the section's sort.

I thought at first they might be defaulting to creation / System ID order but it looks like new ones are placed alphabetically just displayed reverse instead of ascending. What's more odd is the seemingly random order that they're displayed in within the main menu list (image 02).

I wonder if this is a switch you can throw within any a core Symphony file?

Try tweaking line 133 of symphony/lib/toolkit/fields/field.select.php:

$sql = "SELECT DISTINCT `value` FROM `sym_entries_data_".$this->get('dynamic_options')."`
ORDER BY `value` DESC";

Change DESC to ASC. Also, you could order by entry_id to get the order they were added. And finally you can always do your own sorting once the data is out of the DB. Use ksort() or sort() just after the next line, 136, which contains the array_merge()

Hope that helps.

Hope that helps.

Now that's helpful! Thanks Alistair. I really love how fields are implemented in Symphony 2.

Try tweaking line 133 of symphony/lib/toolkit/fields/field.select.php

Perfect. Thanks Alistair. I'll try that out.

Alistair, your suggestion to change the DESC value to ASC in the field.select.php file fixed the sorting in the select box in the actual entry. However, trying to apply the sort() function to the array_merge() doesn't seem to work in sorting those values like in clayton's 2nd image example in his first post. is line 136 supposed to be where that displays those values?

Try using the sort() function on the $values variable, line 144. Something like:

    function prepareTableValue($data, XMLElement $link=NULL){
        $value = $data['value'];

        if(!is_array($value)) $value = array($value);

        sort($value);

        return parent::prepareTableValue(array('value' => General::sanitize(@implode(', ', $value))), $link);
    }

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details