/
admin_theme.module
39 lines (32 loc) · 1.62 KB
/
admin_theme.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
use Drupal\Core\Form\FormState;
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_form_FORM_ID_alter() for system_themes_admin_form.
*
* @see admin_theme_form_system_themes_form_alter_submit()
*/
function admin_theme_form_system_themes_admin_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$paths = \Drupal::configFactory()->getEditable('admin_theme.settings')->get('paths');
$condition = \Drupal::service('plugin.manager.condition')->createInstance('request_path', ['pages' => $paths]);
$form_state->set(['conditions', 'admin_theme_request_path'], $condition);
$form['admin_theme']['admin_theme_request_path'] = $condition->buildConfigurationForm([], $form_state);
$form['admin_theme']['admin_theme_request_path']['#tree'] = TRUE;
unset($form['admin_theme']['admin_theme_request_path']['negate']);
$form['#submit'][] = 'admin_theme_form_system_themes_form_alter_submit';
}
/**
* Form submission handler for system_themes_admin_form.
*
* @see admin_theme_form_system_themes_admin_form_alter()
*/
function admin_theme_form_system_themes_form_alter_submit($form, FormStateInterface $form_state) {
$condition = $form_state->get(['conditions', 'admin_theme_request_path']);
$condition_values = (new FormState())->setValues($form_state->getValue('admin_theme_request_path'));
$condition->submitConfigurationForm($form, $condition_values);
$condition_configuration = $condition->getConfiguration();
\Drupal::configFactory()->getEditable('admin_theme.settings')
->set('paths', $condition_configuration['pages'])
->save();
\Drupal::service('router.builder')->setRebuildNeeded();
}