Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Add more textfields

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: 1695 Views
  • jovoo
    Avatar
    Community Member
    12 Posts

    Add more textfields Link to this post

    Hi everyone, hi UncleCheese,

    I'm using the dataObjectManager in a popup in my cms. My cms suposted to be like a blog, but instead of pages (blogmodule) I use dataobjects for a new post. It should be possible to post an url of a free mp3 file. No problem with just one url. But it would be nicer if the user is able to post more than one url, so the blog-article would show two or three seperate musicplayers, each with one mp3 file.

    Would be fantastic if it would be possible to have a little plus-symbol or something to add more textfields in the pop-up for more urls.

    Do you think that's possible, somehow?

    Thank you for help!
    jovoo

  • UncleCheese
    Avatar
    4085 Posts

    Re: Add more textfields Link to this post

    Yup. You can do this with NestedDataObjectManager.

    BlogArticle.php

    class BlogArticle extends DataObject
    {
    // example fields.. use whatever you have.
    static $db = array('Title' => 'Varchar(50', 'Date' => 'Date');

    static $has_many = array ('AudioFiles' => 'AudioFile');

    // example.. use whatever page contains your blogarticle objects.
    static $has_one = array ('BlogHolder' => 'BlogHolder');

    function getCMSFields()
    {
    return new FieldSet(
    new TextField('Title'),
    new DatePickerField('Date'),
    new FileDataObjectManager(
    $this,
    'AudioFiles',
    'AudioFile',
    'MP3',
    array('Title' => 'Title')
    )
    );
    }
    }

    AudioFile.php

    class AudioFile extends DataObject
    {
    static $db = array ('Title' => 'Title');
    static $has_one = array (
    'BlogArticle' => 'BlogArticle',
    'MP3' => 'MP3'
    );

    function getCMSFields()
    {
    return new FieldSet(
    new TextField('Title'),
    new FileIFrameField('MP3')
    );
    }
    }

    That should give you a FileDataObjectManager in your popup window that will allow you to add files to your BlogArticle.

    Then on the template, you just need to do:

    <% control AudioFiles %>
    Listen to $Title
    $MP3.Player
    <% end_control %>

  • jovoo
    Avatar
    Community Member
    12 Posts

    Re: Add more textfields Link to this post

    Hi UncleCheese,

    thank you for your fast answer!! Unfortunately that's not exactly what I meant. I'm pretty new in SilverStripe so, sorry if I didn't explain my task correctly. I try to explain it with your excample. Your Blogpost is my subcategory (a holder for many dataobjects) the audiofile is my post (dataobject). This post contains a Title, Subtitle, LongText and the AudioFile. The audiofile suppost to be just a link to a different page, where you can get free and legal mp3s. So this file will stay on that server. Now I need this let's call it "addMoreAudioURLs"-funktion in the dialog for the dataobject or so. One post should be able to contain more than one link to audiofiles. But I don't want to have like ten textfields in the popup for more urls in default.

    Probably I need a JavaScript to disable more textfields in defaultmode...

    Cheers,
    jovoo

  • UncleCheese
    Avatar
    4085 Posts

    Re: Add more textfields Link to this post

    Well then that's a much easier problem.

    BlogArticle.php

    class BlogArticle extends DataObject
    {
    // example fields.. use whatever you have.
    static $db = array('Title' => 'Varchar(50', 'Date' => 'Date');

    static $has_many = array ('AudioLinks' => 'AudioLink');

    // example.. use whatever page contains your blogarticle objects.
    static $has_one = array ('BlogHolder' => 'BlogHolder');

    function getCMSFields()
    {
    return new FieldSet(
    new TextField('Title'),
    new DatePickerField('Date'),
    new DataObjectManager(
    $this,
    'AudioLinks',
    'AudioLink',
    array('Title'=>'Title','URL' => 'URL')
    )
    );
    }
    }

    AudioLink.php

    class AudioFile extends DataObject
    {
    static $db = array ('URL' => 'Varchar(100)','Title' => 'Text');
    static $has_one = array (
    'BlogArticle' => 'BlogArticle'
    );

    function getCMSFields()
    {
    return new FieldSet(
    new TextField('Title'),
    new TextField('URL','Link to audio file','http://')
    );
    }
    }

    <% control AudioLinks %>
    <a href="$URL">$Title</a>
    <% end_control %>

  • jovoo
    Avatar
    Community Member
    12 Posts

    Re: Add more textfields Link to this post

    Hello UncleCheese,

    thank you so much! Great! It took a while till I understood what you mean (newbie-problem I guess), but after watching your video about nested DataObjectManager and reading your post again I got it.

    Perfect, thats exactly what I need and it's so simple!!

    Cheers,
    jovoo

  • UncleCheese
    Avatar
    4085 Posts

    Re: Add more textfields Link to this post

    Great to hear that!

    FYI for anyone reading this thread.. there's a typo in the code above. class AudioFile should read "AudioLink".

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