Hi,
Firstly a disclaimer - what I am trying to do may well not be possible, but I thought I would check just in case...
I am trying to make a generic means of tagging objects in my SS3 application. The idea is that on any given page, I can pull together any related content based on tags. E.g. If a Page has tags for "apple", and i have some Files that have been tagged with "apple" then I will be able to display links to / the image on the Page. I am trying to do this with some generic configuration.
So far I have done the following:
Tag.php
<?php
class Tag extends DataObject {
static $db = array(
"Name" => "Varchar(25)"
);
static $belongs_many_many = array(
"Taggables" => "Taggable"
);
// The summary fields to be used in GridField's etc.
static $summary_fields = array(
'Name' => 'Name'
);
}
Taggable.php
<?php
class Taggable extends DataExtension {
static $many_many = array(
"Tags" => "Tag"
);
function updateCMSFields(FieldList $fields) {
$tags = GridField::create('Tags', 'Some tags', $this->owner->Tags(), new GridFieldConfig_RelationEditor());
$fields->push($tags);
}
}
_config.php
Object::add_extension("File", "Taggable");
Object::add_extension("Page", "Taggable");
To an extent, the above works. The data model has been created so that there is a Tag table, and then Page_Tag and File_Tag tables. This seems perfectly reasonable. The GridField also appears on both the Page and File editing screens. I am able to add new Tags and link to existing Tags, but I get an internal server error when I edit the Tag. (Note - I do get an error on adding tags, but that is just because the url changes to edit - the data is inserted into the tables as expected).
It is just a browser Server Error page, rather than an SS templated screen, and I've been unable to locate any logs, so I really don't know what the cause of the issue is.
As I have said before, maybe it is just not possible, and I have been lucky to get this far, but I thought I'd see to see if anyone else has tried to merge together DataExtensions and GridFields.
Any help gratefully received.