Skip to content
Snippets Groups Projects

Issue #3367015: Refactor Layout Builder Form Alter with a better logic

1 file
+ 23
26
Compare changes
  • Side-by-side
  • Inline
@@ -47,10 +47,10 @@ function varbase_layout_builder_form_alter(&$form, FormStateInterface $form_stat
// Only for layout builder forms.
if (isset($form_id) && strpos($form_id, '_layout_builder_form') !== FALSE) {
// Attache the Varbase Layout Builder enhancements libraray.
// Attache the Varbase Layout Builder enhancements library.
$form['#attached']['library'][] = 'varbase_layout_builder/enhancements';
// Attache the Varbase Layout Builder configure section admin libraray.
// Attache the Varbase Layout Builder configure section admin library.
$form['#attached']['library'][] = 'varbase_layout_builder/configure-section.admin';
// No revision information or revision log message.
@@ -80,33 +80,30 @@ function varbase_layout_builder_form_alter(&$form, FormStateInterface $form_stat
}
}
$current_path = \Drupal::service('path.current')->getPath();
$url_object = \Drupal::service('path.validator')->getUrlIfValid($current_path);
$route_name = '';
if (isset($url_object) && is_object($url_object)) {
$route_name = $url_object->getRouteName();
}
$applicable_forms = [
'layout_builder_add_block',
'layout_builder_update_block',
'media_image_edit_form',
];
if (in_array($form_id, $applicable_forms)
|| $route_name === 'layout_builder.overrides.node.view') {
$config = \Drupal::config('varbase_layout_builder.settings');
$use_claro = $config->get('use_claro');
if (isset($use_claro) && $use_claro == 1
&& \Drupal::service('theme_handler')->themeExists('claro')) {
if ($form_id !== 'layout_builder_configure_section') {
$config = \Drupal::config('varbase_layout_builder.settings');
$use_claro = $config->get('use_claro');
$applicable_forms = [
'layout_builder_add_block',
'layout_builder_update_block',
'media_image_edit_form',
];
if (isset($use_claro) && $use_claro == 1
&& !version_compare(\Drupal::VERSION, '8.8.0', 'lt')) {
if (in_array($form_id, $applicable_forms)) {
$form['#attached']['library'][] = 'varbase_layout_builder/claro';
}
else {
$current_path = \Drupal::service('path.current')->getPath();
$url_object = \Drupal::service('path.validator')->getUrlIfValid($current_path);
$route_name = '';
if (isset($url_object) && is_object($url_object) && $url_object->isRouted()) {
$route_name = $url_object->getRouteName();
}
if (\Drupal::service('theme_handler')->themeExists('claro')) {
// Add claro theme libraries.
$form['#attached']['library'][] = 'varbase_layout_builder/claro';
}
if ($route_name === 'layout_builder.overrides.node.view') {
$form['#attached']['library'][] = 'varbase_layout_builder/claro';
}
}
}
Loading