BlockHTMLEditorField   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 25
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A saveInto() 0 14 2
A extraClass() 0 3 1
1
<?php
2
3
namespace LeKoala\Blocks\Fields;
4
5
use SilverStripe\View\Parsers\HTMLValue;
6
use SilverStripe\ORM\DataObjectInterface;
7
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
8
use SilverStripe\Forms\HTMLEditor\HTMLEditorConfig;
9
use SilverStripe\Forms\HTMLEditor\HTMLEditorSanitiser;
10
11
/**
12
 * This simple extension allow storing the html into json
13
 * and relies on our hijacked setCastedField method to save the html
14
 */
15
class BlockHTMLEditorField extends HTMLEditorField
16
{
17
    public function extraClass()
18
    {
19
        return 'htmleditor ' . parent::extraClass();
20
    }
21
22
    /**
23
     * @param DataObject|DataObjectInterface $record
0 ignored issues
show
Bug introduced by
The type LeKoala\Blocks\Fields\DataObject was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
     * @throws Exception
25
     */
26
    public function saveInto(DataObjectInterface $record)
27
    {
28
        // Sanitise if requested
29
        $htmlValue = HTMLValue::create($this->Value());
30
        if (HTMLEditorField::config()->sanitise_server_side) {
31
            $santiser = HTMLEditorSanitiser::create(HTMLEditorConfig::get_active());
32
            $santiser->sanitise($htmlValue);
33
        }
34
35
        // optionally manipulate the HTML after a TinyMCE edit and prior to a save
36
        $this->extend('processHTML', $htmlValue);
37
38
        // Store into record
39
        $record->setCastedField($this->name, $htmlValue->getContent());
40
    }
41
}
42