Jump to:

5541 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Multiple ComplexTableFields in CMS

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

Page: 1
Go to End
Author Topic: 1459 Views
  • JGC
    Avatar
    Community Member
    25 Posts

    Multiple ComplexTableFields in CMS Link to this post

    http://doc.silverstripe.com/doku.php?id=complextablefield

    In the documentation for CTFs, they're all shown as using a parameter "MyName" (which goes where the relation name would go).

    I'm modifying the CMS and trying to get different Page Types to show different CTFs. Each Page Type has its own class which extends Page, and it's pulling in only one table with no relations, which has its own class which extends DataObject.

    Example:
    BandMembers.php - table

    <?php

    class BandMembers extends DataObject
    {
    public static $db = array
    (
    'BandFirstName' => 'Text',
    'BandFamilyName' => 'Text',
    'BandInstruments' => 'Text',
    'BandMemberBlurb' => 'Text'
    );

    public static $has_one = array();
    }

    class BandMembers_Controller extends ContentController
    {
    }

    AboutPage.php - About Page page type

    class AboutPage extends Page
    {

    ##
    ## Set up the database
    ##

    static $db = array
    (
    'BackgroundTitle' => 'Text',
    'BackgroundContent' => 'HTMLText',
    # Some more DB fields here, no name clashes or anything
    );

    function getCMSFields()
    {
    $fields = parent::getCMSFields();

    # Create Band Member management tab
    $showMembers = new ComplexTableField(
    $this,
    'MyName',
    'BandMembers',
    array(
    'BandFirstName' => 'Forename',
    'BandFamilyName' => 'Surname',
    'BandInstruments' => 'Instrument(s)'
    ),
    new FieldSet(
    new TextField('BandFirstName', 'Forename'),
    new TextField('BandFamilyName', 'Surname'),
    new TextField('BandInstruments', 'Instrument(s)'),
    new HTMLEditorField('BandMemberBlurb', 'Band Member Blurb')
    )
    );

    $showMembers->setPermissions(array(
    'add',
    'delete',
    'edit'
    ));

    $fields->addFieldToTab('Root.Content.BandMembers', $showMembers);
    return $fields;
    }

    The problem is I can only use "MyName" as a parameter for one Page Type like this - other Page Types using MyName will pull in this form. Using anything else gives a error of "I can't handle sub-URLs of a ... object" (Form, in this case).

    The member Dig here says he fixed it here:
    http://www.silverstripe.com/extending-hacking-silverstripe-forum/flat/245239
    "EDIT: I fixed it, I was being too clever and not constructing the full form if it wasn't being requested for displaying. Basically any path the exits early before creating the full form with the ComplexTableField in it will break it. Makes sense when you think about it!"

    I'd try to return a form, except I have to return a FieldSet for getCMSMethods.

    Any suggestions on how I can fix it to allow multiple CTFs with different tables?

    Each CTF only needs to show data from one table.

    Thanks in advance

  • JGC
    Avatar
    Community Member
    25 Posts

    Re: Multiple ComplexTableFields in CMS Link to this post

    Been trying to solve this for a while now, any ideas would be very much appreciated.

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Multiple ComplexTableFields in CMS Link to this post

    Hmm, not sure I'm really understanding you but in most of my cases I'd have a 'singular' named DataObject subclass (BandMember), which would lead to

    - where you have 'MyName' I'd have 'BandMembers' (the 'Name' of the table)
    - where you have 'BandMembers' I'd have 'BandMember' (the SourceClass).

    The BandMember class is dataobject and is 'one' item in the BandMembers ctf.

    Also, is there a specific reason why you're making a controller for the dataobject? (In most normal cases, dataobjects don't have a controller).

    1459 Views
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.