TomeStaticCronSettingsForm.php in Tome 8        
                          
                  
                        
  
  
  
  
  
File
  modules/tome_static/modules/tome_static_cron/src/Form/TomeStaticCronSettingsForm.php
  
    View source  
  <?php
namespace Drupal\tome_static_cron\Form;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class TomeStaticCronSettingsForm extends ConfigFormBase {
  
  public function getFormId() {
    return 'tome_static_cron_settings_form';
  }
  
  protected function getEditableConfigNames() {
    return [
      'tome_static_cron.settings',
    ];
  }
  
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildForm($form, $form_state);
    $config = $this
      ->config('tome_static_cron.settings');
    $form['base_url'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Base URL'),
      '#description' => $this
        ->t('The base URL to use for static cron runs.'),
      '#default_value' => $config
        ->get('base_url'),
      '#required' => TRUE,
    ];
    return $form;
  }
  
  public function validateForm(array &$form, FormStateInterface $form_state) {
    if (!UrlHelper::isValid($form_state
      ->getValue('base_url'), TRUE)) {
      $form_state
        ->setError($form['base_url'], $this
        ->t('The provided URL is not valid.'));
    }
  }
  
  public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form, $form_state);
    $config = $this
      ->config('tome_static_cron.settings');
    $config
      ->set('base_url', $form_state
      ->getValue('base_url'));
    $config
      ->save();
  }
}