Skip to content

Commit

Permalink
fix missing force execution in in order to set attributes even when t…
Browse files Browse the repository at this point in the history
…he Balloon form has still not been used - Issue #3337618 by mvogel
  • Loading branch information
WengerK committed Apr 6, 2024
1 parent 2c1974a commit 3845fc8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- add cpsell project words for Gitlab-CI
- add phpstan.neon in order to ignore new static() errors

### Fixed
- fix missing force execution in in order to set attributes even when the Balloon form has still not been used - Issue #3337618 by mvogel

## [2.2.0] - 2023-10-17
### Added
- CKEditor 5: Allow disabling the Balloon - Issue #3337623 by mvogel, wengerk
Expand Down
2 changes: 1 addition & 1 deletion js/build/editorAdvancedImage.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ export default class EditorAdvancedImageCommand extends Command {
if (element.hasAttribute("id")) {
this.attributes.id = element.getAttribute("id");
}

// Force an execution at refresh time in order to set attributes even when the Balloon form has still not been used.
this.execute(this.attributes);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,39 @@ public function testDefaultClass(): void {
self::assertSame("img-fluid", $eai_input->getValue());
}

/**
* Tests that EditorAdvancedImage default class feature works.
*
* The difference to testDefaultClass() is, that the Editor Advanced Image
* form will not be opened and saved. The default class should be applied
* anyway.
*/
public function testDefaultClassWithoutInteraction(): void {
// Update text format and editor to allow editing of the class attribute via
// the EditorAdvancedImage plugin.
$editor = Editor::load('test_format');
$settings = $editor->getSettings();
$settings['plugins']['editor_advanced_image_image']['enabled_attributes'][] = 'class';
$settings['plugins']['editor_advanced_image_image']['default_class'] = 'img-responsive';
$editor->setSettings($settings)->save();

$page = $this->getSession()->getPage();

$this->drupalGet($this->testNode->toUrl('edit-form'));
$this->waitForEditor();
$assert_session = $this->assertSession();

// Confirm the images widget exists.
$this->assertNotEmpty($image_block = $assert_session->waitForElementVisible('css', ".ck-content .ck-widget.image"));

// Open the Image balloon.
$image_block->click();

// Save the node and confirm that the attribute text is retained.
$page->pressButton('Save');
$this->assertNotEmpty($assert_session->waitForElement('css', 'img[class="img-responsive"]'));
}

/**
* A collection of attribute to enable and ensure works when enabled.
*/
Expand Down Expand Up @@ -320,7 +353,7 @@ public function testDisabledBalloon(): void {

// Ensure the Default Class has been applied directly when the image has
// been added to CKEditor 5.
$this->assertEmpty($assert_session->waitForElement('css', 'img[class="img-responsive"]'));
$this->assertNotEmpty($assert_session->waitForElement('css', 'img[class="img-responsive"]'));

// Ensure that the Editor Advanced Image button is not visible on the Image
// Balloon.
Expand All @@ -329,7 +362,7 @@ public function testDisabledBalloon(): void {

// Save the node and confirm that the attribute text is retained.
$page->pressButton('Save');
$this->assertEmpty($assert_session->waitForElement('css', 'img[class="img-responsive"]'));
$this->assertNotEmpty($assert_session->waitForElement('css', 'img[class="img-responsive"]'));
}

}

0 comments on commit 3845fc8

Please sign in to comment.