Skip to content
Snippets Groups Projects
Commit 80c3e0e9 authored by Sven Decabooter's avatar Sven Decabooter
Browse files

Merge branch '3511134-add-schema-validation' into '1.3.x'

Resolve #3511134 "Add schema validation"

See merge request !23
parents 3a72919b a80479d3
No related branches found
No related tags found
No related merge requests found
Pipeline #447628 passed
......@@ -9,3 +9,4 @@ layout_builder_iframe_routes:
- layout_builder.move_block_form
- layout_builder.translate_block
- layout_builder.translate_inline_block
custom_routes: { }
......@@ -8,9 +8,15 @@ layout_builder_iframe_modal.settings:
sequence:
type: string
label: 'Route'
constraints:
NotBlank: { }
custom_routes:
type: sequence
label: 'Custom Iframe routes'
sequence:
type: string
label: 'Route'
constraints:
NotBlank: { }
constraints:
FullyValidatable: ~
name: Layout Builder iFrame Modal
type: module
description: 'Render Layout Builder edit forms in an iframe'
core_version_requirement: ^10.1.3 || ^11
core_version_requirement: ^10.3 || ^11
lifecycle: stable
configure: layout_builder_iframe_modal.settings
dependencies:
- drupal:layout_builder
......@@ -33,3 +33,14 @@ function layout_builder_iframe_modal_post_update_remove_duplicate_route_prefixes
$config->set('layout_builder_iframe_routes', $routes)->save();
}
/**
* Add default value for custom_routes config if empty.
*/
function layout_builder_iframe_modal_post_update_custom_routes_config(): void {
$config = \Drupal::service('config.factory')->getEditable('layout_builder_iframe_modal.settings');
$custom_routes = $config->get('custom_routes');
if (empty($custom_routes)) {
$config->set('custom_routes', [])->save();
}
}
......@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Drupal\layout_builder_iframe_modal\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\ConfigTarget;
use Drupal\Core\Form\FormStateInterface;
/**
......@@ -30,8 +31,6 @@ class LayoutBuilderIframeModalSettingsForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state): array {
$config = $this->config('layout_builder_iframe_modal.settings');
$options = [
'layout_builder.configure_section' => $this->t('Configure section'),
'layout_builder.remove_section' => $this->t('Remove section'),
......@@ -49,40 +48,36 @@ class LayoutBuilderIframeModalSettingsForm extends ConfigFormBase {
$options[$key] = $label . " ($key)";
}
$defaults = $config->get('layout_builder_iframe_routes');
$form['layout_builder_iframe_routes'] = [
'#type' => 'checkboxes',
'#title' => $this->t('Layout Builder Routes'),
'#description' => $this->t('Select Layout Builder routes to apply iframe to.'),
'#options' => $options,
'#default_value' => $defaults,
'#config_target' => new ConfigTarget(
'layout_builder_iframe_modal.settings',
'layout_builder_iframe_routes',
// Converts config value to a form value.
NULL,
// Converts form value to a config value.
fn ($value) => array_keys(array_filter($value)),
),
];
$custom_routes = $config->get('custom_routes') ?? [];
$form['custom_routes'] = [
'#type' => 'textarea',
'#title' => $this->t('Custom routes'),
'#description' => $this->t('Add custom routes (one per line) that should also open in an iframe modal. Note that it can only apply to routes which are already configured to open in a dialog. It may require additional code for the route to actually open in an iframe modal.'),
'#default_value' => implode("\r\n", $custom_routes),
'#config_target' => new ConfigTarget(
'layout_builder_iframe_modal.settings',
'custom_routes',
// Converts config value to a form value.
fn($value) => implode("\n", $value),
// Converts form value to a config value.
fn($value) => array_filter(array_map('trim', explode("\n", trim($value)))),
),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state): void {
$config = $this->config('layout_builder_iframe_modal.settings');
$options = array_filter(array_values($form_state->getValue('layout_builder_iframe_routes')));
$config->set('layout_builder_iframe_routes', $options);
$custom_routes = explode("\r\n", $form_state->getValue('custom_routes'));
$config->set('custom_routes', array_values(array_filter($custom_routes)));
$config->save();
parent::submitForm($form, $form_state);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment