wolfv / silverstripe-markdowneditorfield

15 stars 4 forks source link

Parsing Markdown inside the CMS Gridfield #5

Open graphicagenda opened 12 years ago

graphicagenda commented 12 years ago

The way I was able to parse text while viewing the gridfield is like so. I was hoping an easier way (without require statements), but it works in my test enviro. I made this an issue, so that someone could clear this as working for others.

        $config = GridFieldConfig_RelationEditor::create()->addComponents(
            new GridFieldSortableRows('SortOrder')
        );
        $f = new GridField('Testimonials', 'Book Testimonials', $this->Testimonials(), $config);
        $f->getConfig()->getComponentByType('GridFieldDataColumns')->setFieldFormatting(array( 
                        "Title" => function($obj) {
                             require_once(BASE_PATH.'/markdowneditorfield/code/lib/markdown/markdown.php');
                             require_once(BASE_PATH.'/markdowneditorfield/code/lib/markdown/markdown_extended.php');
                             return MarkdownExtended($obj); 
                        })); 
        $fields->addFieldToTab('Root.Testimonials', $f);
graphicagenda commented 12 years ago

Actually, the question is how to bring the function($obj){} outside setFieldFormatting() and formatting the other columns at once

wolfv commented 12 years ago

Hey,

do you know about getters and setters? Maybe you can do it with them: relevant DOC entry: http://doc.silverstripe.org/framework/en/topics/datamodel#properties

:)

graphicagenda commented 12 years ago

Thank you, I will update the issue with the right getter function.