config_preview_deploy-1.0.0-alpha3/src/Form/SettingsForm.php
src/Form/SettingsForm.php
<?php
declare(strict_types=1);
namespace Drupal\config_preview_deploy\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Configuration form for Config Preview Deploy settings.
*/
class SettingsForm extends ConfigFormBase {
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
$instance = parent::create($container);
$instance->moduleHandler = $container->get('module_handler');
return $instance;
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames(): array {
return ['config_preview_deploy.settings'];
}
/**
* {@inheritdoc}
*/
public function getFormId(): string {
return 'config_preview_deploy_settings';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state): array {
$config = $this->config('config_preview_deploy.settings');
$form['production_settings'] = [
'#type' => 'fieldset',
'#title' => $this->t('Production Environment'),
'#description' => $this->t('Configure the production environment where configurations will be deployed.'),
];
$form['production_settings']['production_url'] = [
'#type' => 'url',
'#title' => $this->t('Production URL'),
'#description' => $this->t('The base URL of the production environment (e.g., https://example.com).'),
'#default_value' => $config->get('production_url'),
'#required' => TRUE,
];
// Add config_ignore integration information if the module is enabled.
if ($this->moduleHandler->moduleExists('config_ignore')) {
$form['config_ignore_integration'] = [
'#type' => 'fieldset',
'#title' => $this->t('Configuration Filtering'),
];
$form['config_ignore_integration']['info'] = [
'#markup' => '<p>' . $this->t('The Config Ignore module is active. Ignored configurations will be excluded from deployment diffs and will not be deployed to production.') . '</p>',
];
$form['config_ignore_integration']['configure_link'] = [
'#type' => 'link',
'#title' => $this->t('Configure ignored configurations'),
'#url' => Url::fromRoute('config_ignore.settings'),
'#attributes' => [
'class' => ['button', 'button--small'],
],
];
}
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state): void {
$this->config('config_preview_deploy.settings')
->set('production_url', $form_state->getValue('production_url'))
->save();
parent::submitForm($form, $form_state);
}
}
