l10n_server-2.x-dev/l10n_packager/src/Form/L10nPackagerSettingsForm.php

l10n_packager/src/Form/L10nPackagerSettingsForm.php
<?php

declare(strict_types=1);

namespace Drupal\l10n_packager\Form;

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * Configure Localization packager settings for this site.
 */
class L10nPackagerSettingsForm extends ConfigFormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'l10n_packager_l10n_packager_settings';
  }

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return ['l10n_packager.settings'];
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['cron'] = [
      '#type' => 'checkbox',
      '#title' => t('Generate packages on every Drupal cron run'),
      '#default_value' => $this->config('l10n_packager.settings')->get('cron'),
    ];
    $form['directory'] = [
      '#type' => 'textfield',
      '#title' => t('Directory for generated packages'),
      '#description' => t('The directory on the local file system to use to store packages generated. Either relative to the Drupal installation directory or an absolute path on your file system. Drupal should have read and write access to the files and directories found there.'),
      '#default_value' => $this->config('l10n_packager.settings')->get('directory'),
      '#required' => TRUE,
    ];
    $form['update_url'] = [
      '#type' => 'textfield',
      '#title' => t('Root URL for translation downloads'),
      '#description' => t('Root URL for the client to build file URLs and fetch updates. The public facing URL for the package directory defined above. Leave blank for not providing any.'),
      '#default_value' => $this->config('l10n_packager.settings')->get('update_url'),
    ];
    $form['filepath'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Filepath'),
      '#default_value' => $this->config('l10n_packager.settings')->get('filepath'),
    ];
    $form['release_limit'] = [
      '#type' => 'select',
      '#title' => t('Number of releases to check at once'),
      '#description' => t('The number of releases to check on a manual or cron run.'),
      '#options' => array_combine(
        [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100],
        [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100]
      ),
      '#default_value' => $this->config('l10n_packager.settings')->get('release_limit'),
    ];
    $form['file_limit'] = [
      '#title' => t('Maximum number of files to package at once'),
      '#description' => t('The number of files to package on a manual or cron run.'),
      '#type' => 'select',
      '#options' => array_combine(
        [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100],
        [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100]
      ),
      '#default_value' => $this->config('l10n_packager.settings')->get('file_limit'),
    ];
    // Logging settings.
    // @todo format_interval
    $period = [0 => t('Never'), 1 => t('Every cron run')] + array_combine(
      // phpcs:ignore
      [3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800,],
      // phpcs:ignore
      [3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800]
    );
    $form['update'] = [
      '#type' => 'select',
      '#title' => t('Repackaging interval'),
      '#description' => t('Time interval for the translations to be automatically repackaged.'),
      '#options' => $period,
      '#default_value' => $this->config('l10n_packager.settings')->get('update'),
    ];
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    /** @var \Drupal\Core\File\FileSystemInterface $file_system */
    $file_system = \Drupal::service('file_system');
    $directory = $form_state->getValue('directory');
    $file_system->prepareDirectory($directory);

    $this->config('l10n_packager.settings')
      ->set('cron', $form_state->getValue('cron'))
      ->set('directory', $form_state->getValue('directory'))
      ->set('update_url', $form_state->getValue('update_url'))
      ->set('filepath', $form_state->getValue('filepath'))
      ->set('release_limit', $form_state->getValue('release_limit'))
      ->set('file_limit', $form_state->getValue('file_limit'))
      ->set('update', $form_state->getValue('update'))
      ->save();
    parent::submitForm($form, $form_state);
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc