Jump to:

5540 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » SilverStripe Book: CRM-Customisation mixed with ManyManyComplexTableField

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

Page: 1
Go to End
Author Topic: 884 Views
  • david_b
    Avatar
    Community Member
    3 Posts

    SilverStripe Book: CRM-Customisation mixed with ManyManyComplexTableField Link to this post

    Hello hello,

    I'm right now extending the ModelAdmin based upon how it is written in the SilverStripe book. Now I included a ManyManyComplexTableField as well and so far everything works just fine.

    But I still have a few questions to my code. You can find my 3 Files here:
    NewsletterAdmin.php http://pastebin.com/tkgWQdgE

    <?php
    class NewsletterAdmin extends ModelAdmin {
       static $managed_models = array(
          'NewsletterContact',
          'NewsletterGroup',
       );
       
       static $url_segment = 'newsletter';
    }
    ?>

    NewsletterContact.php http://pastebin.com/0FzfQqJm

    <?php
    class NewsletterContact extends Member {
       static $singular_name = 'Kontakt';
       static $plural_name = 'Kontakte';
       
       static $db = array(
          'Gender' => 'Enum("männlich, weiblich")',
          'NameTitle' => 'Varchar(100)'
       );
       
       static $many_many = array(
          'NewsletterGroups' => 'NewsletterGroup',
       );
       
       static $field_labels = array(
          'Gender' => 'Geschlecht',
          'NameTitle' => 'Anrede',
       );
       
       function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->removeByName('Permissions');
          $fields->removeByName('Groups');
          
          $fields->removeByName('Password');
          $fields->removeByName('Locale');
          $fields->removeByName('DateFormat');
          $fields->removeByName('TimeFormat');
          $fields->removeByName('MemberUserDetailsHeader');
          

          $newsletterGroupTablefield = new ManyManyComplexTableField(
             $this,
             'NewsletterGroups',
             'NewsletterGroup',
             array(
                'Title' => 'Title'
             ),
             'getCMSFields'
          );
          
          $fields->addFieldToTab( 'Root.NewsletterGroups', $newsletterGroupTablefield );
          
          return $fields;
       }
    }
    ?>

    NewsletterGroup.php http://pastebin.com/N3kBhkZt

    <?php
    class NewsletterGroup extends DataObject {
       static $singular_name = 'NewsletterGruppe';
       static $plural_name = 'NewsletterGruppen';

       static $db = array(
          'Title' => 'Varchar(255)',
       );
       static $belongs_many_many = array(
          'NewsletterContacts' => 'NewsletterContact',
       );
       
       static $field_labels = array(
          'Title' => 'Titel',
       );
       
    function getCMSFields() {
    $fields = new FieldSet();
    $fields->push( new TextField( 'Title' ) );
    return $fields;
    }
    }
    ?>

    My Questions:
    If I create a new NewsletterContact it first only says "Add" in the lower right corner and only if I hit "Add" I get the 3 new buttons "Back", "Delete" and "Save". This wouldn't really matter to me, but on hitting "Add" it only saves me the Name and the Title of the NewsletterContacts but not the NewsletterGroup in the ManyManyComplexTableField. Is this normal behaviour or is there a way, that I can already save all the data on the first click?

    And my second question: On first glance, am I making any serious mistakes, which one should never ever make?

    Thanks in advance
    Cheers,
    David

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: SilverStripe Book: CRM-Customisation mixed with ManyManyComplexTableField Link to this post

    Is this normal behaviour or is there a way, that I can already save all the data on the first click?

    I guess so, if we were to edit one of the child objects we wouldn't expect it to save the parent would we? If you want to change the save behaviour you can use onBeforeWrite/onAfterWrite to do so.

    And my second question: On first glance, am I making any serious mistakes, which one should never ever make?
    Not that I can see

  • david_b
    Avatar
    Community Member
    3 Posts
    884 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.