From 15d7c264b5da05a98e562ce428abcd9823e49fb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C4=85browski?= <64841871+dabrt@users.noreply.github.com> Date: Tue, 5 Dec 2023 15:31:30 +0100 Subject: [PATCH 1/6] Fix form attribute instructions --- docs/content_management/forms/create_form_attribute.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/content_management/forms/create_form_attribute.md b/docs/content_management/forms/create_form_attribute.md index ff213cafcc..d663f5ee9b 100644 --- a/docs/content_management/forms/create_form_attribute.md +++ b/docs/content_management/forms/create_form_attribute.md @@ -53,6 +53,14 @@ The templates for the forms should look as follows: [[= include_file('code_samples/forms/custom_form_attribute/templates/themes/standard/formtheme/formbuilder_checkbox_with_richtext_description.html.twig') =]] ``` +Then, specify the new template in configuration, under the `twig.form_themes` configuration key: + +``` yaml +twig: + form_themes: + - 'themes//formtheme/formbuilder_checkbox_with_richtext_description.html.twig' +``` + ## Add scripts Now you need to enable the RichText editor. Provide the required script in a new `public/js/formbuilder-richtext-checkbox.js` file: From 7ac050117f5206de4b74b7782a78c04eb874c186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C4=85browski?= <64841871+dabrt@users.noreply.github.com> Date: Thu, 14 Dec 2023 11:55:07 +0100 Subject: [PATCH 2/6] Implement review comments --- docs/content_management/forms/create_form_attribute.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content_management/forms/create_form_attribute.md b/docs/content_management/forms/create_form_attribute.md index d663f5ee9b..896d8ea20b 100644 --- a/docs/content_management/forms/create_form_attribute.md +++ b/docs/content_management/forms/create_form_attribute.md @@ -58,7 +58,7 @@ Then, specify the new template in configuration, under the `twig.form_themes` co ``` yaml twig: form_themes: - - 'themes//formtheme/formbuilder_checkbox_with_richtext_description.html.twig' + - '@ibexadesign/formtheme/formbuilder_checkbox_with_richtext_description.html.twig' ``` ## Add scripts From 6afad3146e7bde06be8163af2b16db59f2f86b93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C4=85browski?= <64841871+dabrt@users.noreply.github.com> Date: Thu, 14 Dec 2023 13:58:30 +0100 Subject: [PATCH 3/6] Changes in code --- .../public/js/formbuilder-richtext-checkbox.js | 12 ++++++++++-- .../Type/CheckboxWithRichtextDescriptionType.php | 4 +++- .../forms/create_form_attribute.md | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/code_samples/forms/custom_form_attribute/public/js/formbuilder-richtext-checkbox.js b/code_samples/forms/custom_form_attribute/public/js/formbuilder-richtext-checkbox.js index d800380f5a..f4e7af75ee 100644 --- a/code_samples/forms/custom_form_attribute/public/js/formbuilder-richtext-checkbox.js +++ b/code_samples/forms/custom_form_attribute/public/js/formbuilder-richtext-checkbox.js @@ -13,8 +13,16 @@ return; } - const CKEditor = richtext.init(richtextContainer); + richtext.init(richtextContainer); } ); }); -})(window, window.document, window.ibexa); + + const openUdw = (config) => { + const openUdwEvent = new CustomEvent('ibexa-open-udw', { detail: config }); + + doc.body.dispatchEvent(openUdwEvent); + }; + + ibexa.addConfig('richText.alloyEditor.callbacks.selectContent', openUdw); +})(window, window.document, window.ibexa); \ No newline at end of file diff --git a/code_samples/forms/custom_form_attribute/src/FormBuilder/Form/Type/CheckboxWithRichtextDescriptionType.php b/code_samples/forms/custom_form_attribute/src/FormBuilder/Form/Type/CheckboxWithRichtextDescriptionType.php index 4ce8f2f28c..24125f936a 100644 --- a/code_samples/forms/custom_form_attribute/src/FormBuilder/Form/Type/CheckboxWithRichtextDescriptionType.php +++ b/code_samples/forms/custom_form_attribute/src/FormBuilder/Form/Type/CheckboxWithRichtextDescriptionType.php @@ -38,7 +38,9 @@ public function buildView(FormView $view, FormInterface $form, array $options): { // pass the Dom object of the richtext doc to the template $dom = new \DOMDocument(); - $dom->loadXML($options['richtext_description']); + if (!empty($options['richtext_description'])) { + $dom->loadXML($options['richtext_description']); + }; $view->vars['richtextDescription'] = $dom; } } diff --git a/docs/content_management/forms/create_form_attribute.md b/docs/content_management/forms/create_form_attribute.md index 896d8ea20b..6ccec645cb 100644 --- a/docs/content_management/forms/create_form_attribute.md +++ b/docs/content_management/forms/create_form_attribute.md @@ -30,7 +30,7 @@ The new Form attribute requires a `FieldAttributeTypeMapper`. Register the mappe ## Add Symfony form type -The attribute needs to be editable for the form creator, so it needs to have a Symfony form type. +The attribute needs to be editable for the form creator, so it needs to have a Symfony form type. Add an `AttributeRichtextDescriptionType.php` file with the form type in the `src/FormBuilder/Form/Type/FieldAttribute` directory: ``` php From b6c8fc60323d169ef6dd9b9825da5756a2be978b Mon Sep 17 00:00:00 2001 From: dabrt Date: Thu, 14 Dec 2023 12:59:18 +0000 Subject: [PATCH 4/6] PHP CS Fixes --- .../Form/Type/CheckboxWithRichtextDescriptionType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code_samples/forms/custom_form_attribute/src/FormBuilder/Form/Type/CheckboxWithRichtextDescriptionType.php b/code_samples/forms/custom_form_attribute/src/FormBuilder/Form/Type/CheckboxWithRichtextDescriptionType.php index 24125f936a..ab4060a679 100644 --- a/code_samples/forms/custom_form_attribute/src/FormBuilder/Form/Type/CheckboxWithRichtextDescriptionType.php +++ b/code_samples/forms/custom_form_attribute/src/FormBuilder/Form/Type/CheckboxWithRichtextDescriptionType.php @@ -40,7 +40,7 @@ public function buildView(FormView $view, FormInterface $form, array $options): $dom = new \DOMDocument(); if (!empty($options['richtext_description'])) { $dom->loadXML($options['richtext_description']); - }; + } $view->vars['richtextDescription'] = $dom; } } From c08fcb1f2fda9ab41b3fe0c40e95ed3908c9c786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C4=85browski?= <64841871+dabrt@users.noreply.github.com> Date: Fri, 15 Dec 2023 10:52:09 +0100 Subject: [PATCH 5/6] Update code_samples/forms/custom_form_attribute/public/js/formbuilder-richtext-checkbox.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: MichaƂ Grabowski --- .../public/js/formbuilder-richtext-checkbox.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code_samples/forms/custom_form_attribute/public/js/formbuilder-richtext-checkbox.js b/code_samples/forms/custom_form_attribute/public/js/formbuilder-richtext-checkbox.js index f4e7af75ee..80a2cd40ca 100644 --- a/code_samples/forms/custom_form_attribute/public/js/formbuilder-richtext-checkbox.js +++ b/code_samples/forms/custom_form_attribute/public/js/formbuilder-richtext-checkbox.js @@ -25,4 +25,4 @@ }; ibexa.addConfig('richText.alloyEditor.callbacks.selectContent', openUdw); -})(window, window.document, window.ibexa); \ No newline at end of file +})(window, window.document, window.ibexa); From ad886a8147e58a4c6168e41d113068bc726faaad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C4=85browski?= <64841871+dabrt@users.noreply.github.com> Date: Fri, 15 Dec 2023 11:21:10 +0100 Subject: [PATCH 6/6] Update docs/content_management/forms/create_form_attribute.md --- docs/content_management/forms/create_form_attribute.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content_management/forms/create_form_attribute.md b/docs/content_management/forms/create_form_attribute.md index 6ccec645cb..9d7615f5a8 100644 --- a/docs/content_management/forms/create_form_attribute.md +++ b/docs/content_management/forms/create_form_attribute.md @@ -30,7 +30,7 @@ The new Form attribute requires a `FieldAttributeTypeMapper`. Register the mappe ## Add Symfony form type -The attribute needs to be editable for the form creator, so it needs to have a Symfony form type. +The attribute must be editable for the form creator, so it needs to have a Symfony form type. Add an `AttributeRichtextDescriptionType.php` file with the form type in the `src/FormBuilder/Form/Type/FieldAttribute` directory: ``` php