Hello,
I'd like to create a grid that will allow me to add some photos with names to general configuration (Settings Tab).
So I followed many tutorials and in every of them they use the schema that does not work for me.
I get Fatal error: Call to undefined method GostcompSiteConfig::CooperativesLogoImages() in C:\wamp\www\gostcomp\mysite\code\GostcompSiteConfig.php on line 27. when I try to get to /admin/settings.
Dev/Build success without errors...
Below I show the GostcompSiteConfig.php that looks like many others tutorials about gridfields...
class GostcompSiteConfig extends DataExtension {
public static $has_many = array(
'CooperativesLogoImages' => 'CooperativePhoto',
);
public static $db = array(
//'FacebookURL' => "Varchar(250)",
//'VimeoURL' => "Varchar(250)",
);
public function updateCMSFields(FieldList $fields) {
//$fields->addFieldToTab("Root.CooperativesLogos", new UploadField("CooperativesLogoImages", _t('GostcompSiteConfig.LogosForYourCooperatives', "Zdjęcia (loga) partnerów")));
$gridFieldConfig = GridFieldConfig_RelationEditor::create()->addComponents(
new GridFieldDeleteAction('unlinkrelation')
);
$fields->addFieldToTab("Root.CooperativesLogos", new GridField("CooperativesLogoImages", "CooperativePhoto", $this->CooperativesLogoImages(), $gridFieldConfig));
//$fields->addFieldToTab("Root.Main", new TextField("FacebookURL", "Enter the full URL of your Facebook page"));
//$fields->addFieldToTab("Root.Main", new TextField("VimeoURL", "Enter the full URL of your Vimeo page"));
}
}
class CooperativePhoto extends DataObject
{
public static $db = array(
'Name' => 'Varchar',
);
public static $has_one = array(
'Photo' => 'Image',
'SiteConfig' => 'SiteConfig'
);
// Summary fields
public static $summary_fields = array('Thumbnail'=>'Thumbnail','Name'=>'Name');
public function getThumbnail()
{
return $this->Image()->CMSThumbnail();
}
public function getCMSFields_forPopup()
{
// Profile picture field
$thumbField = new UploadField('Photo', 'Photo (transparent background suggested)');
$thumbField->allowedExtensions = array('png');
// 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
);
}
}
Finally I add this extension to SiteConfig in _config.php file
Object::add_extension('SiteConfig', 'GostcompSiteConfig');