PHP code example of clesson-de / silverstripe-markdown

1. Go to this page and download the library: Download clesson-de/silverstripe-markdown library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

clesson-de / silverstripe-markdown example snippets


use SilverStripe\ORM\DataObject;

class BlogPost extends DataObject
{
    private static array $db = [
        'Title'   => 'Varchar(255)',
        'Content' => 'Markdown',
    ];
}

use Clesson\Silverstripe\Markdown\Forms\MarkdownEditorField;
use SilverStripe\ORM\FieldType\FieldList;

public function getCMSFields(): FieldList
{
    $fields = parent::getCMSFields();

    /** @var MarkdownEditorField $contentField */
    $contentField = MarkdownEditorField::create('Content', $this->fieldLabel('Content'));
    $contentField->setRows(20);

    $fields->addFieldToTab('Root.Main', $contentField);

    return $fields;
}

$field = MarkdownEditorField::create('Content', 'Content')
    ->setRows(25);

$field = MarkdownEditorField::create('Content', 'Content')
    ->setPreviewOnly(true);

use Clesson\Silverstripe\Markdown\Constants\MarkdownToolbarButton;
use Clesson\Silverstripe\Markdown\Forms\MarkdownEditorField;

$field = MarkdownEditorField::create('Content', 'Content')
    ->setToolbarButtons([
        MarkdownToolbarButton::HEADER,
        MarkdownToolbarButton::BOLD,
        MarkdownToolbarButton::ITALIC,
        MarkdownToolbarButton::DIVIDER,
        MarkdownToolbarButton::LINK,
        MarkdownToolbarButton::TABLE,
    ]);