mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge branch '5.1' into 5
This commit is contained in:
commit
1eadc84a22
@ -114,20 +114,10 @@ class HTMLEditorField extends TextareaField
|
|||||||
|
|
||||||
public function getAttributes()
|
public function getAttributes()
|
||||||
{
|
{
|
||||||
$config = $this->getEditorConfig();
|
$config = $this->setEditorHeight($this->getEditorConfig());
|
||||||
// Fix CSS height based on rows
|
|
||||||
$rowHeight = $this->config()->get('fixed_row_height');
|
|
||||||
$attributes = [];
|
|
||||||
if ($rowHeight && ($config instanceof TinyMCEConfig)) {
|
|
||||||
$height = $this->getRows() * $rowHeight;
|
|
||||||
$attributes['style'] = sprintf('height: %dpx;', $height);
|
|
||||||
$config = clone $config;
|
|
||||||
$config->setOption('height', 'auto');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Merge attributes
|
// Merge attributes
|
||||||
return array_merge(
|
return array_merge(
|
||||||
$attributes,
|
|
||||||
parent::getAttributes(),
|
parent::getAttributes(),
|
||||||
$config->getAttributes()
|
$config->getAttributes()
|
||||||
);
|
);
|
||||||
@ -190,7 +180,7 @@ class HTMLEditorField extends TextareaField
|
|||||||
public function getSchemaStateDefaults()
|
public function getSchemaStateDefaults()
|
||||||
{
|
{
|
||||||
$stateDefaults = parent::getSchemaStateDefaults();
|
$stateDefaults = parent::getSchemaStateDefaults();
|
||||||
$config = $this->getEditorConfig();
|
$config = $this->setEditorHeight($this->getEditorConfig());
|
||||||
$stateDefaults['data'] = $config->getConfigSchemaData();
|
$stateDefaults['data'] = $config->getConfigSchemaData();
|
||||||
return $stateDefaults;
|
return $stateDefaults;
|
||||||
}
|
}
|
||||||
@ -204,4 +194,23 @@ class HTMLEditorField extends TextareaField
|
|||||||
{
|
{
|
||||||
return htmlentities($this->Value() ?? '', ENT_COMPAT, 'UTF-8', false);
|
return htmlentities($this->Value() ?? '', ENT_COMPAT, 'UTF-8', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set height of editor based on number of rows
|
||||||
|
*/
|
||||||
|
private function setEditorHeight(HTMLEditorConfig $config): HTMLEditorConfig
|
||||||
|
{
|
||||||
|
$rowHeight = $this->config()->get('fixed_row_height');
|
||||||
|
if ($rowHeight && ($config instanceof TinyMCEConfig)) {
|
||||||
|
$rows = (int) $this->getRows();
|
||||||
|
$height = $rows * $rowHeight;
|
||||||
|
$config = clone $config;
|
||||||
|
if ($height) {
|
||||||
|
$config->setOption('height', 'auto');
|
||||||
|
$config->setOption('row_height', sprintf('%dpx', $height));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $config;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,4 +267,43 @@ EOS
|
|||||||
$editor->saveInto($obj);
|
$editor->saveInto($obj);
|
||||||
$this->assertEquals($htmlValue, $obj->Content, 'Table is removed');
|
$this->assertEquals($htmlValue, $obj->Content, 'Table is removed');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetAttributes()
|
||||||
|
{
|
||||||
|
// Create an editor and set fixed_row_height to 0
|
||||||
|
$editor = HTMLEditorField::create('Content');
|
||||||
|
$editor->config()->set('fixed_row_height', 0);
|
||||||
|
// Get the attributes and config from the editor
|
||||||
|
$attributes = $editor->getAttributes();
|
||||||
|
$data_config = json_decode($attributes['data-config'], true);
|
||||||
|
// If fixed_row_height is 0 then row_height and height config are not set
|
||||||
|
$this->assertArrayNotHasKey('height', $data_config, 'Config height should not be set');
|
||||||
|
$this->assertArrayNotHasKey('row_height', $data_config, 'Config row_height should not be set');
|
||||||
|
// Set the fixed_row_height back to 20px
|
||||||
|
$editor->config()->set('fixed_row_height', 20);
|
||||||
|
// Set the rows to 0
|
||||||
|
$editor->setRows(0);
|
||||||
|
// Get the attributes and config from the editor
|
||||||
|
$attributes = $editor->getAttributes();
|
||||||
|
$data_config = json_decode($attributes['data-config'], true);
|
||||||
|
// If rows is 0 then row_height and height config are not set
|
||||||
|
$this->assertArrayNotHasKey('height', $data_config, 'Config height should not be set');
|
||||||
|
$this->assertArrayNotHasKey('row_height', $data_config, 'Config row_height should not be set');
|
||||||
|
// Set the rows to 5
|
||||||
|
$editor->setRows(5);
|
||||||
|
// Get the attributes and config from the editor
|
||||||
|
$attributes = $editor->getAttributes();
|
||||||
|
$data_config = json_decode($attributes['data-config']);
|
||||||
|
// Check the height is set to auto and the row height is set to 100px (5 rows * 20px)
|
||||||
|
$this->assertEquals("auto", $data_config->height, 'Config height is not set');
|
||||||
|
$this->assertEquals("100px", $data_config->row_height, 'Config row_height is not set');
|
||||||
|
// Change the row height to 60px and set the rows to 3
|
||||||
|
$editor->setRows(3);
|
||||||
|
// Get the attributes and config from the editor
|
||||||
|
$attributes = $editor->getSchemaStateDefaults();
|
||||||
|
$data_config = json_decode($attributes['data']['attributes']['data-config']);
|
||||||
|
// Check the height is set to auto and the row height is set to 60px (3 rows * 20px)
|
||||||
|
$this->assertEquals("auto", $data_config->height, 'Config height is not set');
|
||||||
|
$this->assertEquals("60px", $data_config->row_height, 'Config row_height is not set');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user