7912 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Add more textfields
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 1436 Views |
-
Add more textfields

1 September 2009 at 4:45am
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 -
Re: Add more textfields

1 September 2009 at 5:14am
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 %> -
Re: Add more textfields

1 September 2009 at 7:37pm
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 -
Re: Add more textfields

2 September 2009 at 3:01am Last edited: 2 September 2009 3:03am
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 %> -
Re: Add more textfields

8 September 2009 at 10:36pm
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 -
Re: Add more textfields

9 September 2009 at 2:06am
Great to hear that!
FYI for anyone reading this thread.. there's a typo in the code above. class AudioFile should read "AudioLink".
| 1436 Views | ||
|
Page:
1
|
Go to Top |

