Jump to:

7939 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » FileDataObjectManager grid view filename

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1336 Views
  • richard-ward
    Avatar
    Community Member
    31 Posts

    FileDataObjectManager grid view filename Link to this post

    Hi,

    I have got the file data object manager working roughly as I would like it, with the exception of the grid view of my files showing "#5" for example rather than the title of the file? Any ideas why?

    Publication

    class Publication extends DataObject {
       static $db = array(
          'IssueNumber' => 'Varchar(25)',
          'Date' => 'Date'
       );
       
       static $has_one = array(
          'Document' => 'File',
          'PublicationPage' => 'PublicationPage'
       );

       function getCMSFields_forPopup() {
          $datefield = new DateField('Date');
          $datefield->setConfig('showcalendar', true);
          $datefield->setConfig('showdropdown', true);
          $datefield->setConfig('dateformat', 'dd/MM/YYYY');
       
          return new FieldSet(
             new TextField('IssueNumber'),
             $datefield,
             new FileIFrameField('Document')
          );
       }
    }

    PublicationPage

    class PublicationPage extends Page {
       
       static $has_many = array(
          'Publications' => 'Publication'
       );
       
       static $has_one = array (
          'RootFolder' => 'Folder'
       );
       
       function onBeforeWrite() {
          parent::onBeforeWrite();
          if($this->ID) {
             $this->RootFolder()->Title = $this->Title;
          }
       }   
       
       function onAfterWrite() {
          if($this->ID) {
             $this->checkFolder();
          }
          parent::onAfterWrite();
       }
       
       function onBeforeDelete() {
          parent::onBeforeDelete();
          $this->RootFolder()->delete();
       }
       
       function checkFolder() {
          if(!$this->RootFolderID) {
             $folder = Folder::findOrMake("PublicationPage-" . $this->ID);
             $folder->Title = $this->Title;
             $folder->write();
             
             $this->RootFolderID = $folder->ID;
             $this->write();
          } else {
             $this->RootFolder()->Title = $this->Title;
             $this->RootFolder()->write();
          }
       }
       
       function getCMSFields() {
          $fields = parent::getCMSFields();
          $manager = new FileDataObjectManager(
             $this,
             'Publications',
             'Publication',
             'Document',
             array(
                'IssueNumber' => 'IssueNumber',
                'Date' => 'Date'),
             'getCMSFields_forPopup'
          );
          $manager->setUploadFolder("PublicationPage-" . $this->ID);
          $manager->setAllowedFileTypes(array ('pdf','doc'));
          
          $fields->addFieldToTab("Root.Content.Publications", $manager);
          return $fields;
       }
    }

    class PublicationPage_Controller extends Page_Controller {
       public function init() {
          parent::init();
       }
    }

  • UncleCheese
    Avatar
    4085 Posts

    Re: FileDataObjectManager grid view filename Link to this post

    $manager->setGridLabelField('IssueNumber');

  • richard-ward
    Avatar
    Community Member
    31 Posts

    Re: FileDataObjectManager grid view filename Link to this post

    Thanks for the quick reply!

    That worked perfectly for getting the IssueNumber. Now I have decided to use the filename, how would I go about that?

    I have tried:

    'Document.Title'
    'Document()->Title'

    And I had tried creating a method in Publication and calling that, but all to no avail!!

  • UncleCheese
    Avatar
    4085 Posts

    Re: FileDataObjectManager grid view filename Link to this post

    It should fall back on the Title field of your File object if there's not grid label defined. Are the numbers you're getting representative of the DataObject ID, or the File ID? Is the Title field of the File stored in the database?

  • richard-ward
    Avatar
    Community Member
    31 Posts

    Re: FileDataObjectManager grid view filename Link to this post

    It is the DataObjectID...

    EDIT: Don't worry! I was using some old versions of SS and DOM. Thanks very much!

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