Skip to content

Commit 262a318

Browse files
committed
remove content cleaning code
1 parent 5d6dbc7 commit 262a318

File tree

5 files changed

+0
-412
lines changed

5 files changed

+0
-412
lines changed

resources/css/fields.css

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +0,0 @@
1-
/* Hide Trix caption field for RichEditor when hideCaptions is enabled */
2-
3-
/* Target the specific figcaption with attachment__caption class */
4-
[data-hide-captions="true"] figcaption.attachment__caption {
5-
display: none !important;
6-
}
7-
8-
/* Target figcaption with data-trix-placeholder attribute */
9-
[data-hide-captions="true"] figcaption[data-trix-placeholder] {
10-
display: none !important;
11-
}
12-
13-
/* Target any figcaption within the editor area */
14-
[data-hide-captions="true"] .trix-content figcaption,
15-
[data-hide-captions="true"] .trix-editor figcaption,
16-
[data-hide-captions="true"] .fi-fo-rich-editor figcaption {
17-
display: none !important;
18-
}
19-
20-
/* Target Filament's rich editor container */
21-
[data-hide-captions="true"] .fi-fo-rich-editor .trix-content figcaption,
22-
[data-hide-captions="true"] .fi-fo-rich-editor .trix-editor figcaption {
23-
display: none !important;
24-
}
25-
26-
/* More specific targeting for the attachment caption */
27-
[data-hide-captions="true"] .trix-content figure figcaption.attachment__caption,
28-
[data-hide-captions="true"] .trix-editor figure figcaption.attachment__caption {
29-
display: none !important;
30-
}
31-
32-
/* Hide the caption input field that appears when uploading images */
33-
[data-hide-captions="true"] .trix-content figcaption input,
34-
[data-hide-captions="true"] .trix-content figcaption textarea {
35-
display: none !important;
36-
}
37-
38-
/* Alternative selectors for different Trix versions */
39-
[data-hide-captions="true"] .trix-content .attachment__caption,
40-
[data-hide-captions="true"] .trix-content .attachment__name,
41-
[data-hide-captions="true"] .trix-content .attachment__size {
42-
display: none !important;
43-
}
44-
45-
/* Hide caption fields in the editor */
46-
[data-hide-captions="true"] .trix-content [data-trix-content-type] figcaption {
47-
display: none !important;
48-
}
49-
50-
/* Hide any caption-related elements */
51-
[data-hide-captions="true"] .trix-content .caption,
52-
[data-hide-captions="true"] .trix-content .image-caption {
53-
display: none !important;
54-
}
55-
56-
/* Global targeting for any figcaption when hideCaptions is enabled */
57-
[data-hide-captions="true"] figcaption {
58-
display: none !important;
59-
}

src/Concerns/HasContentCleaning.php

Lines changed: 0 additions & 63 deletions
This file was deleted.

src/Fields/RichEditor.php

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
use Backstage\Fields\Contracts\FieldContract;
66
use Backstage\Fields\Enums\ToolbarButton;
77
use Backstage\Fields\Models\Field;
8-
use Backstage\Fields\Services\ContentCleaningService;
9-
use Filament\Forms;
108
use Filament\Forms\Components\RichEditor as Input;
119
use Filament\Forms\Components\Select;
1210
use Filament\Schemas\Components\Grid;
@@ -21,9 +19,6 @@ public static function getDefaultConfig(): array
2119
...parent::getDefaultConfig(),
2220
'toolbarButtons' => ['attachFiles', 'blockquote', 'bold', 'bulletList', 'codeBlock', 'h2', 'h3', 'italic', 'link', 'orderedList', 'redo', 'strike', 'underline', 'undo'],
2321
'disableToolbarButtons' => [],
24-
'autoCleanContent' => true,
25-
'preserveCustomCaptions' => false,
26-
'hideCaptions' => true,
2722
];
2823
}
2924

