editing many many extra fields

628 views
Skip to first unread message

Nicolaas Thiemen Francken - Sunny Side Up

unread,
Aug 17, 2011, 11:46:08 PM8/17/11
to silverstripe-dev
does anyone know a nice solution for editing many many extra fields?

thank you

--
Nicolaas 

Rodney Way

unread,
Aug 18, 2011, 12:02:51 AM8/18/11
to silverst...@googlegroups.com
Hi Nicolaas,

Andrew Short's itemsetfield module handles this nicely - https://github.com/ajshort/silverstripe-itemsetfield

Cheers,

Rodney.
--
You received this message because you are subscribed to the Google Groups "SilverStripe Core Development" group.
To post to this group, send email to silverst...@googlegroups.com.
To unsubscribe from this group, send email to silverstripe-d...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/silverstripe-dev?hl=en.

Nicolaas Thiemen Francken - Sunny Side Up

unread,
Aug 18, 2011, 12:26:48 AM8/18/11
to silverst...@googlegroups.com
Rodney.... THANK YOU!

Rodney Way

unread,
Aug 18, 2011, 1:11:44 AM8/18/11
to silverst...@googlegroups.com
Nah - thanks Andrew :)

On 18/08/11 14:26, Nicolaas Thiemen Francken - Sunny Side Up wrote:
Rodney.... THANK YOU!

Nicolaas Thiemen Francken - Sunny Side Up

unread,
Aug 18, 2011, 1:18:36 AM8/18/11
to silverst...@googlegroups.com
Hi Rodney

I just installed this module and I cant get it to work....  I can select many many relationships, but I cant seem to edit (or view) any of the "extra" fields.

Any hints?

Nicolaas

Rodney Way

unread,
Aug 18, 2011, 1:47:05 AM8/18/11
to silverst...@googlegroups.com
Check out the module docs (docs/en/index.md) - my guess is you'll be looking for the ManyManyPickerField...

Basically you'll need to update getCMSFields() on the DataObject declaring the many_many_extraFields - and add a function to the DataObject with the $belongs_many_many to return the actual picker field.

Here's an example from one of my sites; where the many_many is between AFLMatch & AFLPlayer. Essentially the example provides a 'Give votes to Player per Match' interface. Votes is the conceptual 'extra field' that goes into the join table.


HTH,

Rod.

   
   // AFLMatch

    public static $many_many = array(
        'Votes'        => 'AFLPlayer'
    );
   
    public static $many_many_extraFields = array(
        'Votes' => array('NumberOfVotes' => 'Int')
    );
   
    public function getCMSFields() { 
        $fields = parent::getCMSFields();
       
        $votesManyManyOptions = array(
            'ExtraFields'    => 'manyManyFieldSet',
        );

        $fields->addFieldsToTab('Root.Votes', array(
            new ManyManyPickerField(
                $this, 'Votes', 'Votes Awarded', array(
                    'ExtraFields'            => 'getCMSExtraFields',
                    'ShowPickedInSearch'     => false,
                    'ExtraFilter'            => '"TeamID" = ' . $this->HomeTeamID . ' OR "TeamID" = ' . $this->AwayTeamID,
            )),
        ));
       
        $rounds = DataObject::get('AFLRound')->map('ID', 'RoundNumber');
        $fields->addFieldToTab('Root.Main', new DropdownField('AFLRoundID', 'Round Number', $rounds, '', null, "None"));
       
        $teams = DataObject::get('AFLTeam')->map('ID', 'TeamName');
        $fields->addFieldToTab('Root.Main', new DropdownField('HomeTeamID', 'Home Team', $teams, '', null, "No Team"));
        $fields->addFieldToTab('Root.Main', new DropdownField('AwayTeamID', 'Away Team', $teams, '', null, "No Team"));
       
        return $fields;
    }

   

    // AFLPlayer

    public static $belongs_many_many = array(
        'Votes'            => 'AFLMatch'
    );

    /**
     * Used for ManyManyPickerField in AFLMatch
     * @return FieldSet
     */
    public function getCMSExtraFields() { 
        return new FieldSet(
            new NumericField('NumberOfVotes', 'Votes Awarded')
        );
    }

Nicolaas Thiemen Francken - Sunny Side Up

unread,
Aug 18, 2011, 2:09:08 AM8/18/11
to silverst...@googlegroups.com
Rodney, that looks excellent! Thank you and thank you Andrew.
Reply all
Reply to author
Forward
0 new messages