Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ui_patterns
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
ui_patterns
Commits
3a2a6707
Commit
3a2a6707
authored
10 months ago
by
Mikael Meulle
Committed by
Pierre Dureau
10 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3456083
by just_like_good_vibes: Add text format trusted callback to WysiwygWidget source
parent
a3595c42
No related branches found
No related tags found
1 merge request
!121
Resolves issue 3456083 (Bug WysiwygWidget)
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Plugin/UiPatterns/Source/WysiwygWidget.php
+42
-7
42 additions, 7 deletions
src/Plugin/UiPatterns/Source/WysiwygWidget.php
with
42 additions
and
7 deletions
src/Plugin/UiPatterns/Source/WysiwygWidget.php
+
42
−
7
View file @
3a2a6707
...
...
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace
Drupal\ui_patterns\Plugin\UiPatterns\Source
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Security\TrustedCallbackInterface
;
use
Drupal\ui_patterns
\SourcePluginBase
;
/**
...
...
@@ -20,7 +21,36 @@ use Drupal\ui_patterns\SourcePluginBase;
* tags = { "widget" }
* )
*/
class
WysiwygWidget
extends
SourcePluginBase
{
class
WysiwygWidget
extends
SourcePluginBase
implements
TrustedCallbackInterface
{
/**
* {@inheritdoc}
*/
public
static
function
trustedCallbacks
()
{
return
[
'textFormat'
];
}
/**
* Customize the text_format element.
*/
public
static
function
textFormat
(
$element
)
{
if
(
!
isset
(
$element
[
'format'
][
'format'
][
'#access'
])
||
$element
[
'format'
][
'format'
][
'#access'
])
{
return
$element
;
}
// See code at Drupal\filter\Element\TextFormat::processTextFormat()
// when the format is not accessible, we need to make it accessible.
$element
[
'format'
][
'format'
][
'#access'
]
=
TRUE
;
$config
=
\Drupal
::
configFactory
()
->
get
(
'filter.settings'
);
$fallback_format
=
$config
->
get
(
'fallback_format'
);
$formats
=
filter_formats
();
// We add the fallback format to the list of options if removed.
if
(
array_key_exists
(
$fallback_format
,
$formats
)
&&
!
array_key_exists
(
$fallback_format
,
$element
[
'format'
][
'format'
][
'#options'
]))
{
$element
[
'format'
][
'format'
][
'#options'
][
$fallback_format
]
=
$formats
[
$fallback_format
]
->
label
();
}
return
$element
;
}
/**
* {@inheritdoc}
...
...
@@ -49,13 +79,18 @@ class WysiwygWidget extends SourcePluginBase {
* {@inheritdoc}
*/
public
function
settingsForm
(
array
$form
,
FormStateInterface
$form_state
):
array
{
return
[
'value'
=>
[
'#type'
=>
'text_format'
,
'#default_value'
=>
$this
->
getSetting
(
'value'
)[
'value'
],
'#format'
=>
$this
->
getSetting
(
'value'
)[
'format'
],
],
$value
=
$this
->
getSetting
(
'value'
);
$element
=
[
'#type'
=>
'text_format'
,
];
if
(
is_array
(
$value
)
&&
array_key_exists
(
"value"
,
$value
))
{
$element
[
'#default_value'
]
=
$value
[
'value'
];
}
if
(
is_array
(
$value
)
&&
array_key_exists
(
"format"
,
$value
))
{
$element
[
'#format'
]
=
$value
[
'format'
];
}
$element
[
'#pre_render'
]
=
[[
static
::
class
,
'textFormat'
]];
return
[
'value'
=>
$element
];
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment