DomainSourceSettingsForm.php in Domain Access 8
File
domain_source/src/Form/DomainSourceSettingsForm.php
View source
<?php
namespace Drupal\domain_source\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class DomainSourceSettingsForm extends ConfigFormBase {
public function getFormId() {
return 'domain_source_settings';
}
protected function getEditableConfigNames() {
return [
'domain_source.settings',
];
}
public function buildForm(array $form, FormStateInterface $form_state) {
$manager = \Drupal::entityTypeManager();
$routes = $manager
->getDefinition('node')
->getLinkTemplates();
$options = [];
foreach ($routes as $route => $path) {
$route = str_replace([
'-',
'drupal:',
], [
'_',
'',
], $route);
$options[$route] = $route;
}
$config = $this
->config('domain_source.settings');
$form['exclude_routes'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Disable link rewrites for the selected routes.'),
'#default_value' => $config
->get('exclude_routes') ?: [],
'#options' => $options,
'#description' => $this
->t('Check the routes to disable. Any entity URL with a Domain Source field will be rewritten unless its corresponding route is disabled.'),
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->config('domain_source.settings')
->set('exclude_routes', $form_state
->getValue('exclude_routes'))
->save();
parent::submitForm($form, $form_state);
}
}