Skip to content

Commit

Permalink
Merge pull request #1 from adrexia/silverstripe-4
Browse files Browse the repository at this point in the history
Silverstripe 4 Updates
  • Loading branch information
adrexia authored Jun 28, 2017
2 parents 9b4bb6a + 59f9cb4 commit 7036b25
Show file tree
Hide file tree
Showing 22 changed files with 37 additions and 247 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
> Provides the standards editing features supplied to CWP editors in an easily reusable module.
## Features
* StandardsHtmlEditorConfig - Customises TinyMCE removing the underline option and adding more appropriate options.
* CustomHtmlEditorField - Validates inserted media to check for alt attribute.
* Customises TinyMCE configuration
* RichLinksExtension - Adds capability to augment links with extra attributes and meta information.

## Requirements

SilverStripe Admin ^4.0
84 changes: 22 additions & 62 deletions _config.php
Original file line number Diff line number Diff line change
@@ -1,73 +1,33 @@
<?php

// TinyMCE configuration
$standardsEditor = HtmlEditorConfig::get('standards');

// Start with the same configuration as 'cms' config (defined in framework/admin/_config.php).
$standardsEditor->setOptions(array(
'friendly_name' => 'Default Standards',
'priority' => '60',
'mode' => 'none',

'body_class' => 'typography',
'document_base_url' => Director::absoluteBaseURL(),
use SilverStripe\Forms\HTMLEditor\TinyMCEConfig;

'cleanup_callback' => "sapphiremce_cleanup",

'use_native_selects' => false,
'valid_elements' => "@[id|class|style|title],a[id|rel|rev|dir|tabindex|accesskey|type|name|href|target|title"
. "|class],-strong/-b[class],-em/-i[class],-strike[class],-u[class],#p[id|dir|class|align|style],-ol[class],"
. "-ul[class],-li[class],br,img[id|dir|longdesc|usemap|class|src|border|alt=|title|width|height|align|data*],"
. "-sub[class],-sup[class],-blockquote[dir|class],"
. "-table[cellspacing|cellpadding|width|height|class|align|dir|id|style],"
. "-tr[id|dir|class|rowspan|width|height|align|valign|bgcolor|background|bordercolor|style],"
. "tbody[id|class|style],thead[id|class|style],tfoot[id|class|style],"
. "#td[id|dir|class|colspan|rowspan|width|height|align|valign|scope|style|headers],"
. "-th[id|dir|class|colspan|rowspan|width|height|align|valign|scope|style|headers],caption[id|dir|class],"
. "-div[id|dir|class|align|style],-span[class|align|style],-pre[class|align],address[class|align],"
. "-h1[id|dir|class|align|style],-h2[id|dir|class|align|style],-h3[id|dir|class|align|style],"
. "-h4[id|dir|class|align|style],-h5[id|dir|class|align|style],-h6[id|dir|class|align|style],hr[class],"
. "dd[id|class|title|dir],dl[id|class|title|dir],dt[id|class|title|dir],@[id,style,class]",
'extended_valid_elements' =>
'img[class|src|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|usemap|data*],'
. 'object[classid|codebase|width|height|data|type],'
// TinyMCE configuration
$standardsEditor = TinyMCEConfig::get('cms')->setOptions(array(
"block_formats" => 'Paragraph=p;Header 1=h2;Header 2=h3;Header 3=h4;Header 4=h5;Header 5=h6;Preformatted=pre; Address=address',
'extended_valid_elements' =>
"img[class|src|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|usemap|data*]," . "iframe[src|name|width|height|align|frameborder|marginwidth|marginheight|scrolling],"
. "object[width|height|data|type],"
. 'embed[width|height|name|flashvars|src|bgcolor|align|play|loop|quality|allowscriptaccess|type|pluginspage|autoplay],'
. 'param[name|value],'
. 'map[class|name|id],'
. 'area[shape|coords|href|target|alt],'
. 'ins[cite|datetime],del[cite|datetime],'
. 'menu[label|type],'
. 'meter[form|high|low|max|min|optimum|value],'
. 'cite,abbr,,b,article,aside,code,col,colgroup,details[open],dfn,figure,figcaption,'
. 'footer,header,kbd,mark,,nav,pre,q[cite],small,summary,time[datetime],var,ol[start|type]',
'browser_spellcheck' => true,
'theme_advanced_blockformats' => 'p,pre,address,h2,h3,h4,h5,h6'
. "param[name|value],"
. "map[class|name|id],"
. "area[shape|coords|href|target|alt]",
'browser_spellcheck' => true
));

$standardsEditor->enablePlugins('media', 'fullscreen', 'inlinepopups');
$standardsEditor->enablePlugins('template');
$standardsEditor->enablePlugins('lists');
$standardsEditor->enablePlugins('visualchars');
$standardsEditor->enablePlugins('xhtmlxtras');
$standardsEditor->enablePlugins(array(
'ssbuttons' => sprintf('../../../%s/tinymce_ssbuttons/editor_plugin_src.js', THIRDPARTY_DIR),
'ssmacron' => sprintf('../../../%s/tinymce_ssmacron/editor_plugin_src.js', THIRDPARTY_DIR)
));

// First line:
$standardsEditor->insertButtonsAfter('strikethrough', 'sub', 'sup');
$standardsEditor->removeButtons('underline', 'strikethrough', 'spellchecker');
// Removed unwanted formatting tools - these can be added with css if needed
$standardsEditor->removeButtons('underline', 'alignleft', 'alignright', 'alignjustify', 'aligncenter');

// Second line:
$standardsEditor->insertButtonsBefore('formatselect', 'styleselect');
$standardsEditor->addButtonsToLine(2,
'ssmedia', 'sslink', 'unlink', 'anchor', 'separator','code', 'fullscreen', 'separator',
'template', 'separator', 'ssmacron'
);
$standardsEditor->insertButtonsAfter('pasteword', 'removeformat');
$standardsEditor->insertButtonsAfter('selectall', 'visualchars');
$standardsEditor->removeButtons('visualaid');
// enable plugins
$standardsEditor->enablePlugins('template', 'hr', 'charmap', 'anchor', 'wordcount');

//First line:
$standardsEditor->insertButtonsAfter('removeformat', '|', 'superscript', 'subscript', 'blockquote', 'hr');
$standardsEditor->addButtonsToLine(1, '|', 'charmap', 'template');

// Third line:
$standardsEditor->removeButtons('tablecontrols');
$standardsEditor->addButtonsToLine(3, 'cite', 'abbr', 'ins', 'del', 'separator', 'tablecontrols');
// // Second line:
$standardsEditor->insertButtonsBefore('formatselect', 'styleselect');
$standardsEditor->insertButtonsAfter('unlink', '|', 'anchor');
11 changes: 2 additions & 9 deletions _config/config.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
---
Name: standardseditingconfig
After: 'framework/*','cms/*'
---
DBField:
SilverStripe\ORM\FieldType\DBField:
extensions:
- RichLinksExtension
Group:
extensions:
- StandardsHtmlEditorConfig
HtmlEditorField_Toolbar:
extensions:
- CustomHtmlEditorFieldToolbar
- RichLinksExtension
9 changes: 0 additions & 9 deletions code/extensions/CustomHtmlEditorField.php

This file was deleted.

7 changes: 5 additions & 2 deletions code/extensions/RichLinksExtension.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php

use SilverStripe\Assets\File;
use SilverStripe\ORM\DataObject;
use SilverStripe\Core\Extension;
/**
* Adds capability to augment links with extra attributes and meta information.
*
Expand All @@ -25,7 +29,7 @@ public function RichLinks() {

// Attach the file type and size to each of the links.
for ($i = 0; $i < count($matches[0]); $i++){
$file = DataObject::get_by_id('File', $matches[1][$i]);
$file = DataObject::get_by_id(File::class, $matches[1][$i]);
if ($file) {
$size = $file->getSize();
$ext = strtoupper($file->getExtension());
Expand All @@ -47,4 +51,3 @@ public function RichLinks() {
}

}

16 changes: 0 additions & 16 deletions code/extensions/StandardsHtmlEditorConfig.php

This file was deleted.

4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
"license": "BSD-3-Clause",
"require":
{
"silverstripe/framework": "3.6.*",
"silverstripe/cms": "3.6.*",
"silverstripe/html5": "*"
"silverstripe/admin": "^4"
},
"conflict": {
"cwp/cwp-core": "*"
Expand Down
65 changes: 0 additions & 65 deletions javascript/CustomHtmlEditorFieldToolbar.js

This file was deleted.

9 changes: 0 additions & 9 deletions javascript/lang/ar.js

This file was deleted.

9 changes: 0 additions & 9 deletions javascript/lang/en.js

This file was deleted.

7 changes: 0 additions & 7 deletions javascript/lang/en_US.js

This file was deleted.

9 changes: 0 additions & 9 deletions javascript/lang/fi.js

This file was deleted.

9 changes: 0 additions & 9 deletions javascript/lang/mi.js

This file was deleted.

3 changes: 0 additions & 3 deletions javascript/lang/src/ar.js

This file was deleted.

3 changes: 0 additions & 3 deletions javascript/lang/src/en.js

This file was deleted.

3 changes: 0 additions & 3 deletions javascript/lang/src/fi.js

This file was deleted.

3 changes: 0 additions & 3 deletions javascript/lang/src/mi.js

This file was deleted.

3 changes: 0 additions & 3 deletions javascript/lang/src/vi.js

This file was deleted.

3 changes: 0 additions & 3 deletions javascript/lang/src/zh.js

This file was deleted.

9 changes: 0 additions & 9 deletions javascript/lang/vi.js

This file was deleted.

9 changes: 0 additions & 9 deletions javascript/lang/zh.js

This file was deleted.

2 changes: 2 additions & 0 deletions tests/RichLinksExtensionTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use SilverStripe\Dev\SapphireTest;

class RichLinksExtensionTest extends SapphireTest {

function testContentLinkInjections() {
Expand Down

0 comments on commit 7036b25

Please sign in to comment.