OK thks again
I have it working now but my problem is in the template : I can't access custom fields Description and DestLink
I tried DataObject::add_extension('Image', 'AttachedFile'); in _config without success
<% if AttachedFiles(MyImages) %>
<div id="our_work">
<ul >
<% control AttachedFiles(MyImages) %>
<li><a href="$DestLink">$SetWidth(200) dqsfqsdfqsd $Description</a></li>
<% end_control %>
</ul>
</div>
<div id="worm"></div>
<% end_if %>
AttachedFile customization :
class AttachedFile extends DataObjectDecorator
{
// get the additional DB Fields
public function extraDBFields() {
return array(
'db' => array(
'Grouping' => 'Varchar(255)',
'Description'=> 'Varchar(255)'
),
'has_one' => array(
'SiteTree' => 'SiteTree',
"LinkTo" => "SiteTree"
),
);
}
/**
* check wheather or not this is a image
* @return bool
*/
public function IsImage(){
return $this->owner instanceof Image;
}
static $default_sort = 'Sort';
// set the container class here. usually SiteTree will do.
// This should be the same class as in the has_one relation
static $containerClass = 'SiteTree';
/**
* This is needed in the FileManager. We just allow the user to edit the
* File Title by adding it here.
*
* FIXED: Name is changed to getMyCMSFields 'cause there s an existing
* getCMSFields function in the File-Class.
*
* @return FieldSet fields that should be editable by the user
*/
public function getMyCMSFields(){
/**
* FIXED: Value is only shown if theres an existing entry.
* Otherwise we get some crappy stuff in the Title
*/
$items = DataObject::get('SiteTree');
$values = array();$values[0] = "";
foreach($items as $item){
$values[$item->ID] = $item->Title;
}
$fields = new FieldSet(
new TextField('Title', _t('AttachedFile_Uploader.TITLE', 'Title'),($this->owner->ID) ? $this->owner->Title : ""),
new TextareaField('Description', "Description",5,5,($this->owner->ID) ? $this->owner->Description : ""),
new DropdownField(
"LinkToID",
"Lien", $values,$this->owner->LinkToID
)
);
return $fields;
}
public function testDecoClass(){
Debug::show('i am decorated');
}
public function getContainerClass(){
return self::$containerClass;
}
function DestLink() {
$linkTo = $this->LinkToID ? DataObject::get_by_id("SiteTree", $this->LinkToID) : null;
if($linkTo) {
return $linkTo->Link();
}
}