Jump to:

5537 Posts in 1737 Topics by 1223 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Customising gridField in CMS? (SS3) // SOLVED

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

Page: 1
Go to End
Author Topic: 566 Views
  • LinseyM
    Avatar
    Community Member
    99 Posts

    Customising gridField in CMS? (SS3) // SOLVED Link to this post

    Hi there,

    Since I've now realised that $gridField doesn't use "getCMSFields_forPopup()"*, how can I control my gridField to specify:

    1) The upload folder for an image?
    2) The title/label of the field(s) that are displayed in the CMS? (so I can can display something like: "Brand Logo (100x50px)" for the logo image field, instead of just "Logo")

    Many thanks.

    *despite stumbling on an online tutorial that said it did... (http://www.inforbiro.com/blog-eng/silverstripe-gridfield-tutorial/)

    ps here is my code:

    Data Object (Partner.php)

    class Partner extends DataObject {

       // object's fields
       public static $db = array(
          'BrandName' => 'Varchar(255)',
          'OrderBy' => 'Varchar(5)'
       );

       // One-to-one relationships
       public static $has_one = array(
          'Logo' => 'Image',
          'GalleryPic' => 'Image',
          'Partners' => 'Partners'
       );

       // Summary fields
       public static $summary_fields = array(
          'Logo.StripThumbnail' => 'Image',
          'BrandName' => 'BrandName',
          'OrderBy' => 'OrderBy'
       );

       static $default_sort = "OrderBy";

    }

    And the Holding Page (Partners.php)

       public static $has_many = array(
          'Partners' => 'Partner'
       );

    function getCMSFields() {

          $fields = parent::getCMSFields();

          $fields->removeByName("RightColumn");

          $gridFieldConfig1 = GridFieldConfig::create()->addComponents(
             new GridFieldToolbarHeader(),
             new GridFieldAddNewButton('toolbar-header-right'),
             new GridFieldSortableHeader(),
             new GridFieldDataColumns(),
             new GridFieldPaginator(10),
             new GridFieldEditButton(),
             new GridFieldDeleteAction(),
             new GridFieldDetailForm()
          );
          
          $gridField = new GridField("Partners", "Brand Partners:", $this->Partners(), $gridFieldConfig1);
          $fields->addFieldToTab("Root.BrandPartners", $gridField);
             
          return $fields;
    }

  • simon_w
    Avatar
    Forum Moderator
    471 Posts

    Re: Customising gridField in CMS? (SS3) // SOLVED Link to this post

    GridField, like ComplexTableField, uses the getCMSFields() method on the managed DataObject.

  • LinseyM
    Avatar
    Community Member
    99 Posts

    Re: Customising gridField in CMS? (SS3) // SOLVED Link to this post

    OK, that worked once I figured out how to reference it (just Root.Main). Awesome. Thank you Simon. Much appreciated.

    Just in case anyone is wondering:

    I added the following code to the data object Partner.php

    function getCMSFields() {

          $fields = parent::getCMSFields();

             $uploadField = new UploadField('Logo', 'Brand Logo:');
             $uploadField->getValidator()->allowedExtensions = array('jpg', 'gif', 'png');
             $uploadField->setFolderName('assets/BrandPartners');
             $fields->addFieldToTab('Root.Main', $uploadField);
             
          return $fields;
    }

    }

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