Skip to content

Commit

Permalink
added a more formal way of changing the HTMLText to MarkdownText. Als…
Browse files Browse the repository at this point in the history
…o updated the docs on how to completed replace it.
  • Loading branch information
fonsekaean committed Oct 27, 2017
1 parent 5bb3cb8 commit 9b19209
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

8 changes: 1 addition & 7 deletions _config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
2 changes: 0 additions & 2 deletions _config/model.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ Name: markdownfieldtype
SilverStripe\Core\Injector\Injector:
MarkdownText:
class: SilverStripers\markdown\db\MarkdownText
HTMLText:
class: SilverStripers\markdown\db\MarkdownText
2 changes: 0 additions & 2 deletions src/db/MarkdownText.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class MarkdownText extends DBText
'NoHTML' => 'Text',
];

private static $markdown_as_base = false;

private $parsedContent;
private $shortcodes = [];

Expand Down
4 changes: 3 additions & 1 deletion src/extensions/MarkdownSiteTreeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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'));
}
}
Expand Down

0 comments on commit 9b19209

Please sign in to comment.