Skip to content
Snippets Groups Projects
Commit 712d62b0 authored by Den's avatar Den Committed by Yurii Panchuk
Browse files

Issue #3283984 by Chesterr, galileo25, Panchuk, økse, swentel: Sections...

Issue #3283984 by Chesterr, galileo25, Panchuk, økse, swentel: Sections ordering for the locked sections
parent eb3e2f7a
Branches
Tags
1 merge request!11Issue #3283984: Sections ordering for the locked sections.
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\layout_builder\OverridesSectionStorageInterface; use Drupal\layout_builder\OverridesSectionStorageInterface;
use Drupal\layout_builder_lock\LayoutBuilderLock; use Drupal\layout_builder_lock\LayoutBuilderLock;
use Drupal\Core\Url;
/** /**
* Implements hook_element_info_alter(). * Implements hook_element_info_alter().
...@@ -179,3 +181,36 @@ function layout_builder_lock_block_operations() { ...@@ -179,3 +181,36 @@ function layout_builder_lock_block_operations() {
'layout_builder_block_remove' => 'layout-builder-block-remove' 'layout_builder_block_remove' => 'layout-builder-block-remove'
]; ];
} }
/**
* Implements hook_form_alter().
*/
function layout_builder_lock_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if (!empty($form['actions']['move_sections'])) {
// Get the sections from the form state.
$sections = $form_state->getBuildInfo()['args'][0]->getContext('display')->getContextData()->getEntity()->getThirdPartySettings('layout_builder')['sections'];
$locks = [];
foreach ($sections as $value) {
if (!empty($value->getThirdPartySettings('layout_builder_lock')['lock'])) {
$lock = $value->getThirdPartySettings('layout_builder_lock')['lock'];
if (!empty($lock)) {
$locks += $lock;
}
}
}
// Check if any lock has LOCKED_SECTION_CONFIGURE option.
if (in_array(LayoutBuilderLock::LOCKED_SECTION_CONFIGURE, $locks)) {
// Add classes to the move_sections button and make it inactive.
$form['actions']['move_sections']['#attributes']['class'] = [
'is-disabled',
'button',
];
// Added alert text for inactive button.
$form['actions']['move_sections']['#attributes']['title'] = t('You cannot reorder the sections, as the section has the option: Do not allow configuring the section');
// Set the inactive URL for the move_sections button.
$form['actions']['move_sections']['#url'] = Url::fromRoute('<none>');
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment