Jump to:

5513 Posts in 1732 Topics by 1218 members

Customising the CMS

SilverStripe Forums » Customising the CMS » File Upload Field in ManyManyComplexTableField popup

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

Page: 1 2 3
Go to End
Author Topic: 3699 Views
  • kevino
    Avatar
    Community Member
    30 Posts

    File Upload Field in ManyManyComplexTableField popup Link to this post

    I'm trying to add a group of text fields plus some file fields to a ManyManyComplexTableField.
    From what I can fathom, I've done the logcal thing (to me), but it fails.
    I can get the upload brows boxes to show, but it doesn't upload.

    Can anyone see a blunder in this code?

    -----
    UnitList.php

    <?php

    class UnitList extends DataObject {

       static $db = array(
                'UnitNumber' => 'Text',
                'UnitType' => 'Text',
                'UnitArea' => 'Text',
                'UnitRent' => 'Text'
       );
       
       static $has_one = array(
                'UnitSpec' => 'File',
                'UnitLease' => 'File'
       );
       
       static $belongs_many_many = array(
          'AvailableUnitss' => 'AvailableUnits'
       );

       function getCMSFields_forPopup() {
          $fields = new FieldSet();
          $fields->push( new TextField( 'UnitNumber', 'UnitNumber' ) );
          $fields->push( new TextField( 'UnitType', 'Unit Type' ) );
          $fields->push( new TextField( 'UnitArea', 'Unit Area' ) );
          $fields->push( new TextField( 'UnitRent', 'Unit Rent' ) );
          $fields->push( new FileField( 'UnitSpec', 'Unit Specsheet' ) );
          $fields->push( new FileField( 'UnitLease', 'Unit Lease Document' ) );
          return $fields;
       }

    }
    ?>

    PropertyPage.php

    <?php
    /**
    * Defines the PropertyPage page type
    */
    class PropertyPage extends Page {
    static $db = array(
    'AvailableSpace' => 'Text',
    'UnitSizeRange' => 'Text'
       );

    static $has_one = array(
    );

       static $many_many = array(
          'AvailableUnits' => 'UnitList'
       );

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

    $fields->addFieldToTab('Root.Content.Main', new TextField('AvailableSpace'), 'Content');
    $fields->addFieldToTab('Root.Content.Main', new TextField('UnitSizeRange'), 'Content');
          
          $Unitstablefield = new ManyManyComplexTableField(
             $this,
             'AvailableUnits',
             'UnitList',
             array(
                'UnitNumber' => 'UnitNumber',
                'UnitType' => 'Unit Type',
                'UnitArea' => 'Unit Area',
                'UnitRent' => 'Unit Rent',
                'UnitSpec' => 'Unit Specsheet',
                'UnitLease' => 'Unit Lease Document'
             ),
             'getCMSFields_forPopup'
          );
          $Unitstablefield->setAddTitle( 'A Unit' );
          $Unitstablefield->setPageSize(100);

          $fields->addFieldToTab( 'Root.Content.Units', $Unitstablefield );
       
    return $fields;
       }
       
        static $icon = "themes/tutorial/images/treeicons/news";
       
        static $defaults = array('ProvideComments' => false);

    }

    class PropertyPage_Controller extends Page_Controller {

    }

    ?>

    Best wishes,
    K

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: File Upload Field in ManyManyComplexTableField popup Link to this post

    Hi Kevino

    Try using a FileIframeField, that has always worked for me. Alternatively use the Data Object Manager Module which it certainly works with and is a lot more feature rich.

    Aram

  • kevino
    Avatar
    Community Member
    30 Posts

    Re: File Upload Field in ManyManyComplexTableField popup Link to this post

    Thanks for the reply.
    I'm pretty sure I tried the FileIframeField, which didn't work either.
    I assumed this is because it was trying to work from a pop-up?

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: File Upload Field in ManyManyComplexTableField popup Link to this post

    Hmm, must be a problem in your code, as FileIFrameField has always worked fine in a popup. I havn't used a complex table field in quite a while, I only ever use the DataObjectmanager thesedays but I can't think of any reason it would have stopped working.

    I would give ti another go, and if it still doesnt work, post ur code and I'll take a look

  • kevino
    Avatar
    Community Member
    30 Posts

    Re: File Upload Field in ManyManyComplexTableField popup Link to this post

    I think there must be a problem with my code to some extent. Or maybe I'm just going about it the complete wrond way.
    Does the code look plausible?

    From what I can gather, if I change the upload fields to text fields instead, I can get a list of text fields into my db..?

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: File Upload Field in ManyManyComplexTableField popup Link to this post

    Ok, so here is some slightly adapted code for your dataobject (your belongs_many_many relationshop was not referencing the page and I changed the fields to IFrameFields):

    <?php

    class UnitList extends DataObject {

    static $db = array(
    'UnitNumber' => 'Text',
    'UnitType' => 'Text',
    'UnitArea' => 'Text',
    'UnitRent' => 'Text'
    );

    static $has_one = array(
    'UnitSpec' => 'File',
    'UnitLease' => 'File'
    );

    static $belongs_many_many = array(
    'PropertyPages' => 'PropertyPage'
    );

    function getCMSFields_forPopup() {
    return new FieldSet(
              new TextField( 'UnitNumber', 'UnitNumber' ),
             new TextField( 'UnitArea', 'Unit Area' ),
             new TextField( 'UnitRent', 'Unit Rent' ),
             new FileIFrameField( 'UnitSpec', 'Unit Specsheet' ),
             new FileIFrameField( 'UnitLease', 'Unit Lease Document' )
        );

    }

    }
    ?>


    And here is the CTF code (you don't put the file field in the display array as it doesn't know what to do with it):

    $Unitstablefield = new ManyManyComplexTableField(
    $this,
    'AvailableUnits',
    'UnitList',
    array(
    'UnitNumber' => 'UnitNumber',
    'UnitType' => 'Unit Type',
    'UnitArea' => 'Unit Area',
    'UnitRent' => 'Unit Rent'
    ),
    'getCMSFields_forPopup'
    );
    $Unitstablefield->setAddTitle( 'A Unit' );
    $Unitstablefield->setPageSize(100);
    $fields->addFieldToTab( 'Root.Content.Units', $Unitstablefield );

    As far as I can see this should work...

  • kevino
    Avatar
    Community Member
    30 Posts

    Re: File Upload Field in ManyManyComplexTableField popup Link to this post

    I've tried to give the DOM a go, and couldn't get it working as I hoped.

    The code that you've modified, aram, has worked perfectly. Thank you very much.

    I'm actually struggling to get this to sit in my template however.

    This is what my controlling code is at the moment

                <li class="available-units">
                   <ul>
                   <% control AvailableUnits %>
                   <li>$UnitNumber $UnitType $UnitArea $UnitRent <a href="$UnitSpec.URL" title="Download Unit Specification Sheet PDF">Unit Specification</a> <a href="$UnitLease.URL" title="Download Unit Lease Document PDF">Unit Lease Document</a></li>
                   <% end_control %>
                   </ul>
                </li>

    So I'm not sure if I'm just doing the control wrong, or have an error all on the db side.

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: File Upload Field in ManyManyComplexTableField popup Link to this post

    hmm, looks ok to me.....not sure what to suggest. Are you getting anything at all in the template?

    Try adding a conditional in there to see if AvailableUnits() is actually returning anything:

    <% if AvailableUnits %>
    <p>FOO</p>
    <% end_if %>

    3699 Views
Page: 1 2 3
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.