From c97badfb93e6f45b8e9650e2387887e1b22570fa Mon Sep 17 00:00:00 2001 From: Justin Toupin <21499-justin2pin@users.noreply.drupalcode.org> Date: Thu, 30 Jan 2025 01:54:04 +0000 Subject: [PATCH] Issue #3502083: Fix validation issues for automated testing --- .eslintrc.json | 5 +- .gitlab-ci.yml | 1 + README.md | 11 +- composer.json | 3 +- config/schema/layout_paragraphs.schema.yml | 2 +- css/builder-form.css | 2 +- css/builder.css | 156 +++++++++--------- css/component-list.css | 6 +- css/layout-select.css | 2 +- js/builder-form.js | 13 +- js/builder.js | 130 ++++++++------- js/component-form.js | 8 +- layout_paragraphs.module | 16 +- layout_paragraphs.services.yml | 2 +- .../layout_paragraphs_library.module | 3 +- .../layout_paragraphs_permissions.module | 2 +- ...layout_paragraphs_permissions.services.yml | 2 +- ...youtParagraphsPermissionsBuilderAccess.php | 8 +- src/Access/LayoutParagraphsBuilderAccess.php | 10 +- src/Contracts/ComponentFormInterface.php | 6 +- src/Controller/ChooseComponentController.php | 15 +- src/Controller/ComponentFormController.php | 4 +- src/Controller/DuplicateController.php | 6 +- .../LayoutParagraphsBuilderController.php | 5 +- src/Controller/ReorderController.php | 6 +- src/Element/LayoutParagraphsBuilder.php | 29 ++-- src/Element/LayoutSelect.php | 3 +- .../LayoutParagraphsAllowedTypesEvent.php | 10 +- ...LayoutParagraphsComponentDefaultsEvent.php | 3 +- .../LayoutParagraphsUpdateLayoutEvent.php | 4 +- ...LayoutParagraphsAllowedTypesSubscriber.php | 4 +- ...LayoutParagraphsUpdateLayoutSubscriber.php | 2 +- src/Form/ComponentFormBase.php | 32 ++-- src/Form/DeleteComponentForm.php | 12 +- src/Form/EditComponentForm.php | 11 +- src/Form/InsertComponentForm.php | 22 +-- src/Form/LayoutParagraphsBuilderForm.php | 19 ++- .../LayoutParagraphsSectionsSettingsForm.php | 2 +- src/Form/LayoutParagraphsSettingsForm.php | 2 +- src/LayoutParagraphsLayout.php | 15 +- ...outParagraphsLayoutTempstoreRepository.php | 4 +- src/LayoutParagraphsSection.php | 8 +- .../LayoutParagraphsBuilderFormatter.php | 29 +++- .../LayoutParagraphsFormatter.php | 49 +++++- .../FieldWidget/LayoutParagraphsWidget.php | 30 ++-- .../Behavior/LayoutParagraphsBehavior.php | 51 ++++-- src/Utility/Dialog.php | 4 +- ...ragraphs_complex_permissions_test.info.yml | 4 +- .../src/Access/ReorderAccessByContentType.php | 8 +- ...ut_paragraphs_correct_region_test.info.yml | 2 +- ...ayoutParagraphsRefreshLayoutSubscriber.php | 2 +- ...aragraphs_custom_host_entity_test.info.yml | 2 +- .../src/Entity/LpHostEntity.php | 3 +- .../src/Form/LpHostEntityForm.php | 37 ++++- ...agraphs_empty_component_list_test.info.yml | 2 +- ...LayoutParagraphsAllowedTypesSubscriber.php | 4 +- ...ut_paragraphs_entity_validator_test.module | 9 +- .../LayoutParagraphsTestConstraint.php | 5 + ...ut_paragraphs_form_rendering_test.info.yml | 2 +- .../src/Form/TestForm.php | 6 +- ...paragraphs_preprocess_layout_test.info.yml | 2 +- ...yout_paragraphs_translations_test.info.yml | 2 +- .../src/MockLibrariesDirectoryFileFinder.php | 2 +- tests/src/Functional/LayoutParagraphsTest.php | 2 + .../AlterControlsTest.php | 2 + .../FunctionalJavascript/BlockFieldTest.php | 4 +- .../BuilderAlteredTemplatesTest.php | 2 + .../src/FunctionalJavascript/BuilderTest.php | 12 +- .../FunctionalJavascript/BuilderTestBase.php | 18 +- .../FunctionalJavascript/CardinalityTest.php | 2 + .../ComplexPermissionsTest.php | 2 + .../CorrectRegionTest.php | 9 +- .../CustomHostEntityTest.php | 4 +- .../FunctionalJavascript/DisplayModeTest.php | 7 +- .../DuplicateComponentsTest.php | 2 + .../EmptyComponentListTest.php | 2 + .../FormRenderingTest.php | 2 + .../LayoutParagraphsLibraryTest.php | 4 +- .../LayoutParagraphsPermissionsTest.php | 2 + .../FunctionalJavascript/ModalHeightTest.php | 2 + .../NestedSectionsTest.php | 4 +- .../ParagraphsWidgetCompatibilityTest.php | 4 +- .../PreprocessLayoutTest.php | 2 + .../ReorderFormElementsTest.php | 8 +- .../FunctionalJavascript/TranslationTest.php | 8 +- .../ValidationConstraintTest.php | 4 +- 86 files changed, 583 insertions(+), 386 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index be8252d5..edbdc8fc 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,8 +1,5 @@ { - "extends": [ - "drupal" - ], "globals": { "dragula": true } -} \ No newline at end of file +} diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c6f62cff..243f9ab7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -51,6 +51,7 @@ include: variables: OPT_IN_TEST_PREVIOUS_MINOR: 1 OPT_IN_TEST_NEXT_MINOR: 1 + _CSPELL_WORDS: 'bevacqua, dragula, tooltiptext, Toupin, Italo, Mairo, itamair, autoresize, Fieldto, cclip, cdefs, cpath, crect, csvg' # SKIP_ESLINT: '1' diff --git a/README.md b/README.md index d1c68ef3..e2ee57ec 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,9 @@ seamlessly with existing paragraph reference fields. - Visit https://www.drupal.org/docs/develop/using-composer/manage-dependencies#third-party-libraries for further information. -- Run `composer require bower-asset/dragula drupal/paragraphs drupal/layout_paragraphs` -- Install Layout Paragraps. +- Run `composer require + bower-asset/dragula drupal/paragraphs drupal/layout_paragraphs` +- Install Layout Paragraphs. **Without composer** - Download the [Dragula dist folder](https://github.com/bevacqua/dragula/tree/master/dist) @@ -43,7 +44,7 @@ as you would normally install a contributed Drupal module. - Install the the [Paragraphs module](https://www.drupal.org/project/paragraphs) and the [Layout Paragraphs module](https://www.drupal.org/project/layout_paragraphs) as you would normally install a contributed Drupal module. -- The Dragual library will be automatically loaded via CDN if no local library +- The Dragula library will be automatically loaded via CDN if no local library exists. Visit "[Installing Modules](https://www.drupal.org/node/1897420)", if you have @@ -157,11 +158,11 @@ system. #### Example Code: Working with a Layout ```php -// Instantiate a new layout given an exisitng node +// Instantiate a new layout given an existing node // and the paragraph reference field name. $layout = new LayoutParagraphsLayout($node, $field_name); -// Insert a new component directly after the exisiting paragraph with the given +// Insert a new component directly after the existing paragraph with the given // uuid. This will add the new component into the same section and region as the // paragraph with the given uuid. $layout->insertAfterComponent($existing_paragraph_uuid, $the_new_paragraph); diff --git a/composer.json b/composer.json index 283def5b..0e3fc699 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,7 @@ }, "require-dev": { "drupal/entity_usage": "2.x-dev", - "drupal/block_field": "~1.0" + "drupal/block_field": "~1.0", + "drupal/field_group": "^3.6" } } diff --git a/config/schema/layout_paragraphs.schema.yml b/config/schema/layout_paragraphs.schema.yml index 93c2a2e5..9bdcf259 100644 --- a/config/schema/layout_paragraphs.schema.yml +++ b/config/schema/layout_paragraphs.schema.yml @@ -13,7 +13,7 @@ layout_paragraphs.settings: paragraph_behaviors_label: type: string label: 'Paragraph behaviors label' - descripton: 'The paragraph behaviors form fieldset label' + description: 'The paragraph behaviors form fieldset label' paragraph_behaviors_position: type: integer label: 'Paragraph behaviors fieldset position' diff --git a/css/builder-form.css b/css/builder-form.css index 3536d9ae..c859ef31 100644 --- a/css/builder-form.css +++ b/css/builder-form.css @@ -1,5 +1,5 @@ .lpb-form__actions { - background: rgba(0,0,0,.05); margin-top: 0; padding: 20px; + background: rgba(0, 0, 0, 0.05); } diff --git a/css/builder.css b/css/builder.css index e01d327e..8153ed31 100644 --- a/css/builder.css +++ b/css/builder.css @@ -1,26 +1,26 @@ .lp-builder { - min-height: 30px; position: relative; + min-height: 30px; } .js-lpb-region { + position: relative; + box-sizing: border-box; min-height: 40px; cursor: default; - box-sizing: border-box; - position: relative; } .lpb-empty-container__wrapper { position: relative; } .lpb-empty-container { - text-align: center; padding-bottom: 30px; + text-align: center; } .lpb-empty-toggle { min-height: 20px; } .lpb-empty-message { - text-align: center; padding-bottom: 40px; + text-align: center; } .lpb-empty-container__wrapper .lpb-section-menu__wrapper { bottom: 20px; @@ -33,10 +33,10 @@ outline: 1px dotted white; } .js-lpb-component { + position: relative; + transition: all 0.15s linear; outline: 1px solid blue; outline-color: transparent; - transition: all .15s linear; - position: relative; } .lp-builder:not(.is-navigating) .js-lpb-component:hover, .lp-builder:not(.is-navigating) .js-lpb-component:focus-within { @@ -53,7 +53,9 @@ outline: 1px dotted rgba(0, 0, 255, 0.5); } .lp-builder:not(.is-navigating) .js-lpb-component:hover .js-lpb-region:hover, -.lp-builder:not(.is-navigating) .js-lpb-component:focus-within .js-lpb-region:focus-within { +.lp-builder:not(.is-navigating) + .js-lpb-component:focus-within + .js-lpb-region:focus-within { outline: 1px solid rgba(0, 0, 255, 0.5); } .lpb-layout { @@ -62,8 +64,8 @@ .lpb-layout .lpb-layout-label { position: absolute; right: 0; - border: 1px dotted #ccc; padding: 5px 10px; + border: 1px dotted #ccc; font-size: small; } .js-lpb-btn--add { @@ -73,30 +75,32 @@ position: absolute; } .lpb-controls { - cursor: default; - padding: 5px; - display: flex; - z-index: 80; position: absolute; - left: 0; + z-index: 80; top: 0; + left: 0; + display: flex; + padding: 5px; + cursor: default; opacity: 0; border-radius: 0 0 6px 0; - box-shadow: 0 1px 1px rgba(0, 0, 0, 0.25), 0 1px 3px rgba(0, 0, 0, 0.25); background-color: #fff; + box-shadow: + 0 1px 1px rgba(0, 0, 0, 0.25), + 0 1px 3px rgba(0, 0, 0, 0.25); } .lpb-controls:hover, .lpb-controls:focus-within { z-index: 90; } .lpb-controls.is-layout { - background-color: #00659b; - border-radius: 6px 6px 0 0; - box-shadow: none; - color: #fff; top: -40px; - left: auto; right: -1px; + left: auto; + color: #fff; + border-radius: 6px 6px 0 0; + background-color: #00659b; + box-shadow: none; } .lp-builder:not(.is-navigating) .js-lpb-component:hover > .lpb-controls, .lp-builder:not(.is-navigating) .js-lpb-component:focus-within > .lpb-controls { @@ -106,9 +110,9 @@ font-size: 0; } .lpb-controls-label { + padding: 0 5px 0 10px; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; line-height: 30px; - padding: 0 5px 0 10px; } .lpb-drag, .lpb-up, @@ -116,13 +120,13 @@ .lpb-edit, .lpb-duplicate, .lpb-delete { - cursor: pointer; - height: 30px; width: 30px; - border-radius: 3px; + height: 30px; margin: 0; padding: 0; - opacity: .5; + cursor: pointer; + opacity: 0.5; + border-radius: 3px; } .is-layout .lpb-drag, .is-layout .lpb-up, @@ -133,9 +137,9 @@ opacity: 1; } .lpb-drag { + cursor: grab; background-image: url("data:image/svg+xml,%3Csvg width='30' height='30' viewBox='0 0 30 30' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12.5 11C13.3284 11 14 10.3284 14 9.5C14 8.67157 13.3284 8 12.5 8C11.6716 8 11 8.67157 11 9.5C11 10.3284 11.6716 11 12.5 11Z' fill='%23000000'/%3E%3Cpath d='M12.5 16C13.3284 16 14 15.3284 14 14.5C14 13.6716 13.3284 13 12.5 13C11.6716 13 11 13.6716 11 14.5C11 15.3284 11.6716 16 12.5 16Z' fill='%23000000'/%3E%3Cpath d='M14 19.5C14 20.3284 13.3284 21 12.5 21C11.6716 21 11 20.3284 11 19.5C11 18.6716 11.6716 18 12.5 18C13.3284 18 14 18.6716 14 19.5Z' fill='%23000000'/%3E%3Cpath d='M17.5 11C18.3284 11 19 10.3284 19 9.5C19 8.67157 18.3284 8 17.5 8C16.6716 8 16 8.67157 16 9.5C16 10.3284 16.6716 11 17.5 11Z' fill='%23000000'/%3E%3Cpath d='M19 14.5C19 15.3284 18.3284 16 17.5 16C16.6716 16 16 15.3284 16 14.5C16 13.6716 16.6716 13 17.5 13C18.3284 13 19 13.6716 19 14.5Z' fill='%23000000'/%3E%3Cpath d='M17.5 21C18.3284 21 19 20.3284 19 19.5C19 18.6716 18.3284 18 17.5 18C16.6716 18 16 18.6716 16 19.5C16 20.3284 16.6716 21 17.5 21Z' fill='%23000000'/%3E%3C/svg%3E%0A"); background-size: cover; - cursor: grab; } .is-layout .lpb-drag { background-image: url("data:image/svg+xml,%3Csvg width='30' height='30' viewBox='0 0 30 30' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12.5 11C13.3284 11 14 10.3284 14 9.5C14 8.67157 13.3284 8 12.5 8C11.6716 8 11 8.67157 11 9.5C11 10.3284 11.6716 11 12.5 11Z' fill='white'/%3E%3Cpath d='M12.5 16C13.3284 16 14 15.3284 14 14.5C14 13.6716 13.3284 13 12.5 13C11.6716 13 11 13.6716 11 14.5C11 15.3284 11.6716 16 12.5 16Z' fill='white'/%3E%3Cpath d='M14 19.5C14 20.3284 13.3284 21 12.5 21C11.6716 21 11 20.3284 11 19.5C11 18.6716 11.6716 18 12.5 18C13.3284 18 14 18.6716 14 19.5Z' fill='white'/%3E%3Cpath d='M17.5 11C18.3284 11 19 10.3284 19 9.5C19 8.67157 18.3284 8 17.5 8C16.6716 8 16 8.67157 16 9.5C16 10.3284 16.6716 11 17.5 11Z' fill='white'/%3E%3Cpath d='M19 14.5C19 15.3284 18.3284 16 17.5 16C16.6716 16 16 15.3284 16 14.5C16 13.6716 16.6716 13 17.5 13C18.3284 13 19 13.6716 19 14.5Z' fill='white'/%3E%3Cpath d='M17.5 21C18.3284 21 19 20.3284 19 19.5C19 18.6716 18.3284 18 17.5 18C16.6716 18 16 18.6716 16 19.5C16 20.3284 16.6716 21 17.5 21Z' fill='white'/%3E%3C/svg%3E%0A"); @@ -146,14 +150,14 @@ .lpb-duplicate:hover, .lpb-delete:hover { opacity: 1; - background-color: rgba(0, 0, 0, .1); + background-color: rgba(0, 0, 0, 0.1); } .is-layout .lpb-up:hover, .is-layout .lpb-down:hover, .is-layout .lpb-edit:hover, .is-layout .lpb-duplicate:hover, .is-layout .lpb-delete:hover { - background-color: rgba(0, 0, 0, .25); + background-color: rgba(0, 0, 0, 0.25); } .lpb-drag:focus, .lpb-up:focus, @@ -192,8 +196,8 @@ } .lpb-down[tabindex="-1"], .lpb-up[tabindex="-1"] { - opacity: .3; cursor: default; + opacity: 0.3; } .lpb-edit { background-image: url("data:image/svg+xml,%3Csvg width='30' height='30' viewBox='0 0 30 30' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M18.284 8.63082L19.6136 7.30121C20.0152 6.8996 20.6664 6.8996 21.068 7.30121L22.6988 8.93203C23.1004 9.33365 23.1004 9.98479 22.6988 10.3864L21.3692 11.716L18.284 8.63082Z' fill='%23000000'/%3E%3Cpath d='M17.2556 9.65922L9.0284 17.8864L8 22L12.1136 20.9716L20.3408 12.7444L17.2556 9.65922Z' fill='%23000000'/%3E%3C/svg%3E%0A"); @@ -218,15 +222,15 @@ } .lpb-btn { position: absolute; - display: inline-block; - background: #fff; - border-radius: 10px; - box-shadow: 0 2px 15px rgba(0, 0, 0, .15); z-index: 80; left: 50%; - transform: translateX(-50%); + display: inline-block; padding: 6px 10px; - transition: all .15s linear; + transition: all 0.15s linear; + transform: translateX(-50%); + border-radius: 10px; + background: #fff; + box-shadow: 0 2px 15px rgba(0, 0, 0, 0.15); } .lpb-btn.before { top: -17px; @@ -246,26 +250,28 @@ opacity: 1; } .lpb-btn--add { + position: absolute; + z-index: 80; + left: 50%; width: 24px; height: 24px; - left: 50%; - z-index: 80; - position: absolute; - border: 3px solid white; + margin: auto; cursor: pointer; - box-shadow: 0 1px 1px rgba(0, 0, 0, 0.25), 0 1px 3px rgba(0, 0, 0, 0.25); + transition: all 0.15s linear; + transform: translateX(-50%); + border: 3px solid white; border-radius: 6px; - background-color: #ffffff; + background-color: #fff; background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath opacity='.5' fill-rule='evenodd' clip-rule='evenodd' d='M13 6V11H18V13H13V18H11V12.999L6 13V11L11 10.999V6H13Z' fill='%23130F13'/%3E%3C/svg%3E%0A"); background-size: cover; - margin: auto; - transform: translateX(-50%); - transition: all .15s linear; + box-shadow: + 0 1px 1px rgba(0, 0, 0, 0.25), + 0 1px 3px rgba(0, 0, 0, 0.25); } .lpb-btn--add:hover { + opacity: 1; background-color: #e1e0e1; background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M13 6V11H18V13H13V18H11V12.999L6 13V11L11 10.999V6H13Z' fill='%23130F13'/%3E%3C/svg%3E%0A"); - opacity: 1; } .lpb-btn--add:hover, .lpb-btn:hover, @@ -305,14 +311,14 @@ display: none; } .gu-mirror { - background: #fff; cursor: grabbing; + background: #fff; } form.layout-paragraphs-builder-form { - margin-left: -20px; margin-right: -20px; - outline: 1px solid rgba(0,0,0,.15); + margin-left: -20px; + outline: 1px solid rgba(0, 0, 0, 0.15); } form.layout-paragraphs-builder-form .js-lpb-component-list { @@ -320,14 +326,14 @@ form.layout-paragraphs-builder-form .js-lpb-component-list { } .lpb-enable { - display: flex; - justify-content: center; - left: 0; - opacity: 0; position: absolute; - right: 0; top: 0; + right: 0; + left: 0; + display: flex; + justify-content: center; transform: translateY(-50%); + opacity: 0; } .lpb-enable__button { @@ -335,35 +341,35 @@ form.layout-paragraphs-builder-form .js-lpb-component-list { } a.lpb-enable-button { + display: flex; align-items: center; - background-color: #00659b; + padding: 3px 12px 3px 0; + color: white; border: none; border-radius: 3px; - color: white; - display: flex; + background-color: #00659b; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; - padding: 3px 12px 3px 0; } a.lpb-enable-button:hover, a.lpb-enable-button:focus { padding: 3px 12px 3px 0; - border-bottom-style: none; color: white; + border-bottom-style: none; outline: none; } a.lpb-enable-button::before { - content: ""; display: block; - height: 30px; width: 30px; - border-radius: 3px; + height: 30px; margin: 0; padding: 0; - opacity: .5; + content: ""; + opacity: 0.5; + border-radius: 3px; background-image: url("data:image/svg+xml,%3Csvg width='30' height='30' viewBox='0 0 30 30' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M18.284 8.63082L19.6136 7.30121C20.0152 6.8996 20.6664 6.8996 21.068 7.30121L22.6988 8.93203C23.1004 9.33365 23.1004 9.98479 22.6988 10.3864L21.3692 11.716L18.284 8.63082Z' fill='white'/%3E%3Cpath d='M17.2556 9.65922L9.0284 17.8864L8 22L12.1136 20.9716L20.3408 12.7444L17.2556 9.65922Z' fill='white'/%3E%3C/svg%3E%0A"); - background-position: 50% 50%; background-repeat: no-repeat; + background-position: 50% 50%; } .lpb-formatter { position: relative; @@ -379,26 +385,26 @@ a.lpb-enable-button::before { } .lpb-tooltiptext { - opacity: 0; - pointer-events: none; - transition: all .15s linear; - width: auto; - background-color: black; - color: #fff; - text-align: center; - padding: 10px; position: absolute; z-index: 90; bottom: 100%; left: -7px; + width: auto; margin-bottom: -2px; + padding: 10px; + transition: all 0.15s linear; + text-align: center; white-space: nowrap; + pointer-events: none; + opacity: 0; + color: #fff; + background-color: black; } .lpb-tooltiptext::after { - content: " "; position: absolute; top: 100%; /* At the bottom of the tooltip */ left: 20px; + content: " "; border-width: 7px; border-style: solid; border-color: black transparent transparent transparent; @@ -412,10 +418,10 @@ a.lpb-enable-button::before { opacity: 1; } .js-lpb-ui-message { - background-color: #000; - color: #fff; - text-align: center; position: static; + text-align: center; + color: #fff; + background-color: #000; } .ck.ck-balloon-panel.ck-balloon-panel_visible { diff --git a/css/component-list.css b/css/component-list.css index 53084d64..81efc9b0 100644 --- a/css/component-list.css +++ b/css/component-list.css @@ -9,12 +9,12 @@ } .lpb-component-list__item a { - align-items: center; display: flex; - margin-top: 10px; + align-items: center; width: 100%; + margin-top: 10px; } .lpb-component-list__item img { - margin-right: 10px; max-width: 24px; + margin-right: 10px; } diff --git a/css/layout-select.css b/css/layout-select.css index d84ddeb2..bfbd1646 100644 --- a/css/layout-select.css +++ b/css/layout-select.css @@ -13,8 +13,8 @@ outline: 1px solid #ccc; } .layout-select__item input:checked + label.option { + transition: 0.1s all; outline: 2px solid blue; - transition: .1s all; font-weight: bold; } .layout-select__item-icon { diff --git a/js/builder-form.js b/js/builder-form.js index 916cf7e4..b87c8056 100644 --- a/js/builder-form.js +++ b/js/builder-form.js @@ -17,13 +17,12 @@ 'lpb-component:move.lpb', 'lpb-component:drop.lpb', ].join(' '); - $(once('lpb-builder-form', '[data-lpb-id]', context)) - .on(events, (e) => { - $(e.currentTarget) - .closest('[data-lpb-form-id]') - .find('[data-drupal-selector="edit-close"]') - .val(Drupal.t('Cancel')); - }); + $(once('lpb-builder-form', '[data-lpb-id]', context)).on(events, (e) => { + e.currentTarget + .closest('[data-lpb-form-id]') + .querySelector('[data-drupal-selector="edit-close"]').value = + Drupal.t('Cancel'); + }); }, }; })(jQuery, Drupal, once); diff --git a/js/builder.js b/js/builder.js index 6af8e5ca..440e9fe5 100644 --- a/js/builder.js +++ b/js/builder.js @@ -39,19 +39,20 @@ return; } $dialogs.each((i, dialog) => { - const bounding = dialog.getBoundingClientRect(); - const viewPortHeight = + let bounding = dialog.getBoundingClientRect(); + let viewPortHeight = window.innerHeight || document.documentElement.clientHeight; if (bounding.bottom > viewPortHeight) { const $dialog = $('.ui-dialog-content', dialog); const height = viewPortHeight - 200; $dialog.dialog('option', 'height', height); - $dialog.css('overscroll-behavior', 'contain'); + $dialog[0].style.overscrollBehavior = 'contain'; if ($dialog.data('lpOriginalHeight') !== height) { $dialog.data('lpOriginalHeight', height); - const bounding = dialog.getBoundingClientRect(); - const viewPortHeight = window.innerHeight || document.documentElement.clientHeight; + bounding = dialog.getBoundingClientRect(); + viewPortHeight = + window.innerHeight || document.documentElement.clientHeight; if (bounding.bottom > viewPortHeight) { const pos = $dialog.dialog('option', 'position'); $dialog.dialog('option', 'position', pos); @@ -121,9 +122,7 @@ */ function movesErrors(settings, el, source, handle) { return Drupal._lpbMoveErrors.moves - .map((validator) => - validator.apply(null, [settings, el, source, handle]), - ) + .map((validator) => validator.apply(null, [settings, el, source, handle])) .filter((errors) => errors !== false && errors !== undefined); } @@ -132,8 +131,12 @@ * @param {jQuery} $element The builder element. */ function updateMoveButtons($element) { - const lpbBuilderElements = Array.from($element[0].querySelectorAll('.js-lpb-component-list, .js-lpb-region')); - const lpbBuilderComponent = lpbBuilderElements.filter(el => el.querySelector('.js-lpb-component')); + const lpbBuilderElements = Array.from( + $element[0].querySelectorAll('.js-lpb-component-list, .js-lpb-region'), + ); + const lpbBuilderComponent = lpbBuilderElements.filter((el) => + el.querySelector('.js-lpb-component'), + ); $element[0].querySelectorAll('.lpb-up, .lpb-down').forEach((el) => { // Set the tabindex of the up and down arrows to 0. @@ -141,31 +144,37 @@ }); lpbBuilderComponent.forEach((el) => { - const components = Array.from(el.children).filter(n => n.classList.contains('js-lpb-component')); + const components = Array.from(el.children).filter((n) => + n.classList.contains('js-lpb-component'), + ); if (components.length > 0) { // Set the tabindex of the first component's up arrow to -1. components[0].querySelector('.lpb-up')?.setAttribute('tabindex', '-1'); // Set the tabindex of the last component's down arrow to -1. - components[components.length - 1].querySelector('.lpb-down')?.setAttribute('tabindex', '-1'); + components[components.length - 1] + .querySelector('.lpb-down') + ?.setAttribute('tabindex', '-1'); } }); } /** * Hides the add content button in regions that contain components. - * @param {jQuery} $element The builder element. + * @param {HTMLElement} element The builder element. */ - function hideEmptyRegionButtons($element) { - $element.find('.js-lpb-region').each((i, e) => { - const $e = $(e); - if ($e.find('.js-lpb-component').length === 0) { - $e.find('.lpb-btn--add.center').css('display', 'block'); - } else { - $e.find('.lpb-btn--add.center').css('display', 'none'); - } - }); + function hideEmptyRegionButtons(element) { + element + .querySelectorAll('.lpb-btn--add.center') + .forEach((buttonElement) => { + const regionElement = buttonElement.closest('.js-lpb-region'); + if (regionElement?.querySelector('.js-lpb-component')) { + buttonElement.style.display = 'none'; + } else { + buttonElement.style.display = 'block'; + } + }); } /** @@ -175,7 +184,7 @@ function updateUi($element) { reorderComponents($element); updateMoveButtons($element); - hideEmptyRegionButtons($element); + hideEmptyRegionButtons($element[0]); } /** @@ -199,16 +208,19 @@ } // Determine if the move should be animated horizontally or vertically. - const animateProp = $sibling[0].getBoundingClientRect().top == $moveItem[0].getBoundingClientRect().top - ? 'translateX' - : 'translateY'; + const animateProp = + $sibling[0].getBoundingClientRect().top === + $moveItem[0].getBoundingClientRect().top + ? 'translateX' + : 'translateY'; // Determine the dimension property to use for the animation. - const dimmensionProp = animateProp === 'translateX' ? 'offsetWidth' : 'offsetHeight'; + const dimensionProp = + animateProp === 'translateX' ? 'offsetWidth' : 'offsetHeight'; // Determine the distance to move the sibling and the item. - const siblingDest = $moveItem[0][dimmensionProp] * direction * -1; - const itemDest = $sibling[0][dimmensionProp] * direction; + const siblingDest = $moveItem[0][dimensionProp] * direction * -1; + const itemDest = $sibling[0][dimensionProp] * direction; const distance = Math.abs(Math.max(siblingDest, itemDest)); - const duration = distance * .25; + const duration = distance * 0.25; const siblingKeyframes = [ { transform: `${animateProp}(0)` }, { transform: `${animateProp}(${siblingDest}px)` }, @@ -219,12 +231,12 @@ ]; const timing = { duration, - iterations: 1 - } + iterations: 1, + }; const anim1 = $moveItem[0].animate(itemKeyframes, timing); anim1.onfinish = () => { - $moveItem.css({ transform: 'none' }); - $sibling.css({ transform: 'none' }); + $moveItem[0].style.transform = 'none'; + $sibling[0].style.transform = 'none'; $sibling[method]($moveItem); $moveItem .closest(`[${idAttr}]`) @@ -414,19 +426,20 @@ } function initDragAndDrop($element, settings) { - const containers = once('is-dragula-enabled', '.js-lpb-component-list, .js-lpb-region', $element[0]); - const drake = dragula( - containers, - { - accepts: (el, target, source, sibling) => - acceptsErrors(settings, el, target, source, sibling).length === 0, - moves: (el, source, handle) => - movesErrors(settings, el, source, handle).length === 0, - }, + const containers = once( + 'is-dragula-enabled', + '.js-lpb-component-list, .js-lpb-region', + $element[0], ); + const drake = dragula(containers, { + accepts: (el, target, source, sibling) => + acceptsErrors(settings, el, target, source, sibling).length === 0, + moves: (el, source, handle) => + movesErrors(settings, el, source, handle).length === 0, + }); drake.on('drop', (el) => { const $el = $(el); - if ($el.prev().is('a')) { + if ($el.prev()[0]?.matches('a')) { $el.insertBefore($el.prev()); } $element.trigger('lpb-component:drop', [$el.attr('data-uuid')]); @@ -457,13 +470,13 @@ // An object with arrays for "accepts" and "moves" dragula callback functions. Drupal._lpbMoveErrors = { - 'accepts': [], - 'moves': [], + accepts: [], + moves: [], }; /** * Registers a move validation function. * @param {Function} f The validator function. - * @param {String} t The dragula callback to register the validator for. + * @param {String} c The dragula callback to register the validator for. */ Drupal.registerLpbMoveError = (f, c = 'accepts') => { Drupal._lpbMoveErrors[c].push(f); @@ -521,21 +534,24 @@ } const buttons = []; - const $buttons = $lpDialog.find('.layout-paragraphs-component-form > .form-actions input[type=submit], .layout-paragraphs-component-form > .form-actions a.button'); + const $buttons = $lpDialog.find( + '.layout-paragraphs-component-form > .form-actions input[type=submit], .layout-paragraphs-component-form > .form-actions a.button', + ); if ($buttons.length === 0) { return; } $buttons.each((_i, el) => { - const $originalButton = $(el).css({ display: 'none' }); + const $originalButton = $(el); + $originalButton[0].style.display = 'none'; buttons.push({ text: $originalButton.html() || $originalButton.attr('value'), class: $originalButton.attr('class'), click(e) { // If the original button is an anchor tag, triggering the "click" // event will not simulate a click. Use the click method instead. - if ($originalButton.is('a')) { + if ($originalButton[0].matches('a')) { $originalButton[0].click(); } else { $originalButton @@ -561,10 +577,13 @@ // Listen to relevant events and update UI. once('lpb-events', '[data-lpb-id]').forEach((el) => { - $(el).on('lpb-builder:init.lpb lpb-component:insert.lpb lpb-component:update.lpb lpb-component:move.lpb lpb-component:drop.lpb lpb-component:delete.lpb', (e) => { - const $element = $(e.currentTarget); - updateUi($element); - }); + $(el).on( + 'lpb-builder:init.lpb lpb-component:insert.lpb lpb-component:update.lpb lpb-component:move.lpb lpb-component:drop.lpb lpb-component:delete.lpb', + (e) => { + const $element = $(e.currentTarget); + updateUi($element); + }, + ); }); // Initialize the editor drag and drop ui. @@ -616,7 +635,7 @@ clearInterval(lpDialogInterval); lpDialogInterval = setInterval( repositionDialog.bind(null, lpDialogInterval), - 500 + 500, ); } }; @@ -625,5 +644,4 @@ } else { window.addEventListener('dialog:aftercreate', handleAfterDialogCreate); } - })(jQuery, Drupal, Drupal.debounce, dragula, once); diff --git a/js/component-form.js b/js/component-form.js index a1a2dacb..b825b463 100644 --- a/js/component-form.js +++ b/js/component-form.js @@ -1,6 +1,6 @@ -(function ($, Drupal) { +(($, Drupal) => { Drupal.behaviors.layoutParagraphsComponentForm = { - attach: function attach(context) { + attach: function attach() { // The layout selection element uses AJAX to load the layout config form. // We need to disable the save button while waiting for the AJAX request, // to prevent race UI condition. @@ -11,6 +11,6 @@ // Re-enable the component form save button when the behavior reattaches, // which will happen once the AJAX request completes. $('.lpb-btn--save').prop('disabled', false); - } - } + }, + }; })(jQuery, Drupal); diff --git a/layout_paragraphs.module b/layout_paragraphs.module index a4828205..0d2ae300 100644 --- a/layout_paragraphs.module +++ b/layout_paragraphs.module @@ -126,7 +126,7 @@ function layout_paragraphs_module_implements_alter(&$implementations, $hook) { } /** - * Implements hook_prepreprocess_radios(). + * Implements hook_preprocess_radios(). * * Add wrapper class for layout selection. */ @@ -160,7 +160,7 @@ function layout_paragraphs_preprocess_layout_paragraphs_builder_controls(&$varia 'lpb-tooltip--hover', 'lpb-tooltip--focus', ], - 'aria-describedy' => $id . '--tip', + 'aria-describedby' => $id . '--tip', ], '#weight' => 10, ], @@ -182,7 +182,7 @@ function layout_paragraphs_preprocess_layout_paragraphs_builder_controls(&$varia '#attributes' => [ 'class' => ['lpb-controls-label'], ], - '#value' => $entity->getParagraphType()->label, + '#value' => $entity->getParagraphType()->get('label'), '#weight' => 30, ], 'move_up' => [ @@ -335,6 +335,7 @@ function layout_paragraphs_paragraph_presave(ParagraphInterface $paragraph) { } // If the parent component cannot be loaded, we are not cloning. + /** @var \Drupal\paragraphs\Entity\Paragraph|NULL $parent_component */ $parent_component = \Drupal::service('entity.repository') ->loadEntityByUuid('paragraph', $parent_uuid); if (empty($parent_component)) { @@ -351,8 +352,11 @@ function layout_paragraphs_paragraph_presave(ParagraphInterface $paragraph) { // the paragraph's parent's host's id, we ARE cloning. if ($host->id() !== $parent_host->id()) { + $uuid_map = []; + // Map the UUIDs to deltas from the clone source. $items = _layout_paragraphs_get_paragraphs($parent_component); + /** @var \Drupal\paragraphs\Entity\Paragraph $item */ foreach ($items as $delta => $item) { $uuid_map[$item->uuid()] = $delta; } @@ -360,6 +364,7 @@ function layout_paragraphs_paragraph_presave(ParagraphInterface $paragraph) { // Map the deltas to UUIds from the clone destination. $items = _layout_paragraphs_get_paragraphs($paragraph); $delta_map = []; + /** @var \Drupal\paragraphs\Entity\Paragraph $item */ foreach ($items as $delta => $item) { $delta_map[$delta] = $item->uuid(); } @@ -385,6 +390,7 @@ function layout_paragraphs_paragraph_presave(ParagraphInterface $paragraph) { */ function layout_paragraphs_entity_translation_create(FieldableEntityInterface $entity) { $entity_type_manager = \Drupal::entityTypeManager(); + /** @var \Drupal\Core\Entity\RevisionableStorageInterface $paragraph_storage */ $paragraph_storage = $entity_type_manager->getStorage('paragraph'); /** @var \Drupal\field\FieldConfigInterface[] $field_definitions */ $field_definitions = $entity_type_manager->getStorage('field_config') @@ -468,8 +474,8 @@ function layout_paragraphs_entity_translation_create(FieldableEntityInterface $e * @param \Drupal\paragraphs\ParagraphInterface $paragraph * The paragraph to use for finding the complete list of siblings. * - * @return \Drupal\Core\Field\EntityReferenceFieldItemList - * The list of paragraphs. + * @return array + * The list of paragraph entities. */ function _layout_paragraphs_get_paragraphs(ParagraphInterface $paragraph) { $host = $paragraph->getParentEntity(); diff --git a/layout_paragraphs.services.yml b/layout_paragraphs.services.yml index 19a626d9..3a4fe41e 100644 --- a/layout_paragraphs.services.yml +++ b/layout_paragraphs.services.yml @@ -23,6 +23,6 @@ services: layout_paragraphs.builder_access: class: Drupal\layout_paragraphs\Access\LayoutParagraphsBuilderAccess arguments: - - '@entity_type.manager' + - '@entity_type.manager' tags: - { name: access_check, applies_to: _layout_paragraphs_builder_access } diff --git a/modules/layout_paragraphs_library/layout_paragraphs_library.module b/modules/layout_paragraphs_library/layout_paragraphs_library.module index 2c6c408a..7e6b27df 100644 --- a/modules/layout_paragraphs_library/layout_paragraphs_library.module +++ b/modules/layout_paragraphs_library/layout_paragraphs_library.module @@ -142,6 +142,7 @@ function layout_paragraphs_library_submit(&$form, FormStateInterface $form_state /** @var \Drupal\paragraphs_library\Entity\LibraryItem $library_item */ $library_item = $paragraph->get('field_reusable_paragraph')->entity; if ($library_item) { + /** @var \Drupal\paragraphs\Entity\Paragraph $original_paragraph */ $original_paragraph = $library_item->get('paragraphs')->entity; $form_object->setParagraph($original_paragraph); $new_paragraph = $original_paragraph; @@ -196,7 +197,7 @@ function layout_paragraphs_library_ajax(&$form, FormStateInterface $form_state) if ($command['command'] == 'insert' && $command['selector'] == $wrong_selector) { $command['selector'] = $correct_selector; } - }; + } return $response; } else { diff --git a/modules/layout_paragraphs_permissions/layout_paragraphs_permissions.module b/modules/layout_paragraphs_permissions/layout_paragraphs_permissions.module index 20fe7c5c..7e08d22d 100644 --- a/modules/layout_paragraphs_permissions/layout_paragraphs_permissions.module +++ b/modules/layout_paragraphs_permissions/layout_paragraphs_permissions.module @@ -36,7 +36,7 @@ function layout_paragraphs_permissions_preprocess_layout_paragraphs_builder(&$va * @param string $operation * The operation (i.e. "reorder" or "edit"). * - * @return AccessResult + * @return \Drupal\Core\Access\AccessResultInterface * The access. */ function layout_paragraphs_permissions_access(LayoutParagraphsLayout $layout_paragraphs_layout, string $operation) { diff --git a/modules/layout_paragraphs_permissions/layout_paragraphs_permissions.services.yml b/modules/layout_paragraphs_permissions/layout_paragraphs_permissions.services.yml index 8d63af8a..e6f05a00 100644 --- a/modules/layout_paragraphs_permissions/layout_paragraphs_permissions.services.yml +++ b/modules/layout_paragraphs_permissions/layout_paragraphs_permissions.services.yml @@ -2,6 +2,6 @@ services: layout_paragraphs.builder_access: class: Drupal\layout_paragraphs_permissions\Access\LayoutParagraphsPermissionsBuilderAccess arguments: - - '@entity_type.manager' + - '@entity_type.manager' tags: - { name: access_check, applies_to: _layout_paragraphs_builder_access } diff --git a/modules/layout_paragraphs_permissions/src/Access/LayoutParagraphsPermissionsBuilderAccess.php b/modules/layout_paragraphs_permissions/src/Access/LayoutParagraphsPermissionsBuilderAccess.php index d8e760fb..67c5eda2 100644 --- a/modules/layout_paragraphs_permissions/src/Access/LayoutParagraphsPermissionsBuilderAccess.php +++ b/modules/layout_paragraphs_permissions/src/Access/LayoutParagraphsPermissionsBuilderAccess.php @@ -14,14 +14,14 @@ use Drupal\Core\Access\AccessResult; class LayoutParagraphsPermissionsBuilderAccess extends LayoutParagraphsBuilderAccess { /** - * {@inheritDoc} + * {@inheritdoc} */ public function access( AccountInterface $account, LayoutParagraphsLayout $layout_paragraphs_layout, - string $operation = NULL, - string $component_uuid = NULL, - ParagraphsTypeInterface $paragraph_type = NULL + ?string $operation = NULL, + ?string $component_uuid = NULL, + ?ParagraphsTypeInterface $paragraph_type = NULL, ) { $access = parent::access($account, $layout_paragraphs_layout, $operation, $component_uuid, $paragraph_type); if ($operation == 'reorder') { diff --git a/src/Access/LayoutParagraphsBuilderAccess.php b/src/Access/LayoutParagraphsBuilderAccess.php index b3fade4e..4d64a92b 100644 --- a/src/Access/LayoutParagraphsBuilderAccess.php +++ b/src/Access/LayoutParagraphsBuilderAccess.php @@ -33,7 +33,7 @@ class LayoutParagraphsBuilderAccess implements AccessInterface { } /** - * {@inheritDoc} + * {@inheritdoc} * * @param \Drupal\Core\Session\AccountInterface $account * The account to check access for. @@ -46,15 +46,15 @@ class LayoutParagraphsBuilderAccess implements AccessInterface { * @param \Drupal\paragraphs\ParagraphsTypeInterface $paragraph_type * The paragraph type of a component being added. * - * @return \Drupal\Core\Access\AccessResult + * @return \Drupal\Core\Access\AccessResultInterface * The access result. */ public function access( AccountInterface $account, LayoutParagraphsLayout $layout_paragraphs_layout, - string $operation = NULL, - string $component_uuid = NULL, - ParagraphsTypeInterface $paragraph_type = NULL + ?string $operation = NULL, + ?string $component_uuid = NULL, + ?ParagraphsTypeInterface $paragraph_type = NULL, ) { // Check field access. diff --git a/src/Contracts/ComponentFormInterface.php b/src/Contracts/ComponentFormInterface.php index 5493a486..b0b9ec3d 100644 --- a/src/Contracts/ComponentFormInterface.php +++ b/src/Contracts/ComponentFormInterface.php @@ -57,7 +57,7 @@ interface ComponentFormInterface extends FormInterface { * * @param array $element * The form element. - * @param Drupal\Core\Form\FormStateInterface $form_state + * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state. * @param array $form * The complete form array. @@ -74,7 +74,7 @@ interface ComponentFormInterface extends FormInterface { * * @param array $element * The form element. - * @param Drupal\Core\Form\FormStateInterface $form_state + * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state. * @param array $form * The complete form array. @@ -85,7 +85,7 @@ interface ComponentFormInterface extends FormInterface { public function behaviorPluginsForm(array $element, FormStateInterface $form_state, array &$form); /** - * Provides an Ajax reponse to inject the new / editing component. + * Provides an Ajax response to inject the new / editing component. * * @param array $form * The form array. diff --git a/src/Controller/ChooseComponentController.php b/src/Controller/ChooseComponentController.php index 222cf69e..9ea1dac0 100644 --- a/src/Controller/ChooseComponentController.php +++ b/src/Controller/ChooseComponentController.php @@ -32,7 +32,7 @@ class ChooseComponentController extends ControllerBase { /** * The entity type bundle info service. * - * @var \Drupal\Core\Entity\EntityTypeBundleInfo + * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface */ protected $entityTypeBundleInfo; @@ -57,7 +57,7 @@ class ChooseComponentController extends ControllerBase { } /** - * {@inheritDoc} + * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( @@ -78,11 +78,8 @@ class ChooseComponentController extends ControllerBase { * The build array. */ public function list(Request $request, LayoutParagraphsLayout $layout_paragraphs_layout) { - $route_params = [ - 'layout_paragraphs_layout' => $layout_paragraphs_layout->id(), - ]; $context = $this->getContextFromRequest($request); - // If inserting a new item adjecent to a sibling component, the region + // If inserting a new item adjacent to a sibling component, the region // passed in the URL will be incorrect if the existing sibling component // was dragged into another region. In that case, always use the existing // sibling's region. @@ -97,7 +94,7 @@ class ChooseComponentController extends ControllerBase { return $this->componentForm(key($types), $layout_paragraphs_layout, $context); } else { - return $this->componentMenu($types, $route_params, $context); + return $this->componentMenu($types); } } @@ -202,7 +199,7 @@ class ChooseComponentController extends ControllerBase { * The request object. * * @return array - * The context into which the new component is being iserted. + * The context into which the new component is being inserted. */ protected function getContextFromRequest(Request $request) { return [ @@ -270,7 +267,6 @@ class ChooseComponentController extends ControllerBase { 'layout_paragraphs_layout' => $layout->id(), 'paragraph_type_id' => $paragraphs_type->id(), ]; - $query_params = $context; $types[$bundle] = [ 'id' => $paragraphs_type->id(), 'label' => $paragraphs_type->label(), @@ -295,6 +291,7 @@ class ChooseComponentController extends ControllerBase { */ protected function getSortedAllowedTypes(array $settings) { $bundles = $this->entityTypeBundleInfo->getBundleInfo('paragraph'); + $return_bundles = []; if (!empty($settings['target_bundles'])) { if (isset($settings['negate']) && $settings['negate'] == '1') { $bundles = array_diff_key($bundles, $settings['target_bundles']); diff --git a/src/Controller/ComponentFormController.php b/src/Controller/ComponentFormController.php index 0fd36ff3..16837770 100644 --- a/src/Controller/ComponentFormController.php +++ b/src/Controller/ComponentFormController.php @@ -38,7 +38,7 @@ class ComponentFormController extends ControllerBase { } /** - * {@inheritDoc} + * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( @@ -57,7 +57,7 @@ class ComponentFormController extends ControllerBase { * The paragraph type id. * * @return array|\Drupal\Core\Ajax\AjaxResponse - * A build array or Ajax respone. + * A build array or Ajax response. */ public function insertForm(Request $request, LayoutParagraphsLayout $layout_paragraphs_layout, string $paragraph_type_id) { diff --git a/src/Controller/DuplicateController.php b/src/Controller/DuplicateController.php index 110695da..df0f5c56 100755 --- a/src/Controller/DuplicateController.php +++ b/src/Controller/DuplicateController.php @@ -30,14 +30,14 @@ class DuplicateController extends ControllerBase { protected $tempstore; /** - * {@inheritDoc} + * {@inheritdoc} */ public function __construct(LayoutParagraphsLayoutTempstoreRepository $tempstore) { $this->tempstore = $tempstore; } /** - * {@inheritDoc} + * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( @@ -54,7 +54,7 @@ class DuplicateController extends ControllerBase { * The source component to be cloned. * * @return array|\Drupal\Core\Ajax\AjaxResponse - * A build array or Ajax respone. + * A build array or Ajax response. */ public function duplicate(LayoutParagraphsLayout $layout_paragraphs_layout, string $source_uuid) { $this->setLayoutParagraphsLayout($layout_paragraphs_layout); diff --git a/src/Controller/LayoutParagraphsBuilderController.php b/src/Controller/LayoutParagraphsBuilderController.php index c56c5409..f278c862 100644 --- a/src/Controller/LayoutParagraphsBuilderController.php +++ b/src/Controller/LayoutParagraphsBuilderController.php @@ -9,7 +9,6 @@ use Drupal\Core\Session\AccountInterface; use Drupal\Core\Controller\ControllerBase; use Symfony\Component\HttpFoundation\Request; use Drupal\Core\Entity\ContentEntityInterface; -use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\layout_paragraphs\LayoutParagraphsLayout; use Drupal\Core\Entity\EntityDisplayRepositoryInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -47,7 +46,7 @@ class LayoutParagraphsBuilderController extends ControllerBase { protected $layoutParagraphsBuilderAccess; /** - * {@inheritDoc} + * {@inheritdoc} */ public function __construct(LayoutParagraphsLayoutTempstoreRepository $tempstore, EntityDisplayRepositoryInterface $entity_display_repository, $layout_paragraphs_builder_access) { $this->tempstore = $tempstore; @@ -56,7 +55,7 @@ class LayoutParagraphsBuilderController extends ControllerBase { } /** - * {@inheritDoc} + * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( diff --git a/src/Controller/ReorderController.php b/src/Controller/ReorderController.php index 823f0567..afaa5d51 100644 --- a/src/Controller/ReorderController.php +++ b/src/Controller/ReorderController.php @@ -28,14 +28,14 @@ class ReorderController extends ControllerBase { protected $tempstore; /** - * {@inheritDoc} + * {@inheritdoc} */ public function __construct(LayoutParagraphsLayoutTempstoreRepository $tempstore) { $this->tempstore = $tempstore; } /** - * {@inheritDoc} + * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( @@ -46,7 +46,7 @@ class ReorderController extends ControllerBase { /** * Reorders a Layout Paragraphs Layout's components. * - * Expects an two-dimmensional array of components in the "components" POST + * Expects an two-dimensional array of components in the "components" POST * parameter with key/value pairs for "uuid", "parent_uuid", and "region". * * @param \Symfony\Component\HttpFoundation\Request $request diff --git a/src/Element/LayoutParagraphsBuilder.php b/src/Element/LayoutParagraphsBuilder.php index 7334ecc1..f18841a8 100644 --- a/src/Element/LayoutParagraphsBuilder.php +++ b/src/Element/LayoutParagraphsBuilder.php @@ -2,23 +2,23 @@ namespace Drupal\layout_paragraphs\Element; +use Drupal\Core\Url; +use Drupal\Core\Render\Markup; use Drupal\Component\Serialization\Json; +use Drupal\Core\Render\RendererInterface; +use Drupal\paragraphs\ParagraphInterface; use Drupal\Core\Access\AccessResultAllowed; +use Drupal\layout_paragraphs\Utility\Dialog; use Drupal\Core\Access\AccessResultForbidden; -use Drupal\Core\Entity\EntityTypeBundleInfoInterface; +use Drupal\Core\Render\Element\RenderElementBase; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Layout\LayoutPluginManagerInterface; +use Drupal\Core\Entity\EntityTypeBundleInfoInterface; +use Drupal\layout_paragraphs\LayoutParagraphsSection; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\Core\Render\Element\RenderElement; -use Drupal\Core\Render\Markup; -use Drupal\Core\Render\RendererInterface; -use Drupal\Core\Url; use Drupal\layout_paragraphs\LayoutParagraphsComponent; -use Drupal\layout_paragraphs\LayoutParagraphsLayoutTempstoreRepository; -use Drupal\layout_paragraphs\LayoutParagraphsSection; -use Drupal\layout_paragraphs\Utility\Dialog; -use Drupal\paragraphs\ParagraphInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\layout_paragraphs\LayoutParagraphsLayoutTempstoreRepository; /** * Defines a render element for building the Layout Builder UI. @@ -28,7 +28,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * @internal * Plugin classes are internal. */ -class LayoutParagraphsBuilder extends RenderElement implements ContainerFactoryPluginInterface { +class LayoutParagraphsBuilder extends RenderElementBase implements ContainerFactoryPluginInterface { /** * The layout paragraphs tempstore service. @@ -80,7 +80,7 @@ class LayoutParagraphsBuilder extends RenderElement implements ContainerFactoryP protected $layoutParagraphsLayout; /** - * {@inheritDoc} + * {@inheritdoc} */ public function __construct( array $configuration, @@ -90,7 +90,8 @@ class LayoutParagraphsBuilder extends RenderElement implements ContainerFactoryP EntityTypeManagerInterface $entity_type_manager, LayoutPluginManagerInterface $layout_plugin_manager, RendererInterface $renderer, - EntityTypeBundleInfoInterface $entity_type_bundle_info) { + EntityTypeBundleInfoInterface $entity_type_bundle_info, + ) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->tempstore = $tempstore_repository; @@ -101,7 +102,7 @@ class LayoutParagraphsBuilder extends RenderElement implements ContainerFactoryP } /** - * {@inheritDoc} + * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { return new static( @@ -467,7 +468,7 @@ class LayoutParagraphsBuilder extends RenderElement implements ContainerFactoryP /** * Builds a translation warning message. * - * @return \Drupal\Core\StringTranslation\TranslatableMarkup + * @return \Drupal\Core\StringTranslation\TranslatableMarkup|null * The translation warning. */ protected function translationWarning() { diff --git a/src/Element/LayoutSelect.php b/src/Element/LayoutSelect.php index d0e03208..e5ed1382 100644 --- a/src/Element/LayoutSelect.php +++ b/src/Element/LayoutSelect.php @@ -54,7 +54,8 @@ class LayoutSelect extends Radios { public static function processLayoutSelect( &$element, FormStateInterface $form_state, - &$complete_form) { + &$complete_form, + ) { foreach (Element::children($element) as $key) { $layout_name = $key; $definition = \Drupal::service('plugin.manager.core.layout')->getDefinition($layout_name); diff --git a/src/Event/LayoutParagraphsAllowedTypesEvent.php b/src/Event/LayoutParagraphsAllowedTypesEvent.php index 75f65003..dfe6d62d 100644 --- a/src/Event/LayoutParagraphsAllowedTypesEvent.php +++ b/src/Event/LayoutParagraphsAllowedTypesEvent.php @@ -47,23 +47,21 @@ class LayoutParagraphsAllowedTypesEvent extends Event { protected $region; /** - * The context a new compoment is being added into. + * The context a new component is being added into. * * @var array */ protected $context; /** - * Class cosntructor. + * Class constructor. * * @param array $types * An array of paragraph types. * @param \Drupal\layout_paragraphs\LayoutParagraphsLayout $layout * The layout object. - * @param string $parent_uuid - * The parent uuid. - * @param string $region - * The region. + * @param array $context + * The context. */ public function __construct(array $types, LayoutParagraphsLayout $layout, $context) { $this->types = $types; diff --git a/src/Event/LayoutParagraphsComponentDefaultsEvent.php b/src/Event/LayoutParagraphsComponentDefaultsEvent.php index 200d0d0c..8f87aaf3 100644 --- a/src/Event/LayoutParagraphsComponentDefaultsEvent.php +++ b/src/Event/LayoutParagraphsComponentDefaultsEvent.php @@ -22,7 +22,8 @@ class LayoutParagraphsComponentDefaultsEvent extends Event { */ public function __construct( protected string $paragraphTypeId, - protected array $defaultValues) { + protected array $defaultValues, + ) { } /** diff --git a/src/Event/LayoutParagraphsUpdateLayoutEvent.php b/src/Event/LayoutParagraphsUpdateLayoutEvent.php index a823474c..d073881c 100644 --- a/src/Event/LayoutParagraphsUpdateLayoutEvent.php +++ b/src/Event/LayoutParagraphsUpdateLayoutEvent.php @@ -17,7 +17,7 @@ use Drupal\layout_paragraphs\LayoutParagraphsLayout; * avoid refreshing the entire builder whenever possible (for example, by * appending the HTML for a new paragraph in the correct position in the ui). * There are times when simply appending or replacing the new or altered - * paragraph is insufficient for correclty rendering the layout, and the entire + * paragraph is insufficient for correctly rendering the layout, and the entire * builder interface should be refreshed by setting $needsRefresh to true in * this event. */ @@ -47,7 +47,7 @@ class LayoutParagraphsUpdateLayoutEvent extends Event { public $needsRefresh = FALSE; /** - * Class cosntructor. + * Class constructor. * * @param \Drupal\layout_paragraphs\LayoutParagraphsLayout $original_layout * The layout object. diff --git a/src/EventSubscriber/LayoutParagraphsAllowedTypesSubscriber.php b/src/EventSubscriber/LayoutParagraphsAllowedTypesSubscriber.php index 504bfd2f..262c38b8 100644 --- a/src/EventSubscriber/LayoutParagraphsAllowedTypesSubscriber.php +++ b/src/EventSubscriber/LayoutParagraphsAllowedTypesSubscriber.php @@ -6,12 +6,12 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Drupal\layout_paragraphs\Event\LayoutParagraphsAllowedTypesEvent; /** - * Class definition for LayoutParagraphsAllowedTypesSubcriber. + * Class definition for LayoutParagraphsAllowedTypesSubscriber. */ class LayoutParagraphsAllowedTypesSubscriber implements EventSubscriberInterface { /** - * {@inheritDoc} + * {@inheritdoc} */ public static function getSubscribedEvents(): array { return [ diff --git a/src/EventSubscriber/LayoutParagraphsUpdateLayoutSubscriber.php b/src/EventSubscriber/LayoutParagraphsUpdateLayoutSubscriber.php index 89ac79d7..1140618a 100644 --- a/src/EventSubscriber/LayoutParagraphsUpdateLayoutSubscriber.php +++ b/src/EventSubscriber/LayoutParagraphsUpdateLayoutSubscriber.php @@ -11,7 +11,7 @@ use Drupal\layout_paragraphs\Event\LayoutParagraphsUpdateLayoutEvent; class LayoutParagraphsUpdateLayoutSubscriber implements EventSubscriberInterface { /** - * {@inheritDoc} + * {@inheritdoc} */ public static function getSubscribedEvents(): array { return [ diff --git a/src/Form/ComponentFormBase.php b/src/Form/ComponentFormBase.php index f8e60797..0dbb7b2a 100644 --- a/src/Form/ComponentFormBase.php +++ b/src/Form/ComponentFormBase.php @@ -91,7 +91,7 @@ abstract class ComponentFormBase extends FormBase implements ComponentFormInterf protected $formMode = 'default'; /** - * {@inheritDoc} + * {@inheritdoc} */ public function __construct( LayoutParagraphsLayoutTempstoreRepository $tempstore, @@ -99,8 +99,8 @@ abstract class ComponentFormBase extends FormBase implements ComponentFormInterf LayoutPluginManagerInterface $layout_plugin_manager, ModuleHandlerInterface $module_handler, EventDispatcherInterface $event_dispatcher, - EntityRepositoryInterface $entity_repository - ) { + EntityRepositoryInterface $entity_repository, + ) { $this->tempstore = $tempstore; $this->entityTypeManager = $entity_type_manager; $this->layoutPluginManager = $layout_plugin_manager; @@ -110,7 +110,7 @@ abstract class ComponentFormBase extends FormBase implements ComponentFormInterf } /** - * {@inheritDoc} + * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( @@ -124,28 +124,28 @@ abstract class ComponentFormBase extends FormBase implements ComponentFormInterf } /** - * {@inheritDoc} + * {@inheritdoc} */ public function getFormId() { return 'layout_paragraphs_component_form'; } /** - * {@inheritDoc} + * {@inheritdoc} */ public function getParagraph() { return $this->paragraph; } /** - * {@inheritDoc} + * {@inheritdoc} */ public function setParagraph(ParagraphInterface $paragraph) { $this->paragraph = $paragraph; } /** - * {@inheritDoc} + * {@inheritdoc} */ public function getLayoutParagraphsLayout() { return $this->layoutParagraphsLayout; @@ -158,11 +158,14 @@ abstract class ComponentFormBase extends FormBase implements ComponentFormInterf * The form array. * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state object. + * @param string $form_display_mode + * The form display mode. */ protected function buildComponentForm( array $form, FormStateInterface $form_state, - string $form_display_mode = 'default') { + string $form_display_mode = 'default', + ) { $this->initFormLangcodes($form_state); $display = EntityFormDisplay::collectRenderDisplay($this->paragraph, $form_display_mode); @@ -310,7 +313,7 @@ abstract class ComponentFormBase extends FormBase implements ComponentFormInterf } /** - * {@inheritDoc} + * {@inheritdoc} */ abstract public function successfulAjaxSubmit(array $form, FormStateInterface $form_state); @@ -373,7 +376,10 @@ abstract class ComponentFormBase extends FormBase implements ComponentFormInterf * The form element. */ public function afterBuild(array $element, FormStateInterface $form_state) { - $parents = array_merge($element['#parents'], [$this->getFormId(), $element['#paragraph']->bundle()]); + $parents = array_merge($element['#parents'], [ + $this->getFormId(), + $element['#paragraph']->bundle(), + ]); $unprocessed_id = 'edit-' . implode('-', $parents); $element['#attributes']['data-drupal-selector'] = Html::getId($unprocessed_id); $element['#dialog_id'] = $unprocessed_id . '-dialog'; @@ -616,14 +622,14 @@ abstract class ComponentFormBase extends FormBase implements ComponentFormInterf } /** - * {@inheritDoc} + * {@inheritdoc} */ public function getFormMode() { return $this->formMode; } /** - * {@inheritDoc} + * {@inheritdoc} */ public function setFormMode($view_mode) { $this->formMode = $view_mode; diff --git a/src/Form/DeleteComponentForm.php b/src/Form/DeleteComponentForm.php index 2b7cafd8..c3ed13de 100644 --- a/src/Form/DeleteComponentForm.php +++ b/src/Form/DeleteComponentForm.php @@ -35,14 +35,14 @@ class DeleteComponentForm extends FormBase { protected $componentUuid; /** - * {@inheritDoc} + * {@inheritdoc} */ protected function __construct($tempstore) { $this->tempstore = $tempstore; } /** - * {@inheritDoc} + * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( @@ -51,16 +51,16 @@ class DeleteComponentForm extends FormBase { } /** - * {@inheritDoc} + * {@inheritdoc} */ public function getFormId() { return 'layout_paragraphs_delete_component_form'; } /** - * {@inheritDoc} + * {@inheritdoc} */ - public function buildForm(array $form, FormStateInterface $form_state, LayoutParagraphsLayout $layout_paragraphs_layout = NULL, string $component_uuid = NULL) { + public function buildForm(array $form, FormStateInterface $form_state, ?LayoutParagraphsLayout $layout_paragraphs_layout = NULL, ?string $component_uuid = NULL) { $this->setLayoutParagraphsLayout($layout_paragraphs_layout); $this->componentUuid = $component_uuid; $component = $this->layoutParagraphsLayout->getComponentByUuid($this->componentUuid); @@ -100,7 +100,7 @@ class DeleteComponentForm extends FormBase { } /** - * {@inheritDoc} + * {@inheritdoc} * * Deletes the component and saves the layout. */ diff --git a/src/Form/EditComponentForm.php b/src/Form/EditComponentForm.php index 32386464..19fbc437 100644 --- a/src/Form/EditComponentForm.php +++ b/src/Form/EditComponentForm.php @@ -16,13 +16,14 @@ use Drupal\layout_paragraphs\Ajax\LayoutParagraphsEventCommand; class EditComponentForm extends ComponentFormBase { /** - * {@inheritDoc} + * {@inheritdoc} */ public function buildForm( array $form, FormStateInterface $form_state, - LayoutParagraphsLayout $layout_paragraphs_layout = NULL, - string $component_uuid = NULL) { + ?LayoutParagraphsLayout $layout_paragraphs_layout = NULL, + ?string $component_uuid = NULL, + ) { $this->setLayoutParagraphsLayout($layout_paragraphs_layout); $this->paragraph = $this->layoutParagraphsLayout @@ -58,7 +59,7 @@ class EditComponentForm extends ComponentFormBase { } /** - * {@inheritDoc} + * {@inheritdoc} */ public function successfulAjaxSubmit(array $form, FormStateInterface $form_state) { @@ -121,7 +122,7 @@ class EditComponentForm extends ComponentFormBase { } /** - * {@inheritDoc} + * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { parent::submitForm($form, $form_state); diff --git a/src/Form/InsertComponentForm.php b/src/Form/InsertComponentForm.php index 5a2372db..c844c895 100644 --- a/src/Form/InsertComponentForm.php +++ b/src/Form/InsertComponentForm.php @@ -73,7 +73,7 @@ class InsertComponentForm extends ComponentFormBase { protected $siblingUuid; /** - * {@inheritDoc} + * {@inheritdoc} * * @param array $form * The form array. @@ -97,14 +97,14 @@ class InsertComponentForm extends ComponentFormBase { public function buildForm( array $form, FormStateInterface $form_state, - LayoutParagraphsLayout $layout_paragraphs_layout = NULL, - ParagraphsTypeInterface $paragraph_type = NULL, - string $parent_uuid = NULL, - string $region = NULL, - string $sibling_uuid = NULL, - string $placement = NULL, - array $paragraph_defaults = [] - ) { + ?LayoutParagraphsLayout $layout_paragraphs_layout = NULL, + ?ParagraphsTypeInterface $paragraph_type = NULL, + ?string $parent_uuid = NULL, + ?string $region = NULL, + ?string $sibling_uuid = NULL, + ?string $placement = NULL, + array $paragraph_defaults = [], + ) { if (!empty($paragraph_defaults)) { $this->paragraphDefaults = $paragraph_defaults; @@ -144,7 +144,7 @@ class InsertComponentForm extends ComponentFormBase { } /** - * {@inheritDoc} + * {@inheritdoc} */ public function successfulAjaxSubmit(array $form, FormStateInterface $form_state) { @@ -180,7 +180,7 @@ class InsertComponentForm extends ComponentFormBase { } /** - * {@inheritDoc} + * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { parent::submitForm($form, $form_state); diff --git a/src/Form/LayoutParagraphsBuilderForm.php b/src/Form/LayoutParagraphsBuilderForm.php index 67113547..dd47baa2 100644 --- a/src/Form/LayoutParagraphsBuilderForm.php +++ b/src/Form/LayoutParagraphsBuilderForm.php @@ -50,14 +50,14 @@ class LayoutParagraphsBuilderForm extends FormBase { protected $entityTypeManager; /** - * {@inheritDoc} + * {@inheritdoc} */ public function getFormId() { return 'layout_paragraphs_builder_form'; } /** - * {@inheritDoc} + * {@inheritdoc} */ public function __construct(LayoutParagraphsLayoutTempstoreRepository $tempstore, EntityTypeManagerInterface $entity_type_manager) { $this->tempstore = $tempstore; @@ -65,7 +65,7 @@ class LayoutParagraphsBuilderForm extends FormBase { } /** - * {@inheritDoc} + * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( @@ -91,9 +91,10 @@ class LayoutParagraphsBuilderForm extends FormBase { public function buildForm( array $form, FormStateInterface $form_state, - ContentEntityInterface $entity = NULL, - string $field_name = NULL, - string $view_mode = NULL) { + ?ContentEntityInterface $entity = NULL, + ?string $field_name = NULL, + ?string $view_mode = NULL, + ) { $parents = array_merge($form['#parents'] ?? [], ['layout_paragraphs_storage_key']); $input = $form_state->getUserInput(); @@ -203,7 +204,7 @@ class LayoutParagraphsBuilderForm extends FormBase { } /** - * {@inheritDoc} + * {@inheritdoc} * * Saves the layout to its parent entity. * @@ -222,8 +223,10 @@ class LayoutParagraphsBuilderForm extends FormBase { $field_name = $this->layoutParagraphsLayout->getFieldName(); if ($entity instanceof RevisionableInterface) { $revision_id = $entity->getRevisionId(); + /** @var \Drupal\Core\Entity\RevisionableStorageInterface $storage */ + $storage = $this->entityTypeManager->getStorage($entity_type); /** @var \Drupal\Core\Entity\RevisionableInterface $entity */ - $entity = $this->entityTypeManager->getStorage($entity_type)->loadRevision($revision_id); + $entity = $storage->loadRevision($revision_id); $entity->setNewRevision(FALSE); } else { diff --git a/src/Form/LayoutParagraphsSectionsSettingsForm.php b/src/Form/LayoutParagraphsSectionsSettingsForm.php index ae7e4f7c..dbb9edc5 100644 --- a/src/Form/LayoutParagraphsSectionsSettingsForm.php +++ b/src/Form/LayoutParagraphsSectionsSettingsForm.php @@ -56,7 +56,7 @@ class LayoutParagraphsSectionsSettingsForm extends ConfigFormBase { TypedConfigManagerInterface $typedConfigManager, EntityTypeBundleInfoInterface $entity_type_bundle_info, EntityTypeManagerInterface $entity_type_manager, - LayoutPluginManagerInterface $layout_plugin_manager + LayoutPluginManagerInterface $layout_plugin_manager, ) { parent::__construct($config_factory, $typedConfigManager); $this->typedConfigManager = $typedConfigManager; diff --git a/src/Form/LayoutParagraphsSettingsForm.php b/src/Form/LayoutParagraphsSettingsForm.php index 394b9b15..547e41ee 100644 --- a/src/Form/LayoutParagraphsSettingsForm.php +++ b/src/Form/LayoutParagraphsSettingsForm.php @@ -23,7 +23,7 @@ class LayoutParagraphsSettingsForm extends ConfigFormBase { */ public function __construct( ConfigFactoryInterface $config_factory, - TypedConfigManagerInterface $typedConfigManager + TypedConfigManagerInterface $typedConfigManager, ) { parent::__construct($config_factory, $typedConfigManager); $this->typedConfigManager = $typedConfigManager; diff --git a/src/LayoutParagraphsLayout.php b/src/LayoutParagraphsLayout.php index 7179a60b..fdadf197 100644 --- a/src/LayoutParagraphsLayout.php +++ b/src/LayoutParagraphsLayout.php @@ -2,7 +2,6 @@ namespace Drupal\layout_paragraphs; -use Drupal\Component\Utility\Crypt; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Field\EntityReferenceFieldItemListInterface; use Drupal\Core\DependencyInjection\DependencySerializationTrait; @@ -16,7 +15,7 @@ use Drupal\paragraphs\ParagraphInterface; * Layout Paragraphs Sections and Layout Paragraphs Components * associated with a paragraphs reference field. * This class provides public methods for manipulating a layout - - * i.e. adding, removing, and reording paragraph layout sections + * i.e. adding, removing, and reordering paragraph layout sections * and paragraph layout components. * * See also: @@ -77,7 +76,7 @@ class LayoutParagraphsLayout implements ThirdPartySettingsInterface { */ public function __construct( EntityReferenceFieldItemListInterface $paragraphs_reference_field, - array $settings = [] + array $settings = [], ) { $this->paragraphsReferenceField = $paragraphs_reference_field; $this->settings = $settings; @@ -213,7 +212,7 @@ class LayoutParagraphsLayout implements ThirdPartySettingsInterface { * @param string $uuid * The uuid to search for. * - * @return LayoutParagraphsComponent + * @return LayoutParagraphsComponent|null * The component. */ public function getComponentByUuid($uuid) { @@ -334,6 +333,7 @@ class LayoutParagraphsLayout implements ThirdPartySettingsInterface { * @return $this */ public function reorderComponents(array $ordered_items) { + $reordered_items = []; foreach ($ordered_items as $ordered_item) { if ($component = $this->getComponentByUuid($ordered_item['uuid'])) { $component->setSettings([ @@ -363,7 +363,7 @@ class LayoutParagraphsLayout implements ThirdPartySettingsInterface { * @return \Drupal\layout_paragraphs\LayoutParagraphsComponent * The duplicated component. */ - public function duplicateComponent(string $source_uuid, string $target_section_uuid = NULL) { + public function duplicateComponent(string $source_uuid, ?string $target_section_uuid = NULL) { $source_component = $this->getComponentByUuid($source_uuid); $cloned_paragraph = $source_component->getEntity()->createDuplicate(); if ($target_section_uuid) { @@ -467,7 +467,8 @@ class LayoutParagraphsLayout implements ThirdPartySettingsInterface { protected function insertSiblingComponent( string $sibling_uuid, ParagraphInterface $new_paragraph, - int $delta_offset = 0) { + int $delta_offset = 0, + ) { // Create a layout component for the new paragraph. $new_component = $this->getComponent($new_paragraph); @@ -542,7 +543,7 @@ class LayoutParagraphsLayout implements ThirdPartySettingsInterface { } /** - * Searchs for a component by its uuid and returns its delta. + * Searches for a component by its uuid and returns its delta. * * @param string $uuid * The uuid to search for. diff --git a/src/LayoutParagraphsLayoutTempstoreRepository.php b/src/LayoutParagraphsLayoutTempstoreRepository.php index bf8efca3..22f0dfbe 100644 --- a/src/LayoutParagraphsLayoutTempstoreRepository.php +++ b/src/LayoutParagraphsLayoutTempstoreRepository.php @@ -46,12 +46,12 @@ class LayoutParagraphsLayoutTempstoreRepository { } /** - * Get a layout paragraphs layout frome the tempstore using its storage key. + * Get a layout paragraphs layout from the tempstore using its storage key. * * @param string $key * The storage key. * - * @return \Drupal\layout_paragraphs\LayoutParagraphsLayout + * @return \Drupal\layout_paragraphs\LayoutParagraphsLayout|null * The layout. */ public function getWithStorageKey(string $key) { diff --git a/src/LayoutParagraphsSection.php b/src/LayoutParagraphsSection.php index 06960c3f..8aed58fb 100644 --- a/src/LayoutParagraphsSection.php +++ b/src/LayoutParagraphsSection.php @@ -33,7 +33,7 @@ class LayoutParagraphsSection extends LayoutParagraphsComponent { */ public function __construct( ParagraphInterface $paragraph, - array $components = [] + array $components = [], ) { parent::__construct($paragraph); $this->components = $components; @@ -45,7 +45,7 @@ class LayoutParagraphsSection extends LayoutParagraphsComponent { * @param \Drupal\paragraphs\ParagraphInterface $paragraph * The paragraph entity. * - * @return LayoutParagraphsComponent|LayoutParagraphsSection + * @return LayoutParagraphsComponent|LayoutParagraphsSection|null * The component. */ public function getComponent(ParagraphInterface $paragraph) { @@ -62,7 +62,7 @@ class LayoutParagraphsSection extends LayoutParagraphsComponent { * @param string $uuid * The uuid to search for. * - * @return LayoutParagraphsComponent + * @return LayoutParagraphsComponent|null * The component. */ public function getComponentByUuid($uuid) { @@ -120,7 +120,7 @@ class LayoutParagraphsSection extends LayoutParagraphsComponent { } /** - * {@inheritDoc} + * {@inheritdoc} */ public function defaultSettings() { return [ diff --git a/src/Plugin/Field/FieldFormatter/LayoutParagraphsBuilderFormatter.php b/src/Plugin/Field/FieldFormatter/LayoutParagraphsBuilderFormatter.php index b2fca452..87973ee9 100644 --- a/src/Plugin/Field/FieldFormatter/LayoutParagraphsBuilderFormatter.php +++ b/src/Plugin/Field/FieldFormatter/LayoutParagraphsBuilderFormatter.php @@ -10,6 +10,8 @@ use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Session\AccountProxyInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Routing\Access\AccessInterface; +use Drupal\Core\Entity\EntityRepositoryInterface; +use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\layout_paragraphs\LayoutParagraphsLayout; use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -54,13 +56,21 @@ class LayoutParagraphsBuilderFormatter extends LayoutParagraphsFormatter impleme protected $account; /** - * {@inheritDoc} + * The field widget plugin manager. + * + * @var \Drupal\Core\Plugin\PluginManagerInterface + */ + protected $fieldWidgetPluginManager; + + /** + * {@inheritdoc} */ - public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, LoggerChannelFactoryInterface $logger_factory, EntityDisplayRepositoryInterface $entity_display_repository, LayoutParagraphsLayoutTempstoreRepository $tempstore, AccessInterface $layout_paragraphs_builder_access, AccountProxyInterface $current_user) { - parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings, $logger_factory, $entity_display_repository); + public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, LoggerChannelFactoryInterface $logger_factory, EntityDisplayRepositoryInterface $entity_display_repository, EntityRepositoryInterface $entity_repository, LayoutParagraphsLayoutTempstoreRepository $tempstore, AccessInterface $layout_paragraphs_builder_access, AccountProxyInterface $current_user, PluginManagerInterface $field_widget_plugin_manager) { + parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings, $logger_factory, $entity_display_repository, $entity_repository); $this->tempstore = $tempstore; $this->layoutParagraphsBuilderAccess = $layout_paragraphs_builder_access; $this->account = $current_user->getAccount(); + $this->fieldWidgetPluginManager = $field_widget_plugin_manager; } /** @@ -77,14 +87,16 @@ class LayoutParagraphsBuilderFormatter extends LayoutParagraphsFormatter impleme $configuration['third_party_settings'], $container->get('logger.factory'), $container->get('entity_display.repository'), + $container->get('entity.repository'), $container->get('layout_paragraphs.tempstore_repository'), $container->get('layout_paragraphs.builder_access'), - $container->get('current_user') - ); + $container->get('current_user'), + $container->get('plugin.manager.field.widget') + ); } /** - * {@inheritDoc} + * {@inheritdoc} */ public function view(FieldItemListInterface $items, $langcode = NULL) { @@ -93,7 +105,7 @@ class LayoutParagraphsBuilderFormatter extends LayoutParagraphsFormatter impleme '#root_components' => parent::view($items, $langcode), ]; $entity = $items->getEntity(); - /** @var \Drupal\Core\Entity\EntityDefintion $definition */ + /** @var \Drupal\Core\Entity\EntityDefinition $definition */ $definition = $items->getFieldDefinition(); $layout = new LayoutParagraphsLayout($items, $this->getSettings() + ['reference_field_view_mode' => $this->viewMode]); @@ -182,8 +194,7 @@ class LayoutParagraphsBuilderFormatter extends LayoutParagraphsFormatter impleme * The widget instance. */ protected function widgetInstance() { - $plugin_manager = \Drupal::service('plugin.manager.field.widget'); - $widget = $plugin_manager->getInstance([ + $widget = $this->fieldWidgetPluginManager->getInstance([ 'field_definition' => $this->fieldDefinition, 'form_mode' => 'layout_paragraphs_editor', 'prepare' => TRUE, diff --git a/src/Plugin/Field/FieldFormatter/LayoutParagraphsFormatter.php b/src/Plugin/Field/FieldFormatter/LayoutParagraphsFormatter.php index d9ae2bc5..15c1119c 100644 --- a/src/Plugin/Field/FieldFormatter/LayoutParagraphsFormatter.php +++ b/src/Plugin/Field/FieldFormatter/LayoutParagraphsFormatter.php @@ -2,12 +2,17 @@ namespace Drupal\layout_paragraphs\Plugin\Field\FieldFormatter; -use Drupal\entity_reference_revisions\Plugin\Field\FieldFormatter\EntityReferenceRevisionsEntityFormatter; +use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\TypedData\TranslatableInterface; +use Drupal\Core\Entity\EntityRepositoryInterface; +use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\Core\Field\EntityReferenceFieldItemListInterface; use Drupal\layout_paragraphs\LayoutParagraphsComponent; -use Drupal\Core\TypedData\TranslatableInterface; -use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Entity\EntityDisplayRepositoryInterface; +use Drupal\Core\Field\EntityReferenceFieldItemListInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\entity_reference_revisions\Plugin\Field\FieldFormatter\EntityReferenceRevisionsEntityFormatter; /** * Layout Paragraphs field formatter. @@ -23,6 +28,39 @@ use Drupal\Core\Cache\CacheableMetadata; */ class LayoutParagraphsFormatter extends EntityReferenceRevisionsEntityFormatter implements ContainerFactoryPluginInterface { + /** + * The entity repository. + * + * @var \Drupal\Core\Entity\EntityRepositoryInterface + */ + protected $entityRepository; + + /** + * {@inheritdoc} + */ + public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, LoggerChannelFactoryInterface $logger_factory, EntityDisplayRepositoryInterface $entity_display_repository, EntityRepositoryInterface $entity_repository) { + parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings, $logger_factory, $entity_display_repository); + $this->entityRepository = $entity_repository; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $plugin_id, + $plugin_definition, + $configuration['field_definition'], + $configuration['settings'], + $configuration['label'], + $configuration['view_mode'], + $configuration['third_party_settings'], + $container->get('logger.factory'), + $container->get('entity_display.repository'), + $container->get('entity.repository') + ); + } + /** * Returns the referenced entities for display. * @@ -44,6 +82,7 @@ class LayoutParagraphsFormatter extends EntityReferenceRevisionsEntityFormatter foreach ($items as $delta => $item) { // Ignore items where no entity could be loaded in prepareView(). if (!empty($item->_loaded)) { + /** @var \Drupal\Core\Entity\EntityInterface $entity */ $entity = $item->entity; $access = $this->checkAccess($entity); // Add the access result's cacheability, ::view() needs it. @@ -57,7 +96,7 @@ class LayoutParagraphsFormatter extends EntityReferenceRevisionsEntityFormatter if (LayoutParagraphsComponent::isRootComponent($item->entity)) { // Set the entity in the correct language for display. if ($entity instanceof TranslatableInterface) { - $entity = \Drupal::service('entity.repository')->getTranslationFromContext($entity, $langcode); + $entity = $this->entityRepository->getTranslationFromContext($entity, $langcode); } $entities[$delta] = $entity; } diff --git a/src/Plugin/Field/FieldWidget/LayoutParagraphsWidget.php b/src/Plugin/Field/FieldWidget/LayoutParagraphsWidget.php index 3d6c4769..52b04f2b 100644 --- a/src/Plugin/Field/FieldWidget/LayoutParagraphsWidget.php +++ b/src/Plugin/Field/FieldWidget/LayoutParagraphsWidget.php @@ -119,7 +119,14 @@ class LayoutParagraphsWidget extends WidgetBase implements ContainerFactoryPlugi protected $isTranslating; /** - * {@inheritDoc} + * The optional content translation service. + * + * @var \Drupal\content_translation\ContentTranslationManagerInterface|null + */ + protected $contentTranslationManager; + + /** + * {@inheritdoc} */ public function __construct( $plugin_id, @@ -133,8 +140,9 @@ class LayoutParagraphsWidget extends WidgetBase implements ContainerFactoryPlugi FormBuilderInterface $form_builder, EntityDisplayRepositoryInterface $entity_display_repository, ConfigFactoryInterface $config_factory, - EntityRepositoryInterface $entity_repository - ) { + EntityRepositoryInterface $entity_repository, + $content_translation_manager, + ) { parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings); $this->tempstore = $tempstore; @@ -144,7 +152,7 @@ class LayoutParagraphsWidget extends WidgetBase implements ContainerFactoryPlugi $this->entityDisplayRepository = $entity_display_repository; $this->entityRepository = $entity_repository; $this->config = $config_factory->get('layout_paragraphs.settings'); - + $this->contentTranslationManager = $content_translation_manager; } /** @@ -163,7 +171,8 @@ class LayoutParagraphsWidget extends WidgetBase implements ContainerFactoryPlugi $container->get('form_builder'), $container->get('entity_display.repository'), $container->get('config.factory'), - $container->get('entity.repository') + $container->get('entity.repository'), + $container->has('content_translation.manager') ? $container->get('content_translation.manager') : NULL ); } @@ -305,11 +314,10 @@ class LayoutParagraphsWidget extends WidgetBase implements ContainerFactoryPlugi // if no paragraph entity field is translatable, // even if the host is. if ($paragraph->hasField('content_translation_source')) { - // Initialise the translation with source language values. + // Initialize the translation with source language values. $paragraph->addTranslation($this->langcode, $paragraph->toArray()); $translation = $paragraph->getTranslation($this->langcode); - $manager = \Drupal::service('content_translation.manager'); - $manager->getTranslationMetadata($translation) + $this->contentTranslationManager->getTranslationMetadata($translation) ->setSource($paragraph->language()->getId()); } } @@ -331,7 +339,7 @@ class LayoutParagraphsWidget extends WidgetBase implements ContainerFactoryPlugi */ public function extractFormValues(FieldItemListInterface $items, array $form, FormStateInterface $form_state) { $field_name = $this->fieldDefinition->getName(); - // Load the correct layout paragraphs layout instnace using the value + // Load the correct layout paragraphs layout instance using the value // passed in the layout_instance_id hidden field. $path = array_merge($form['#parents'], [$field_name]); $layout_paragraphs_storage_key = $form_state->getValue(array_merge($path, ['layout_paragraphs_storage_key'])); @@ -365,13 +373,13 @@ class LayoutParagraphsWidget extends WidgetBase implements ContainerFactoryPlugi public function settingsForm(array $form, FormStateInterface $form_state) { $entity_type_id = $this->getFieldSetting('target_type'); $element = parent::settingsForm($form, $form_state); - $element['view_mode'] = array( + $element['view_mode'] = [ '#type' => 'select', '#title' => $this->t('View mode'), '#default_value' => $this->getSetting('view_mode'), '#options' => $this->entityDisplayRepository->getViewModeOptions($entity_type_id), '#required' => TRUE, - ); + ]; $element['preview_view_mode'] = [ '#type' => 'select', '#title' => $this->t('Preview view mode'), diff --git a/src/Plugin/paragraphs/Behavior/LayoutParagraphsBehavior.php b/src/Plugin/paragraphs/Behavior/LayoutParagraphsBehavior.php index efd0bff5..585928ad 100644 --- a/src/Plugin/paragraphs/Behavior/LayoutParagraphsBehavior.php +++ b/src/Plugin/paragraphs/Behavior/LayoutParagraphsBehavior.php @@ -3,7 +3,6 @@ namespace Drupal\layout_paragraphs\Plugin\paragraphs\Behavior; use Drupal\Component\Utility\Html; -use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Form\SubformState; use Drupal\Core\Layout\LayoutInterface; use Drupal\Core\Form\FormStateInterface; @@ -13,7 +12,10 @@ use Drupal\Core\Plugin\PluginFormInterface; use Drupal\paragraphs\ParagraphsBehaviorBase; use Drupal\Core\Plugin\PluginWithFormsInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Plugin\PluginFormFactoryInterface; +use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Layout\LayoutPluginManagerInterface; +use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\layout_paragraphs\LayoutParagraphsSection; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\layout_paragraphs\LayoutParagraphsRendererService; @@ -60,6 +62,20 @@ class LayoutParagraphsBehavior extends ParagraphsBehaviorBase { */ protected $paragraph; + /** + * The plugin form factory. + * + * @var \Drupal\Core\Plugin\PluginFormFactoryInterface + */ + protected $pluginFormFactory; + + /** + * The logger factory. + * + * @var \Drupal\Core\Logger\LoggerChannelFactoryInterface + */ + protected $loggerFactory; + /** * ParagraphsLayoutPlugin constructor. * @@ -77,19 +93,28 @@ class LayoutParagraphsBehavior extends ParagraphsBehaviorBase { * The grid discovery service. * @param \Drupal\layout_paragraphs\LayoutParagraphsRendererService $layout_paragraphs_renderer_service * The layout paragraphs service. + * @param \Drupal\Core\Plugin\PluginFormFactoryInterface $plugin_form_factory + * The plugin form factory. + * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger_factory + * The logger factory. */ public function __construct( - array $configuration, - $plugin_id, - $plugin_definition, - EntityFieldManagerInterface $entity_field_manager, - LayoutPluginManagerInterface $layout_plugin_manager, - EntityTypeManagerInterface $entity_type_manager, - LayoutParagraphsRendererService $layout_paragraphs_renderer_service) { + array $configuration, + $plugin_id, + $plugin_definition, + EntityFieldManagerInterface $entity_field_manager, + LayoutPluginManagerInterface $layout_plugin_manager, + EntityTypeManagerInterface $entity_type_manager, + LayoutParagraphsRendererService $layout_paragraphs_renderer_service, + PluginFormFactoryInterface $plugin_form_factory, + LoggerChannelFactoryInterface $logger_factory, + ) { parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_field_manager); $this->layoutPluginManager = $layout_plugin_manager; $this->entityTypeManager = $entity_type_manager; $this->layoutParagraphsRendererService = $layout_paragraphs_renderer_service; + $this->pluginFormFactory = $plugin_form_factory; + $this->loggerFactory = $logger_factory; } /** @@ -103,17 +128,19 @@ class LayoutParagraphsBehavior extends ParagraphsBehaviorBase { $container->get('entity_field.manager'), $container->get('plugin.manager.core.layout'), $container->get('entity_type.manager'), - $container->get('layout_paragraphs.renderer') + $container->get('layout_paragraphs.renderer'), + $container->get('plugin_form.factory'), + $container->get('logger.factory') ); } /** - * {@inheritDoc} + * {@inheritdoc} */ public function buildBehaviorForm( ParagraphInterface $paragraph, array &$form, - FormStateInterface $form_state + FormStateInterface $form_state, ) { $layout_paragraphs_section = new LayoutParagraphsSection($paragraph); @@ -289,7 +316,7 @@ class LayoutParagraphsBehavior extends ParagraphsBehaviorBase { return $this->pluginFormFactory->createInstance($layout, 'configure'); } catch (\Exception $e) { - $this->loggerFactory->get('layout_paragraphs')->error('Erl, Layout Configuration', $e); + $this->loggerFactory->get('layout_paragraphs')->error('Erl, Layout Configuration', [$e]); } } diff --git a/src/Utility/Dialog.php b/src/Utility/Dialog.php index a65a70a7..2b005668 100644 --- a/src/Utility/Dialog.php +++ b/src/Utility/Dialog.php @@ -38,7 +38,7 @@ class Dialog { } /** - * Returns a CloseDialogComand with the correct selector. + * Returns a CloseDialogCommand with the correct selector. * * @param \Drupal\layout_paragraphs\LayoutParagraphsLayout $layout * The layout paragraphs layout object. @@ -59,7 +59,7 @@ class Dialog { * @return array * The modal settings. */ - public static function dialogSettings(LayoutParagraphsLayout $layout = NULL) { + public static function dialogSettings(?LayoutParagraphsLayout $layout = NULL) { $config = \Drupal::config('layout_paragraphs.modal_settings'); $modal_settings = [ diff --git a/tests/modules/layout_paragraphs_complex_permissions_test/layout_paragraphs_complex_permissions_test.info.yml b/tests/modules/layout_paragraphs_complex_permissions_test/layout_paragraphs_complex_permissions_test.info.yml index a8d29a1f..ea36f05d 100644 --- a/tests/modules/layout_paragraphs_complex_permissions_test/layout_paragraphs_complex_permissions_test.info.yml +++ b/tests/modules/layout_paragraphs_complex_permissions_test/layout_paragraphs_complex_permissions_test.info.yml @@ -4,5 +4,5 @@ core_version_requirement: ^9.2 || ^10 || ^11 type: module package: Layout Paragraphs dependencies: - - layout_paragraphs - - layout_paragraphs_permissions + - layout_paragraphs:layout_paragraphs + - layout_paragraphs:layout_paragraphs_permissions diff --git a/tests/modules/layout_paragraphs_complex_permissions_test/src/Access/ReorderAccessByContentType.php b/tests/modules/layout_paragraphs_complex_permissions_test/src/Access/ReorderAccessByContentType.php index 5349c575..87b4b1a4 100644 --- a/tests/modules/layout_paragraphs_complex_permissions_test/src/Access/ReorderAccessByContentType.php +++ b/tests/modules/layout_paragraphs_complex_permissions_test/src/Access/ReorderAccessByContentType.php @@ -14,14 +14,14 @@ use Drupal\layout_paragraphs\Access\LayoutParagraphsBuilderAccess; class ReorderAccessByContentType extends LayoutParagraphsBuilderAccess { /** - * {@inheritDoc} + * {@inheritdoc} */ public function access( AccountInterface $account, LayoutParagraphsLayout $layout_paragraphs_layout, - string $operation = NULL, - string $component_uuid = NULL, - ParagraphsTypeInterface $paragraph_type = NULL + ?string $operation = NULL, + ?string $component_uuid = NULL, + ?ParagraphsTypeInterface $paragraph_type = NULL, ) { $access = parent::access($account, $layout_paragraphs_layout, $operation, $component_uuid, $paragraph_type); if ($operation == 'reorder') { diff --git a/tests/modules/layout_paragraphs_correct_region_test/layout_paragraphs_correct_region_test.info.yml b/tests/modules/layout_paragraphs_correct_region_test/layout_paragraphs_correct_region_test.info.yml index 0b7aa74a..48ef1820 100644 --- a/tests/modules/layout_paragraphs_correct_region_test/layout_paragraphs_correct_region_test.info.yml +++ b/tests/modules/layout_paragraphs_correct_region_test/layout_paragraphs_correct_region_test.info.yml @@ -4,4 +4,4 @@ core_version_requirement: ^9.2 || ^10 || ^11 type: module package: Layout Paragraphs dependencies: - - layout_paragraphs + - layout_paragraphs:layout_paragraphs diff --git a/tests/modules/layout_paragraphs_correct_region_test/src/EventSubscriber/LayoutParagraphsRefreshLayoutSubscriber.php b/tests/modules/layout_paragraphs_correct_region_test/src/EventSubscriber/LayoutParagraphsRefreshLayoutSubscriber.php index 90eb51e4..92e0c9e1 100644 --- a/tests/modules/layout_paragraphs_correct_region_test/src/EventSubscriber/LayoutParagraphsRefreshLayoutSubscriber.php +++ b/tests/modules/layout_paragraphs_correct_region_test/src/EventSubscriber/LayoutParagraphsRefreshLayoutSubscriber.php @@ -11,7 +11,7 @@ use Drupal\layout_paragraphs\Event\LayoutParagraphsUpdateLayoutEvent; class LayoutParagraphsRefreshLayoutSubscriber implements EventSubscriberInterface { /** - * {@inheritDoc} + * {@inheritdoc} */ public static function getSubscribedEvents(): array { return [ diff --git a/tests/modules/layout_paragraphs_custom_host_entity_test/layout_paragraphs_custom_host_entity_test.info.yml b/tests/modules/layout_paragraphs_custom_host_entity_test/layout_paragraphs_custom_host_entity_test.info.yml index 68dc57bf..0d7c8e71 100644 --- a/tests/modules/layout_paragraphs_custom_host_entity_test/layout_paragraphs_custom_host_entity_test.info.yml +++ b/tests/modules/layout_paragraphs_custom_host_entity_test/layout_paragraphs_custom_host_entity_test.info.yml @@ -4,6 +4,6 @@ description: 'Provides a lp host entity entity.' package: Layout Paragraphs Tests core_version_requirement: ^9.2 || ^10 || ^11 dependencies: - - layout_paragraphs + - layout_paragraphs:layout_paragraphs - drupal:text configure: entity.lp_host_entity.settings diff --git a/tests/modules/layout_paragraphs_custom_host_entity_test/src/Entity/LpHostEntity.php b/tests/modules/layout_paragraphs_custom_host_entity_test/src/Entity/LpHostEntity.php index 2d3ae8c2..322a1034 100644 --- a/tests/modules/layout_paragraphs_custom_host_entity_test/src/Entity/LpHostEntity.php +++ b/tests/modules/layout_paragraphs_custom_host_entity_test/src/Entity/LpHostEntity.php @@ -54,8 +54,7 @@ class LpHostEntity extends ContentEntityBase implements LpHostEntityInterface { /** * {@inheritdoc} * - * When a new lp host entity entity is created, set the uid entity reference to - * the current user as the creator of the entity. + * Set the uid entity reference to the current user. */ public static function preCreate(EntityStorageInterface $storage_controller, array &$values) { parent::preCreate($storage_controller, $values); diff --git a/tests/modules/layout_paragraphs_custom_host_entity_test/src/Form/LpHostEntityForm.php b/tests/modules/layout_paragraphs_custom_host_entity_test/src/Form/LpHostEntityForm.php index 509e33d7..f13ab625 100644 --- a/tests/modules/layout_paragraphs_custom_host_entity_test/src/Form/LpHostEntityForm.php +++ b/tests/modules/layout_paragraphs_custom_host_entity_test/src/Form/LpHostEntityForm.php @@ -2,14 +2,46 @@ namespace Drupal\layout_paragraphs_custom_host_entity_test\Form; -use Drupal\Core\Entity\ContentEntityForm; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Entity\ContentEntityForm; +use Drupal\Core\Render\RendererInterface; +use Drupal\Component\Datetime\TimeInterface; +use Drupal\Core\Entity\EntityRepositoryInterface; +use Drupal\Core\Entity\EntityTypeBundleInfoInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Form controller for the lp host entity entity edit forms. */ class LpHostEntityForm extends ContentEntityForm { + /** + * The renderer service. + * + * @var \Drupal\Core\Renderer\RendererInterface + */ + protected $renderer; + + /** + * {@inheritdoc} + */ + public function __construct(EntityRepositoryInterface $entity_repository, EntityTypeBundleInfoInterface $entity_type_bundle_info, TimeInterface $time, RendererInterface $renderer) { + parent::__construct($entity_repository, $entity_type_bundle_info, $time); + $this->renderer = $renderer; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('entity.repository'), + $container->get('entity_type.bundle.info'), + $container->get('datetime.time'), + $container->get('renderer') + ); + } + /** * {@inheritdoc} */ @@ -20,7 +52,7 @@ class LpHostEntityForm extends ContentEntityForm { $link = $entity->toLink($this->t('View'))->toRenderable(); $message_arguments = ['%label' => $this->entity->label()]; - $logger_arguments = $message_arguments + ['link' => \Drupal::service('renderer')->render($link)]; + $logger_arguments = $message_arguments + ['link' => $this->renderer->render($link)]; if ($result == SAVED_NEW) { $this->messenger()->addStatus($this->t('New lp host entity %label has been created.', $message_arguments)); @@ -32,6 +64,7 @@ class LpHostEntityForm extends ContentEntityForm { } $form_state->setRedirect('entity.lp_host_entity.canonical', ['lp_host_entity' => $entity->id()]); + return $result; } } diff --git a/tests/modules/layout_paragraphs_empty_component_list_test/layout_paragraphs_empty_component_list_test.info.yml b/tests/modules/layout_paragraphs_empty_component_list_test/layout_paragraphs_empty_component_list_test.info.yml index 44bd55ac..9d313956 100644 --- a/tests/modules/layout_paragraphs_empty_component_list_test/layout_paragraphs_empty_component_list_test.info.yml +++ b/tests/modules/layout_paragraphs_empty_component_list_test/layout_paragraphs_empty_component_list_test.info.yml @@ -4,4 +4,4 @@ core_version_requirement: ^9.2 || ^10 || ^11 type: module package: Layout Paragraphs dependencies: - - layout_paragraphs + - layout_paragraphs:layout_paragraphs diff --git a/tests/modules/layout_paragraphs_empty_component_list_test/src/EventSubscriber/LayoutParagraphsAllowedTypesSubscriber.php b/tests/modules/layout_paragraphs_empty_component_list_test/src/EventSubscriber/LayoutParagraphsAllowedTypesSubscriber.php index cf2bf761..ed1090ed 100644 --- a/tests/modules/layout_paragraphs_empty_component_list_test/src/EventSubscriber/LayoutParagraphsAllowedTypesSubscriber.php +++ b/tests/modules/layout_paragraphs_empty_component_list_test/src/EventSubscriber/LayoutParagraphsAllowedTypesSubscriber.php @@ -7,7 +7,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Drupal\layout_paragraphs\Event\LayoutParagraphsAllowedTypesEvent; /** - * Class definition for LayoutParagraphsAllowedTypesSubcriber. + * Class definition for LayoutParagraphsAllowedTypesSubscriber. */ class LayoutParagraphsAllowedTypesSubscriber implements EventSubscriberInterface { @@ -31,7 +31,7 @@ class LayoutParagraphsAllowedTypesSubscriber implements EventSubscriberInterface } /** - * {@inheritDoc} + * {@inheritdoc} */ public static function getSubscribedEvents(): array { return [ diff --git a/tests/modules/layout_paragraphs_entity_validator_test/layout_paragraphs_entity_validator_test.module b/tests/modules/layout_paragraphs_entity_validator_test/layout_paragraphs_entity_validator_test.module index 38e80f02..9a3328db 100644 --- a/tests/modules/layout_paragraphs_entity_validator_test/layout_paragraphs_entity_validator_test.module +++ b/tests/modules/layout_paragraphs_entity_validator_test/layout_paragraphs_entity_validator_test.module @@ -1,11 +1,14 @@ <?php +/** + * @file + * Contains layout_paragraphs_entity_validator_test.module. + */ + /** * Implements hook_entity_type_alter(). - * - * @param array $entity_types */ function layout_paragraphs_entity_validator_test_entity_type_alter(array &$entity_types) { - // Add validation constraint to the paragraph entity + // Add validation constraint to the paragraph entity. $entity_types['paragraph']->addConstraint('LayoutParagraphsTestConstraint'); } diff --git a/tests/modules/layout_paragraphs_entity_validator_test/src/Plugin/Validation/Constraint/LayoutParagraphsTestConstraint.php b/tests/modules/layout_paragraphs_entity_validator_test/src/Plugin/Validation/Constraint/LayoutParagraphsTestConstraint.php index f4f09a08..006c12c5 100644 --- a/tests/modules/layout_paragraphs_entity_validator_test/src/Plugin/Validation/Constraint/LayoutParagraphsTestConstraint.php +++ b/tests/modules/layout_paragraphs_entity_validator_test/src/Plugin/Validation/Constraint/LayoutParagraphsTestConstraint.php @@ -15,6 +15,11 @@ use Symfony\Component\Validator\Constraint; */ class LayoutParagraphsTestConstraint extends Constraint { + /** + * The message that will be shown if the value is not unique. + * + * @var string + */ public $message = 'Failed Layout Paragraphs test validation.'; } diff --git a/tests/modules/layout_paragraphs_form_rendering_test/layout_paragraphs_form_rendering_test.info.yml b/tests/modules/layout_paragraphs_form_rendering_test/layout_paragraphs_form_rendering_test.info.yml index 4641c4c6..7103e3ea 100644 --- a/tests/modules/layout_paragraphs_form_rendering_test/layout_paragraphs_form_rendering_test.info.yml +++ b/tests/modules/layout_paragraphs_form_rendering_test/layout_paragraphs_form_rendering_test.info.yml @@ -4,4 +4,4 @@ core_version_requirement: ^9.2 || ^10 || ^11 type: module package: Layout Paragraphs dependencies: - - layout_paragraphs + - layout_paragraphs:layout_paragraphs diff --git a/tests/modules/layout_paragraphs_form_rendering_test/src/Form/TestForm.php b/tests/modules/layout_paragraphs_form_rendering_test/src/Form/TestForm.php index 59194a8a..46899597 100644 --- a/tests/modules/layout_paragraphs_form_rendering_test/src/Form/TestForm.php +++ b/tests/modules/layout_paragraphs_form_rendering_test/src/Form/TestForm.php @@ -14,14 +14,14 @@ use Drupal\Core\Form\FormStateInterface; class TestForm extends FormBase { /** - * {@inheritDoc} + * {@inheritdoc} */ public function getFormId() { return 'layout_paragraphs_test_form'; } /** - * {@inheritDoc} + * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { // Intentionally named "title" to test for conflict with node title. @@ -39,7 +39,7 @@ class TestForm extends FormBase { } /** - * {@inheritDoc} + * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { } diff --git a/tests/modules/layout_paragraphs_preprocess_layout_test/layout_paragraphs_preprocess_layout_test.info.yml b/tests/modules/layout_paragraphs_preprocess_layout_test/layout_paragraphs_preprocess_layout_test.info.yml index d68a28ae..f9788f73 100644 --- a/tests/modules/layout_paragraphs_preprocess_layout_test/layout_paragraphs_preprocess_layout_test.info.yml +++ b/tests/modules/layout_paragraphs_preprocess_layout_test/layout_paragraphs_preprocess_layout_test.info.yml @@ -4,4 +4,4 @@ core_version_requirement: ^9.2 || ^10 || ^11 type: module package: Layout Paragraphs dependencies: - - layout_paragraphs + - layout_paragraphs:layout_paragraphs diff --git a/tests/modules/layout_paragraphs_translations_test/layout_paragraphs_translations_test.info.yml b/tests/modules/layout_paragraphs_translations_test/layout_paragraphs_translations_test.info.yml index c3858f65..3bdef723 100644 --- a/tests/modules/layout_paragraphs_translations_test/layout_paragraphs_translations_test.info.yml +++ b/tests/modules/layout_paragraphs_translations_test/layout_paragraphs_translations_test.info.yml @@ -4,4 +4,4 @@ core_version_requirement: ^9.2 || ^10 || ^11 type: module package: Layout Paragraphs dependencies: - - layout_paragraphs + - layout_paragraphs:layout_paragraphs diff --git a/tests/modules/test_layout_paragraphs_libraries/src/MockLibrariesDirectoryFileFinder.php b/tests/modules/test_layout_paragraphs_libraries/src/MockLibrariesDirectoryFileFinder.php index 1b43d0eb..a638b0fe 100644 --- a/tests/modules/test_layout_paragraphs_libraries/src/MockLibrariesDirectoryFileFinder.php +++ b/tests/modules/test_layout_paragraphs_libraries/src/MockLibrariesDirectoryFileFinder.php @@ -20,4 +20,4 @@ class MockLibrariesDirectoryFileFinder extends LibrariesDirectoryFileFinder { return parent::find($path); } -} \ No newline at end of file +} diff --git a/tests/src/Functional/LayoutParagraphsTest.php b/tests/src/Functional/LayoutParagraphsTest.php index 484e4618..9a27de94 100644 --- a/tests/src/Functional/LayoutParagraphsTest.php +++ b/tests/src/Functional/LayoutParagraphsTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Drupal\Tests\layout_paragraphs\Functional; use Drupal\Tests\BrowserTestBase; diff --git a/tests/src/FunctionalJavascript/AlterControlsTest.php b/tests/src/FunctionalJavascript/AlterControlsTest.php index 6eb03b59..9535ac1f 100644 --- a/tests/src/FunctionalJavascript/AlterControlsTest.php +++ b/tests/src/FunctionalJavascript/AlterControlsTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Drupal\Tests\layout_paragraphs\FunctionalJavascript; use Behat\Mink\Exception\ExpectationException; diff --git a/tests/src/FunctionalJavascript/BlockFieldTest.php b/tests/src/FunctionalJavascript/BlockFieldTest.php index f6568494..3e37d3a9 100644 --- a/tests/src/FunctionalJavascript/BlockFieldTest.php +++ b/tests/src/FunctionalJavascript/BlockFieldTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Drupal\Tests\layout_paragraphs\FunctionalJavascript; /** @@ -25,7 +27,7 @@ class BlockFieldTest extends BuilderTestBase { ]; /** - * {@inheritDoc} + * {@inheritdoc} */ protected function setUp(): void { $this->markTestSkipped('must be revisited.'); diff --git a/tests/src/FunctionalJavascript/BuilderAlteredTemplatesTest.php b/tests/src/FunctionalJavascript/BuilderAlteredTemplatesTest.php index 1102d750..c1469b5d 100644 --- a/tests/src/FunctionalJavascript/BuilderAlteredTemplatesTest.php +++ b/tests/src/FunctionalJavascript/BuilderAlteredTemplatesTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Drupal\Tests\layout_paragraphs\FunctionalJavascript; /** diff --git a/tests/src/FunctionalJavascript/BuilderTest.php b/tests/src/FunctionalJavascript/BuilderTest.php index f9f88089..d6d98582 100644 --- a/tests/src/FunctionalJavascript/BuilderTest.php +++ b/tests/src/FunctionalJavascript/BuilderTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Drupal\Tests\layout_paragraphs\FunctionalJavascript; /** @@ -171,14 +173,14 @@ class BuilderTest extends BuilderTestBase { $this->addSectionComponent(2, '.lpb-layout > .lpb-btn--add.after'); // Click the new item's drag button. - // This should create a <div> with the id 'lpb-navigatin-msg'. + // This should create a <div> with the id 'lpb-navigating-msg'. $drag_handle = $page->find('css', '.layout__region--content .lpb-drag'); $first_region = $page->find('css', '.layout__region--first'); $drag_handle->dragTo($first_region); $this->htmlOutput($this->getSession()->getPage()->getHtml()); $this->assertSession()->elementExists('css', '.layout__region--first .js-lpb-component'); -// $this->assertSession()->assertWaitOnAjaxRequest(); + // $this->assertSession()->assertWaitOnAjaxRequest(); $this->getSession()->wait(1000); $this->submitForm([ 'title[0][value]' => 'Node title', @@ -203,7 +205,7 @@ class BuilderTest extends BuilderTestBase { $this->addTextComponent('Third item', '.layout__region--third .lpb-btn--add'); // Click the new item's drag button. - // This should create a <div> with the id 'lpb-navigatin-msg'. + // This should create a <div> with the id 'lpb-navigating-msg'. $button = $page->find('css', '.layout__region--third .lpb-drag'); $button->click(); $this->assertSession()->elementExists('css', '#lpb-navigating-msg'); @@ -226,7 +228,7 @@ class BuilderTest extends BuilderTestBase { // Add a fifth item above the third item, which has been moved to the first // region, and ensure the fifth item is correctly added to the first region, - // hiding the controls ui first so it doesn't overlapp the + button. + // hiding the controls ui first so it doesn't overlap the + button. // @see https://www.drupal.org/project/layout_paragraphs/issues/3281169 $this->forceHidden('.layout__region--first .lpb-controls'); $this->addTextComponent('Fifth item', '.layout__region--first .lpb-btn--add'); @@ -268,7 +270,7 @@ class BuilderTest extends BuilderTestBase { $this->addTextComponent('Third item', '.layout__region--third .lpb-btn--add'); // Click the new item's drag button. - // This should create a <div> with the id 'lpb-navigatin-msg'. + // This should create a <div> with the id 'lpb-navigating-msg'. $button = $page->find('css', '.layout__region--third .lpb-drag'); $button->click(); $this->assertSession()->elementExists('css', '#lpb-navigating-msg'); diff --git a/tests/src/FunctionalJavascript/BuilderTestBase.php b/tests/src/FunctionalJavascript/BuilderTestBase.php index 9122fea7..68e2cc53 100644 --- a/tests/src/FunctionalJavascript/BuilderTestBase.php +++ b/tests/src/FunctionalJavascript/BuilderTestBase.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Drupal\Tests\layout_paragraphs\FunctionalJavascript; use Behat\Mink\Exception\ExpectationException; @@ -182,26 +184,22 @@ abstract class BuilderTestBase extends WebDriverTestBase { $page = $this->getSession()->getPage(); // Click the Add Component button. $page->find('css', $css_selector)->click(); -// $this->assertSession()->assertWaitOnAjaxRequest(1000, 'Unable to click add a component.'); $this->assertNotEmpty($this->assertSession()->waitForText('Choose a component')); - // Add a section. $page->clickLink('section'); -// $this->assertSession()->assertWaitOnAjaxRequest(1000, 'Unable to select section component.'); $this->assertNotEmpty($this->assertSession()->waitForText('Create new section')); // Choose a three-column layout. $elements = $page->findAll('css', '.layout-select__item label.option'); $elements[$columns_choice]->click(); -// $this->assertSession()->assertWaitOnAjaxRequest(1000, 'Unable to select layout.'); $this->assertNotEmpty($this->assertSession()->waitForText('Choose a layout:')); $this->getSession()->wait(1000); // Save the layout. $button = $page->find('css', 'button.lpb-btn--save'); $button->click(); -// $this->assertSession()->assertWaitOnAjaxRequest(); + // $this->assertSession()->assertWaitOnAjaxRequest(); $this->getSession()->wait(1000); } @@ -221,7 +219,7 @@ abstract class BuilderTestBase extends WebDriverTestBase { } /** - * {@inheritDoc} + * {@inheritdoc} * * Added method with fixed return comment for IDE type hinting. * @@ -244,14 +242,14 @@ abstract class BuilderTestBase extends WebDriverTestBase { protected function assertOrderOfStrings(array $strings, $assert_message = 'Strings are not in correct order.') { $page = $this->getSession()->getPage(); $page_text = $page->getHtml(); - $highmark = -1; + $high_mark = -1; foreach ($strings as $string) { $this->assertSession()->pageTextContains($string); $pos = strpos($page_text, $string); - if ($pos <= $highmark) { + if ($pos <= $high_mark) { throw new ExpectationException($assert_message, $this->getSession()->getDriver()); } - $highmark = $pos; + $high_mark = $pos; } } @@ -309,7 +307,7 @@ abstract class BuilderTestBase extends WebDriverTestBase { } /** - * Save and close the fronend builder. + * Save and close the frontend builder. */ protected function saveAndCloseFrontendBuilder() { $this->saveFrontendBuilder(); diff --git a/tests/src/FunctionalJavascript/CardinalityTest.php b/tests/src/FunctionalJavascript/CardinalityTest.php index c83be45b..9a9ee079 100644 --- a/tests/src/FunctionalJavascript/CardinalityTest.php +++ b/tests/src/FunctionalJavascript/CardinalityTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Drupal\Tests\layout_paragraphs\FunctionalJavascript; /** diff --git a/tests/src/FunctionalJavascript/ComplexPermissionsTest.php b/tests/src/FunctionalJavascript/ComplexPermissionsTest.php index 5fc1c28a..426c1ee3 100644 --- a/tests/src/FunctionalJavascript/ComplexPermissionsTest.php +++ b/tests/src/FunctionalJavascript/ComplexPermissionsTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Drupal\Tests\layout_paragraphs\FunctionalJavascript; /** diff --git a/tests/src/FunctionalJavascript/CorrectRegionTest.php b/tests/src/FunctionalJavascript/CorrectRegionTest.php index dec9ebb6..05c91b45 100644 --- a/tests/src/FunctionalJavascript/CorrectRegionTest.php +++ b/tests/src/FunctionalJavascript/CorrectRegionTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Drupal\Tests\layout_paragraphs\FunctionalJavascript; /** @@ -43,7 +45,7 @@ class CorrectRegionTest extends BuilderTestBase { $this->addTextComponent('Third item', '.layout__region--third .lpb-btn--add'); // Click the new item's drag button. - // This should create a <div> with the id 'lpb-navigatin-msg'. + // This should create a <div> with the id 'lpb-navigating-msg'. $button = $page->find('css', '.layout__region--third .lpb-drag'); $button->click(); @@ -60,11 +62,10 @@ class CorrectRegionTest extends BuilderTestBase { $this->keyPress('ArrowUp'); $this->assertSession()->assertWaitOnAjaxRequest(); $this->keyPress('Enter'); -// $this->assertSession()->assertWaitOnAjaxRequest(); - + // $this->assertSession()->assertWaitOnAjaxRequest(); // Add a fourth item above the third item, which has been moved to the first // region. Ensure the fourth item is correctly added to the first region, - // hiding the controls ui first so it doesn't overlapp the + button. + // hiding the controls ui first so it doesn't overlap the + button. // @see https://www.drupal.org/project/layout_paragraphs/issues/3281169 $this->forceHidden('.layout__region--first .lpb-controls'); $this->addTextComponent('Fourth item', '.layout__region--first .lpb-btn--add'); diff --git a/tests/src/FunctionalJavascript/CustomHostEntityTest.php b/tests/src/FunctionalJavascript/CustomHostEntityTest.php index c88ba8f0..b0566548 100644 --- a/tests/src/FunctionalJavascript/CustomHostEntityTest.php +++ b/tests/src/FunctionalJavascript/CustomHostEntityTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Drupal\Tests\layout_paragraphs\FunctionalJavascript; use Drupal\field\Entity\FieldConfig; @@ -61,7 +63,7 @@ class CustomHostEntityTest extends BuilderTest { ]; /** - * {@inheritDoc} + * {@inheritdoc} * * Adds fields to the custom host entity rather than a content type. */ diff --git a/tests/src/FunctionalJavascript/DisplayModeTest.php b/tests/src/FunctionalJavascript/DisplayModeTest.php index bf4bb730..a434621b 100644 --- a/tests/src/FunctionalJavascript/DisplayModeTest.php +++ b/tests/src/FunctionalJavascript/DisplayModeTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Drupal\Tests\layout_paragraphs\FunctionalJavascript; use Drupal\Core\Entity\Entity\EntityFormDisplay; @@ -8,8 +10,7 @@ use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\Core\Entity\Entity\EntityViewMode; /** - * Tests setting non-default view modes for paragraphs rendered on the page and - * rendered in the preview. Also tests setting a non-default form display mode. + * Tests non-default view modes and form modes. * * @group layout_paragraphs */ @@ -29,7 +30,7 @@ class DisplayModeTest extends BuilderTestBase { ]; /** - * {@inheritDoc} + * {@inheritdoc} */ protected function setUp(): void { parent::setUp(); diff --git a/tests/src/FunctionalJavascript/DuplicateComponentsTest.php b/tests/src/FunctionalJavascript/DuplicateComponentsTest.php index a30ea0fa..d6b26d29 100644 --- a/tests/src/FunctionalJavascript/DuplicateComponentsTest.php +++ b/tests/src/FunctionalJavascript/DuplicateComponentsTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Drupal\Tests\layout_paragraphs\FunctionalJavascript; use Behat\Mink\Exception\ExpectationException; diff --git a/tests/src/FunctionalJavascript/EmptyComponentListTest.php b/tests/src/FunctionalJavascript/EmptyComponentListTest.php index 75ac7542..5ba52da1 100644 --- a/tests/src/FunctionalJavascript/EmptyComponentListTest.php +++ b/tests/src/FunctionalJavascript/EmptyComponentListTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Drupal\Tests\layout_paragraphs\FunctionalJavascript; /** diff --git a/tests/src/FunctionalJavascript/FormRenderingTest.php b/tests/src/FunctionalJavascript/FormRenderingTest.php index 64543991..00823e16 100644 --- a/tests/src/FunctionalJavascript/FormRenderingTest.php +++ b/tests/src/FunctionalJavascript/FormRenderingTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Drupal\Tests\layout_paragraphs\FunctionalJavascript; /** diff --git a/tests/src/FunctionalJavascript/LayoutParagraphsLibraryTest.php b/tests/src/FunctionalJavascript/LayoutParagraphsLibraryTest.php index 69e22c27..980c76ad 100644 --- a/tests/src/FunctionalJavascript/LayoutParagraphsLibraryTest.php +++ b/tests/src/FunctionalJavascript/LayoutParagraphsLibraryTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Drupal\Tests\layout_paragraphs\FunctionalJavascript; /** @@ -28,7 +30,7 @@ class LayoutParagraphsLibraryTest extends BuilderTestBase { ]; /** - * {@inheritDoc} + * {@inheritdoc} */ protected function setUp(): void { parent::setUp(); diff --git a/tests/src/FunctionalJavascript/LayoutParagraphsPermissionsTest.php b/tests/src/FunctionalJavascript/LayoutParagraphsPermissionsTest.php index 6423c4a3..a012b1d9 100644 --- a/tests/src/FunctionalJavascript/LayoutParagraphsPermissionsTest.php +++ b/tests/src/FunctionalJavascript/LayoutParagraphsPermissionsTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Drupal\Tests\layout_paragraphs\FunctionalJavascript; /** diff --git a/tests/src/FunctionalJavascript/ModalHeightTest.php b/tests/src/FunctionalJavascript/ModalHeightTest.php index 6297acf5..351e3b57 100644 --- a/tests/src/FunctionalJavascript/ModalHeightTest.php +++ b/tests/src/FunctionalJavascript/ModalHeightTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Drupal\Tests\layout_paragraphs\FunctionalJavascript; /** diff --git a/tests/src/FunctionalJavascript/NestedSectionsTest.php b/tests/src/FunctionalJavascript/NestedSectionsTest.php index f95dad68..388e7d41 100644 --- a/tests/src/FunctionalJavascript/NestedSectionsTest.php +++ b/tests/src/FunctionalJavascript/NestedSectionsTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Drupal\Tests\layout_paragraphs\FunctionalJavascript; use Drupal\Core\Entity\Entity\EntityFormDisplay; @@ -12,7 +14,7 @@ use Drupal\Core\Entity\Entity\EntityFormDisplay; class NestedSectionsTest extends BuilderTestBase { /** - * {@inheritDoc} + * {@inheritdoc} */ protected function setUp(): void { parent::setUp(); diff --git a/tests/src/FunctionalJavascript/ParagraphsWidgetCompatibilityTest.php b/tests/src/FunctionalJavascript/ParagraphsWidgetCompatibilityTest.php index 19f65343..17b786af 100644 --- a/tests/src/FunctionalJavascript/ParagraphsWidgetCompatibilityTest.php +++ b/tests/src/FunctionalJavascript/ParagraphsWidgetCompatibilityTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Drupal\Tests\layout_paragraphs\FunctionalJavascript; use Drupal\FunctionalJavascriptTests\WebDriverTestBase; @@ -92,7 +94,7 @@ class ParagraphsWidgetCompatibilityTest extends WebDriverTestBase { $this->submitForm([ 'title[0][value]' => 'Node title', ], 'Save'); - $this->assertSession()->pageTextNotContains('The website encountered an unexpected error. Please try again later.'); + $this->assertSession()->pageTextNotContains('The website encountered an unexpected error.'); } diff --git a/tests/src/FunctionalJavascript/PreprocessLayoutTest.php b/tests/src/FunctionalJavascript/PreprocessLayoutTest.php index 1ad3241e..c71a79d0 100644 --- a/tests/src/FunctionalJavascript/PreprocessLayoutTest.php +++ b/tests/src/FunctionalJavascript/PreprocessLayoutTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Drupal\Tests\layout_paragraphs\FunctionalJavascript; /** diff --git a/tests/src/FunctionalJavascript/ReorderFormElementsTest.php b/tests/src/FunctionalJavascript/ReorderFormElementsTest.php index b884ce9b..9f4f7145 100644 --- a/tests/src/FunctionalJavascript/ReorderFormElementsTest.php +++ b/tests/src/FunctionalJavascript/ReorderFormElementsTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Drupal\Tests\layout_paragraphs\FunctionalJavascript; /** @@ -24,9 +26,6 @@ class ReorderFormElementsTest extends BuilderTestBase { ]); $this->drupalGet('admin/structure/paragraphs_type/section/form-display'); $page = $this->getSession()->getPage(); -// $published_field = $page->find('xpath', '//tr[@id="status"]//a[@class="tabledrag-handle"]'); -// $lp_fields = $page->find('xpath', '//tr[@id="layout-paragraphs-fields"]'); -// $published_field->dragTo($lp_fields); $published_field = $page->find('css', 'tr#status a.tabledrag-handle'); $published_field->dragTo($page->find('css', 'tr#layout-paragraphs-fields td')); $this->submitForm([], 'Save'); @@ -56,9 +55,6 @@ class ReorderFormElementsTest extends BuilderTestBase { ]); $this->drupalGet('admin/structure/paragraphs_type/section/form-display'); $page = $this->getSession()->getPage(); -// $published_field = $page->find('xpath', '//tr[@id="status"]'); -// $lp_fields = $page->find('xpath', '//tr[@id="layout-paragraphs-fields"]//a[@class="tabledrag-handle"]'); -// $lp_fields->dragTo($published_field); $lp_fields = $page->find('css', 'tr#layout-paragraphs-fields a.tabledrag-handle'); $lp_fields->dragTo($page->find('css', 'tr#status')); $this->submitForm([], 'Save'); diff --git a/tests/src/FunctionalJavascript/TranslationTest.php b/tests/src/FunctionalJavascript/TranslationTest.php index c87ff21c..1fb6b591 100644 --- a/tests/src/FunctionalJavascript/TranslationTest.php +++ b/tests/src/FunctionalJavascript/TranslationTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Drupal\Tests\layout_paragraphs\FunctionalJavascript; use Behat\Mink\Exception\ExpectationException; @@ -100,7 +102,7 @@ class TranslationTest extends BuilderTestBase { /** * Tests adding paragraphs in the correct language. */ - public function testAddedInCorrectLanugage() { + public function testAddedInCorrectLanguage() { $this->testSwitchLanguage(); $this->drupalGet('node/1/edit'); $this->addTextComponent('Language should be "de".', '.layout__region--first .lpb-btn--add.after'); @@ -169,7 +171,7 @@ class TranslationTest extends BuilderTestBase { } /** - * Tests symmetric or assymetric translations. + * Tests symmetric or asymmetric translations. */ protected function testContentTranslations($asymmetric = FALSE) { @@ -235,7 +237,7 @@ class TranslationTest extends BuilderTestBase { } else { // If in symmetric mode, deleting component from the primary language - // deletes it everyhere. + // deletes it everywhere. $this->assertSession()->pageTextNotContains('third (de)'); } diff --git a/tests/src/FunctionalJavascript/ValidationConstraintTest.php b/tests/src/FunctionalJavascript/ValidationConstraintTest.php index 00c4ce7e..ad5fd726 100644 --- a/tests/src/FunctionalJavascript/ValidationConstraintTest.php +++ b/tests/src/FunctionalJavascript/ValidationConstraintTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Drupal\Tests\layout_paragraphs\FunctionalJavascript; /** @@ -53,7 +55,7 @@ class ValidationConstraintTest extends BuilderTestBase { $this->assertSession()->assertWaitOnAjaxRequest(); // Assert the fail message exists. $this->assertSession()->pageTextContains('Failed Layout Paragraphs test validation.'); - // Asser the form is still present and hasn't been closed. + // Assert the form is still present and hasn't been closed. $this->assertSession()->elementExists('css', 'form.layout-paragraphs-component-form'); $this->htmlOutput($this->getSession()->getPage()->getHtml()); -- GitLab