Hi everybody,
currently playing around with the gridfield on 3.0.0rc2 on a local xampp, but I can't figure out how to get image thumbnails to show up in the list view.
The custom getter method that used to work for DOM gives me a "Image_Cached" instead of an actual image, and the other solutions i found around the web will print out an image tag with "<" and ">" translated to html entities "<" and ">"
Thumbnail generation and image resizing is working fine otherwise.
Anybody else have problems with this?
Here's the code, based on this example
<?php
class Contact extends DataObject {
// Contact object's fields
public static $db = array(
'Name' => 'Varchar(255)',
'Description' => 'Text',
'Website' => 'Varchar(255)'
);
// One-to-one relationship with profile picture and contact list page
public static $has_one = array(
'ProfilePicture' => 'Image',
'ContactListPage' => 'ContactListPage'
);
// Summary fields
public static $summary_fields = array(
'Thumbnail' => 'DOMThumbnail',
'Name' => 'Name',
'Description' => 'Description',
'Website' => 'Website URL'
);
public function getCMSFields_forPopup() {
// Profile picture field
$thumbField = new UploadField('ProfilePicture', 'Profile picture');
$thumbField->allowedExtensions = array('jpg', 'png', 'gif');
// Name, Description and Website fields
return new FieldList(
new TextField('Name', 'Name'),
new TextareaField('Description', 'Contact description'),
new TextField('Website', 'Website URL (including http://)'),
$thumbField
);
}
public function getThumbnail() {
if ($Image = $this->ProfilePicture()->ID) {
return $this->ProfilePicture()->SetWidth(80)->Tag;
} else {
return '(No Image)';
}
}
}
<?php
class ContactListPage extends Page {
// One to many relationship with Contact object
public static $has_many = array(
'Contacts' => 'Contact'
);
// Create Grid Field
public function getCMSFields() {
$fields = parent::getCMSFields();
$gridFieldConfig = 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("Contacts", "Contact list:", $this->Contacts(), $gridFieldConfig);
$fields->addFieldToTab("Root.Contacts", $gridField);
return $fields;
}
}
class ContactListPage_Controller extends Page_Controller {
public static $allowed_actions = array (
);
public function init() {
parent::init();
}
}
Thanks in advance!
Andi