From 5bb3cb87010aa9d476411f27d7384474df6d50da Mon Sep 17 00:00:00 2001 From: Nivanka Fonseka Date: Fri, 27 Oct 2017 10:12:48 +0530 Subject: [PATCH 1/2] change the HTMLText's class from injector to point to MarkdownText --- _config.php | 7 +------ _config/model.yml | 2 ++ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/_config.php b/_config.php index e5e2c82..cee7b8d 100644 --- a/_config.php +++ b/_config.php @@ -7,7 +7,6 @@ * To change this template use File | Settings | File Templates. */ -use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Core\Config\Config; use SilverStripers\markdown\db\MarkdownText; use SilverStripers\markdown\shortcodes\MarkdownImageShortcodeProvider; @@ -17,13 +16,9 @@ $asBase = Config::inst()->get(MarkdownText::class, 'markdown_as_base'); if ($asBase) { - $siteTreeDB = Config::inst()->get(SiteTree::class, 'db'); - $siteTreeDB['Content'] = MarkdownText::class; - Config::modify() - ->set(SiteTree::class, 'db', $siteTreeDB); + Config::modify('SilverStripe\Core\Injector\Injector', 'class', MarkdownText::class); } - ShortcodeParser::get('default') ->register('image', [ImageShortcodeProvider::class, 'handle_shortcode']) ->register('image_link', [MarkdownImageShortcodeProvider::class, 'handle_shortcode']) diff --git a/_config/model.yml b/_config/model.yml index 4072c32..2ada108 100644 --- a/_config/model.yml +++ b/_config/model.yml @@ -5,3 +5,5 @@ Name: markdownfieldtype SilverStripe\Core\Injector\Injector: MarkdownText: class: SilverStripers\markdown\db\MarkdownText + HTMLText: + class: SilverStripers\markdown\db\MarkdownText From 9b1920968ad751402f571530910266aa1c390dcc Mon Sep 17 00:00:00 2001 From: Nivanka Fonseka Date: Fri, 27 Oct 2017 16:04:22 +0530 Subject: [PATCH 2/2] added a more formal way of changing the HTMLText to MarkdownText. Also updated the docs on how to completed replace it. --- README.md | 16 ++++++++++++---- _config.php | 8 +------- _config/model.yml | 2 -- src/db/MarkdownText.php | 2 -- src/extensions/MarkdownSiteTreeExtension.php | 4 +++- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 22830df..47387f2 100644 --- a/README.md +++ b/README.md @@ -49,12 +49,20 @@ public function getCMSFields() } ``` -There is an option to completely replace the HTMLText fields from a CMS by using the following config +## Force all teh fields to use Markdown -``` +If you are looking to replace all the fields of HTMLText to markdown use the following configs in the config.yml. -SilverStripers\markdown\db\MarkdownText: - markdown_as_base: true +This should override any instances of the HTMLText replacements with MarkdownText ``` +--- +Name: myconfigs +After: + - '#corefieldtypes' +--- +SilverStripe\Core\Injector\Injector: + HTMLText: + class: SilverStripers\markdown\db\MarkdownText +``` diff --git a/_config.php b/_config.php index cee7b8d..7075bbc 100644 --- a/_config.php +++ b/_config.php @@ -6,18 +6,12 @@ * Time: 11:21 AM * To change this template use File | Settings | File Templates. */ - -use SilverStripe\Core\Config\Config; -use SilverStripers\markdown\db\MarkdownText; use SilverStripers\markdown\shortcodes\MarkdownImageShortcodeProvider; use SilverStripe\Assets\Shortcodes\FileShortcodeProvider; use SilverStripe\Assets\Shortcodes\ImageShortcodeProvider; use SilverStripe\View\Parsers\ShortcodeParser; -$asBase = Config::inst()->get(MarkdownText::class, 'markdown_as_base'); -if ($asBase) { - Config::modify('SilverStripe\Core\Injector\Injector', 'class', MarkdownText::class); -} + ShortcodeParser::get('default') ->register('image', [ImageShortcodeProvider::class, 'handle_shortcode']) diff --git a/_config/model.yml b/_config/model.yml index 2ada108..4072c32 100644 --- a/_config/model.yml +++ b/_config/model.yml @@ -5,5 +5,3 @@ Name: markdownfieldtype SilverStripe\Core\Injector\Injector: MarkdownText: class: SilverStripers\markdown\db\MarkdownText - HTMLText: - class: SilverStripers\markdown\db\MarkdownText diff --git a/src/db/MarkdownText.php b/src/db/MarkdownText.php index 897831c..6c9ce8c 100644 --- a/src/db/MarkdownText.php +++ b/src/db/MarkdownText.php @@ -41,8 +41,6 @@ class MarkdownText extends DBText 'NoHTML' => 'Text', ]; - private static $markdown_as_base = false; - private $parsedContent; private $shortcodes = []; diff --git a/src/extensions/MarkdownSiteTreeExtension.php b/src/extensions/MarkdownSiteTreeExtension.php index f8c55f6..96c3696 100644 --- a/src/extensions/MarkdownSiteTreeExtension.php +++ b/src/extensions/MarkdownSiteTreeExtension.php @@ -11,6 +11,7 @@ use SilverStripe\Core\Config\Config; use SilverStripe\Forms\FieldList; use SilverStripe\ORM\DataExtension; +use SilverStripe\Core\Injector\Injector; use SilverStripers\markdown\db\MarkdownText; use SilverStripers\markdown\forms\MarkdownEditorField; @@ -21,7 +22,8 @@ class MarkdownSiteTreeExtension extends DataExtension */ public function updateCMSFields(FieldList $fields) { - if (Config::inst()->get(MarkdownText::class, 'markdown_as_base')) { + $injectorConfig = Config::inst()->get(Injector::class, 'HTMLText'); + if ($injectorConfig && isset($injectorConfig['class']) && $injectorConfig['class'] == MarkdownText::class) { $fields->replaceField('Content', MarkdownEditorField::create('Content')); } }