@@ -32,7 +27,6 @@ public static function make(string $name, ?Field $field = null): Input
3227
$input = self::createBaseInput($name, $field);
3328
$input = self::configureToolbarButtons($input, $field);
3429
$input = self::configureStateHandling($input, $name);
35-
$input = self::configureCaptions($input, $field);
3630

3731
return $input;
3832
}
@@ -66,17 +60,6 @@ private static function configureStateHandling(Input $input, string $name): Inpu
6660
});
6761
}
6862

69-
private static function configureCaptions(Input $input, ?Field $field): Input
70-
{
71-
$hideCaptions = $field->config['hideCaptions'] ?? self::getDefaultConfig()['hideCaptions'];
72-
73-
if ($hideCaptions) {
74-
$input->extraAttributes(['data-hide-captions' => 'true']);
75-
}
76-
77-
return $input;
78-
}
79-
8063
private static function formatRichEditorState($state)
8164
{
8265
if (empty($state)) {
@@ -130,55 +113,13 @@ private static function cleanContentArray(array $state): array
130113
return $state;
131114
}
132115

133-
public static function cleanRichEditorState($state, array $options = [])
134-
{
135-
if (empty($state)) {
136-
return '';
137-
}
138-
139-
$cleanedState = ContentCleaningService::cleanContent($state, $options);
140-
141-
return $cleanedState;
142-
}
143-
144116
public static function mutateBeforeSaveCallback($record, $field, array $data): array
145117
{
146118
$data = self::ensureRichEditorDataFormat($record, $field, $data);
147119

148-
if (self::shouldAutoCleanContent($field)) {
149-
$data = self::applyContentCleaning($record, $field, $data);
150-
}
151-
152120
return $data;
153121
}
154122

155-
private static function shouldAutoCleanContent($field): bool
156-
{
157-
return $field->config['autoCleanContent'] ?? self::getDefaultConfig()['autoCleanContent'];
158-
}
159-
160-
private static function applyContentCleaning($record, $field, array $data): array
161-
{
162-
$options = self::getCleaningOptions($field);
163-
164-
if (isset($data['values'][$field->ulid])) {
165-
// Called from ContentResource
166-
$data['values'][$field->ulid] = self::cleanRichEditorState($data['values'][$field->ulid], $options);
167-
} elseif (isset($data[$record->valueColumn][$field->ulid])) {
168-
// Called from CanMapDynamicFields trait
169-
$data[$record->valueColumn][$field->ulid] = self::cleanRichEditorState($data[$record->valueColumn][$field->ulid], $options);
170-
}
171-
172-
return $data;
173-
}
174-
175-
private static function getCleaningOptions($field): array
176-
{
177-
return [
178-
'preserveCustomCaptions' => $field->config['preserveCustomCaptions'] ?? self::getDefaultConfig()['preserveCustomCaptions'],
179-
];
180-
}
181-
182123
private static function ensureRichEditorDataFormat($record, $field, array $data): array
183124
{
184125
$data = self::normalizeContentResourceValue($data, $field);
@@ -239,21 +180,6 @@ public function getForm(): array
239180
->multiple()
240181
->options(ToolbarButton::array())
241182
->columnSpanFull(),
242-
Forms\Components\Toggle::make('config.autoCleanContent')
243-
->label(__('Auto-clean content'))
244-
->helperText(__('Automatically remove figcaption and unwrap images from links'))
245-
->inline(false)
246-
->columnSpanFull(),
247-
Forms\Components\Toggle::make('config.preserveCustomCaptions')
248-
->label(__('Preserve custom captions'))
249-
->helperText(__('Only remove default captions, keep custom ones'))
250-
->inline(false)
251-
->columnSpanFull(),
252-
Forms\Components\Toggle::make('config.hideCaptions')
253-
->label(__('Hide caption fields'))
254-
->helperText(__('Hide the caption input field that appears when uploading images'))
255-
->inline(false)
256-
->columnSpanFull(),
257183
]),
258184
]),
259185
])->columnSpanFull(),

0 commit comments

Comments
 (0)