Skip to content

Commit

Permalink
Merge pull request #27 from k4lv15/feature/support-ckeditor5-in-drupa…
Browse files Browse the repository at this point in the history
…l-acceptance

Add support for CKEditor5 in DrupalAcceptance->fillWysiwygEditor
  • Loading branch information
guncha25 authored Mar 8, 2024
2 parents 95be4a1 + 50acc63 commit f8efb6f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Codeception/Module/DrupalAcceptance.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ public function addReferenceFieldItem(FormField $field) {
public function fillWysiwygEditor(IdentifiableFormFieldInterface $field, $content) {
$selector = $this->webdriver->grabAttributeFrom($field->value, 'id');
$script = "jQuery(function(){CKEDITOR.instances[\"$selector\"].setData(\"$content\")});";
// Check if CKEditor5 is in use. If so, override the script as global
// registry of editor instances is no longer available and a different
// approach is used to access them via DOM.
if (!empty($this->webdriver->grabAttributeFrom($field->value, 'data-ckeditor5-id'))) {
$script = "document.querySelector(\"#$selector\").nextSibling.querySelector(\".ck-editor__editable_inline\").ckeditorInstance.setData(\"$content\")";
}
$this->webdriver->executeInSelenium(function (RemoteWebDriver $webDriver) use ($script) {
$webDriver->executeScript($script);
});
Expand Down

0 comments on commit f8efb6f

Please sign in to comment.