Skip to content

Commit

Permalink
Add allowed_formats 3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinHoutevelts committed Dec 1, 2023
1 parent 0599108 commit 2b45ed6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
This changelog is incomplete. Pull requests with entries before 1.7.0
are welcome.

## [2.2.2] - 2023-01-01
### Added
- Compatibility with `drupal/allowed_formats:^3.0`

## [2.1.5] - 2023-06-21
### Added
- Documentation on where subscribers are called
Expand Down
9 changes: 5 additions & 4 deletions src/Plugin/Field/FieldWidget/MediaWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,14 @@ public function formElement(
];

if (
$this->moduleHandler->moduleExists('allowed_formats')
&& $item->getMedia()->hasField('field_description')
$item->getMedia()->hasField('field_description')
&& ($fieldDefinition = $item->getMedia()->get('field_description')->getFieldDefinition())
&& ($allowedFormats = $fieldDefinition->getThirdPartySettings('allowed_formats'))
&& ($allowedFormats = $fieldDefinition->getThirdPartySettings('allowed_formats') ?: $fieldDefinition->getSetting('allowed_formats'))
) {
$row['data']['description']['#allowed_formats'] = $allowedFormats['allowed_formats'] ?? $allowedFormats;
$row['data']['description']['#after_build'] = ['_allowed_formats_remove_textarea_help'];
if ($this->moduleHandler->moduleExists('allowed_formats')) {
$row['data']['description']['#after_build'] = ['_allowed_formats_remove_textarea_help'];
}
$row['data']['description']['#allowed_format_hide_settings'] = [
'hide_guidelines' => 1,
'hide_help' => 1,
Expand Down

0 comments on commit 2b45ed6

Please sign in to comment.