From ae97c15e4206f70bbdf6028365cb86373d8329ee Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Tue, 1 Aug 2017 13:59:35 +1200 Subject: [PATCH] ENHANCEMENT Soft-code CSS explicit height and compute against rows --- src/Forms/HTMLEditor/HTMLEditorField.php | 19 ++++++++++++++++++- src/Forms/HTMLEditor/TinyMCEConfig.php | 1 - .../TinyMCECombinedGeneratorTest.php | 4 +++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Forms/HTMLEditor/HTMLEditorField.php b/src/Forms/HTMLEditor/HTMLEditorField.php index 0e2af5cf0..c84555571 100644 --- a/src/Forms/HTMLEditor/HTMLEditorField.php +++ b/src/Forms/HTMLEditor/HTMLEditorField.php @@ -51,7 +51,14 @@ class HTMLEditorField extends TextareaField * @config * @var int */ - private static $default_rows = 30; + private static $default_rows = 20; + + /** + * Extra height per row + * + * @var int + */ + private static $fixed_row_height = 20; /** * ID or instance of editorconfig @@ -110,7 +117,17 @@ class HTMLEditorField extends TextareaField public function getAttributes() { + // Fix CSS height based on rows + $rowHeight = $this->config()->get('fixed_row_height'); + $attributes = []; + if ($rowHeight) { + $height = $this->getRows() * $rowHeight; + $attributes['style'] = sprintf('height: %dpx;', $height); + } + + // Merge attributes return array_merge( + $attributes, parent::getAttributes(), $this->getEditorConfig()->getAttributes() ); diff --git a/src/Forms/HTMLEditor/TinyMCEConfig.php b/src/Forms/HTMLEditor/TinyMCEConfig.php index b11789e25..2bd132aeb 100644 --- a/src/Forms/HTMLEditor/TinyMCEConfig.php +++ b/src/Forms/HTMLEditor/TinyMCEConfig.php @@ -332,7 +332,6 @@ class TinyMCEConfig extends HTMLEditorConfig return [ 'data-editor' => 'tinyMCE', // Register ss.editorWrappers.tinyMCE 'data-config' => Convert::array2json($this->getConfig()), - 'style' => 'height:350px' ]; } diff --git a/tests/php/Forms/HTMLEditor/TinyMCECombinedGeneratorTest.php b/tests/php/Forms/HTMLEditor/TinyMCECombinedGeneratorTest.php index 99eb1cf21..46ceed868 100644 --- a/tests/php/Forms/HTMLEditor/TinyMCECombinedGeneratorTest.php +++ b/tests/php/Forms/HTMLEditor/TinyMCECombinedGeneratorTest.php @@ -8,6 +8,7 @@ use SilverStripe\Dev\SapphireTest; use SilverStripe\Forms\HTMLEditor\HTMLEditorConfig; use SilverStripe\Forms\HTMLEditor\TinyMCECombinedGenerator; use SilverStripe\Forms\HTMLEditor\TinyMCEConfig; +use SilverStripe\View\SSViewer; class TinyMCECombinedGeneratorTest extends SapphireTest { @@ -18,6 +19,7 @@ class TinyMCECombinedGeneratorTest extends SapphireTest // Set custom base_path for tinymce Director::config()->set('alternate_base_folder', __DIR__ . '/TinyMCECombinedGeneratorTest'); Director::config()->set('alternate_base_url', 'http://www.mysite.com/basedir/'); + SSViewer::config()->set('themes', [ SSViewer::DEFAULT_THEME ]); TinyMCEConfig::config()->set('base_dir', 'tinymce'); } @@ -45,7 +47,7 @@ class TinyMCECombinedGeneratorTest extends SapphireTest /** @var TinyMCECombinedGenerator $generator */ $generator = Injector::inst()->create(TinyMCECombinedGenerator::class); $this->assertEquals( - '_tinymce/tinymce-testconfig-8d695fc0be.js', + '_tinymce/tinymce-testconfig-6422b3814d.js', $generator->generateFilename($c), "Filename for config: " . json_encode($c->getAttributes()) . " should match expected value" );