Skip to content

Commit

Permalink
Merge pull request #17 from SilverStripers/feature/injector-class
Browse files Browse the repository at this point in the history
change the HTMLText's class from injector to point to MarkdownText
  • Loading branch information
fonsekaean authored Oct 27, 2017
2 parents d1c5d6a + 9b19209 commit 82ce40d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 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
```

11 changes: 0 additions & 11 deletions _config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,11 @@
* Time: 11:21 AM
* 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;
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) {
$siteTreeDB = Config::inst()->get(SiteTree::class, 'db');
$siteTreeDB['Content'] = MarkdownText::class;
Config::modify()
->set(SiteTree::class, 'db', $siteTreeDB);
}


ShortcodeParser::get('default')
Expand Down
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 82ce40d

Please sign in to comment.