Jump to:

5539 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » sourceFilter and sourceSort not working in ComplexTableField? (2.4.0)

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1012 Views
  • Laurie
    Community Member
    21 Posts

    sourceFilter and sourceSort not working in ComplexTableField? (2.4.0) Link to this post

    I'm trying to include a "highlights" box (think announcements or news items) on several pages on my site.

    The rules are that...
    - A highlight may appear only on the home page.
    - A highlight may appear on the home page and one or more practice area pages.
    - A highlight may appear on one or more practice area pages without appearing on the home page.

    I have created a Highlight class which extends DataObject.

    As part of that class there is a boolean variable for whether or not the item should appear on the home page.

    In addition a highlight has a many-to-many relationship with the different practice areas included on the site.

    For example, if we were to win a contract dealing with gender equity in education an announcement of that contract might appear on the home page, the gender page, and the education page.

    For each applicable page type (i.e., home and practice area) I would like the highlights tab in the CMS to only show highlights that will appear on the particular page. So, I need to filter all highlights for just the applicable highlights on any given page.

    My understanding of how to do this is to include the $sourceFilter and $sourceSort as part of my ComplexTableField.

    However, it seems like $sourceSort is being used for the WHERE clause of the query and $sourceSort is being totally ignored.

    Here is the code I'm using to try and create the tab as desired:


    class HomePage extends Page {
       static $db = array (
       function getCMSFields() {
          $fields = parent::getCMSFields();
          $highlightsTable = new ComplexTableField (
             $controller = $this,
             $name = 'HomePageHighlights',
             $sourceClass = 'Highlight',
             $fieldList = array(
                'StartDate'=>'Start Date',
             $sourceFilter = 'HomePage = 1',
             $sourceSort = 'startDate DESC'
          $fields -> addFieldToTab('Root.Content.Highlights', $highlightsTable);
          return $fields;
    class HomePage_Controller extends Page_Controller {
       function HomePageHighlights() {
          $now = date('Y-m-d');
          $where = "startDate <= '$now' AND endDate > '$now' AND homePage = 1";
          return DataObject::get('Highlight', $where, 'startDate DESC');

    However, this is producing the following error in my SilverStripe log:

    [01-Jun-2010 09:18:32] Error at \sapphire\core\model\MySQLDatabase.php line 536: Couldn't run query:
    SELECT "Highlight"."ClassName", "Highlight"."Created", "Highlight"."LastEdited", "Highlight"."Headline", "Highlight"."Blurb", "Highlight"."Link", "Highlight"."StartDate", "Highlight"."EndDate", "Highlight"."HomePage", "Highlight"."ID", CASE WHEN "Highlight"."ClassName" IS NOT NULL THEN "Highlight"."ClassName" ELSE 'Highlight' END AS "RecordClassName"
    FROM "Highlight"
    WHERE (startDate DESC)

    Based on the error it looks like $sourceSort is being used where $sourceFilter should appear in the WHERE clause and no ORDER BY clause is being included at all.

    Any insight would be most appreciated. Thanks.


Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.