Jump to:

23364 Posts in 18142 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Issues Customising Tutorial 5

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 802 Views
  • ambient
    Avatar
    Community Member
    123 Posts

    Issues Customising Tutorial 5 Link to this post

    Hi there,

    I'm trying to customise tutorial 5 by being able to add images, links and dates to the modules.

    The problem is when I open the popup the image uploader says "Images can be attached once you have saved the record for the first time." so I have to fill in the other data click save and then reopen/edit it to be able to upload an image.

    Also I'm using $many_many but I'd like to only be able to select a maximum of 7 modules instead of unlimited. Is this possible?

    My developer skills are not great so any help is much appreciated

    Module.php

    <?php

    class Module extends DataObject {
       
       static $db = array(
          'CompanyName' => 'Text',
          'StartDate' => 'Date'
       );
       
       static $has_one = array(
    'Logo' => 'Image',      
          'PremiumLink' => 'SiteTree'
    );
       
       static $belongs_many_many = array(
          'Projects' => 'Project'
       );
       
       function getCMSFields_forPopup() {
          $fields = new FieldSet();
          $fields->push( new TextField( 'CompanyName', 'Company Name' ) );
          
          $fields->push( $startdateField = new DateField( 'StartDate', 'Start Date' ) );
          $startdateField->setConfig('showcalendar', true);
          $startdateField->setConfig('DD MM YYYY');
          
          $fields->push( new TreeDropdownField( 'PremiumLinkID', 'Link to page', 'SiteTree')); //Note the ID added after the fieldname
                
          $fields->push( new ImageField( 'Logo' ) );
          return $fields;
       }
       
    }

    ?>

    Project.php

    <?php

    class Project extends Page {
       
       static $has_one = array(
          
       );
       
       static $many_many = array(
          'Modules' => 'Module'
       );
       
       function getCMSFields() {
          $fields = parent::getCMSFields();
          
          
          
          $modulesTablefield = new ManyManyComplexTableField(
             $this,
             'Modules',
             'Module',
             array(
                'CompanyName' => 'Company Name',
                'StartDate' => 'Start Date',
                'PremiumLinkID' => 'Premium Link',
                'Logo' => 'Company Logo'
             ),
             'getCMSFields_forPopup'
          );
          $modulesTablefield->setAddTitle( 'A Module' );
          
          $fields->addFieldToTab( 'Root.Content.Modules', $modulesTablefield );
          
          return $fields;
       }
       
    }

    class Project_Controller extends Page_Controller {
       
    }

    ?>

  • ambient
    Avatar
    Community Member
    123 Posts

    Re: Issues Customising Tutorial 5 Link to this post

    Nobodies got any ideas on this? I kind of thought it would be an easy solution, just something I did wrong to cause the image uploader to behave like that?

    Any ideas? Pleeeeeeeeease

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: Issues Customising Tutorial 5 Link to this post

    Also I'm using $many_many but I'd like to only be able to select a maximum of 7 modules instead of unlimited. Is this possible?

    $modules = $this->Modules();
    if( !empty($modules) ) {
       $count = $modules->Count();
       if( !empty($count) && $count>=8 ) {
          // do something
       }
    }

  • ambient
    Avatar
    Community Member
    123 Posts

    Re: Issues Customising Tutorial 5 Link to this post

    Awesome, Thanks Devlin

    802 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.