Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds localgov_admin_theme_improvements module #119

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(function GinLayoutParagraphsScript(Drupal) {
Drupal.behaviors.GinLayoutParagraphs = {
attach(context) {

function ginLayoutParagraphsFix() {
const layoutParagraphsDialogs = context.querySelectorAll('.ui-dialog.layout-paragraphs-dialog');
layoutParagraphsDialogs.forEach(layoutParagraphsDialog => {
const form = layoutParagraphsDialog.closest('form');
const overlay = context.querySelector('.ui-widget-overlay.ui-front');
const paragraphsField = layoutParagraphsDialog.closest('.field--type-entity-reference-revisions');
const placeholder = document.createElement('div');
placeholder.classList.add('js-layout-paragraph-base-field-placeholder');

if (layoutParagraphsDialog.classList.contains('js-localgov-layout-paragraph-processed')) {
return;
} else {
if (!layoutParagraphsDialog.classList.contains('js-modal-moved')) {
// Add a placeholder so the field can be moved back to here
// when the modal is closed.
paragraphsField.insertBefore(placeholder, paragraphsField.querySelector('.form-item'));

// Move the overlay and the paragraph entity reference field
// to be placed just before we close </form>.
form.insertBefore(overlay, context.querySelector('form > *:last-child').nextSibling);
form.insertBefore(paragraphsField, context.querySelector('form > *:last-child').nextSibling);
layoutParagraphsDialog.classList.add('js-modal-moved');

// When modal is removed, move the paragraph entity reference field back.
layoutParagraphsDialog.addEventListener('remove', function() {
placeholder.replaceWith(paragraphsField);
});
}
layoutParagraphsDialog.classList.add('js-localgov-layout-paragraph-processed')
}
})
}

ginLayoutParagraphsFix();

}
};
})(Drupal);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: LocalGov Admin Theme Improvements
type: module
description: 'Small items to fix issues with the admin theme.'
package: Localgov
core_version_requirement: ^8.8 || ^9
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gin-layout-paragraphs:
js:
js/gin-layout-paragraphs.js: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/**
* @file
* Provides any functions we need to fix admin theme issues.
*/

use Drupal\Core\Form\FormStateInterface;

/**
* Implements hook_layout_paragraphs_layout_paragraph_element_form_alter().
* */
function localgov_admin_theme_improvements_layout_paragraph_element_form_alter(array &$element_form, FormStateInterface &$element_form_state, array $parent_form) {
$current_active_theme = \Drupal::service('theme.manager')->getActiveTheme()->getName();
if ($current_active_theme === 'gin') {
$element_form['#attached']['library'][] = 'localgov_admin_theme_improvements/gin-layout-paragraphs';
}
}