You are here

class AuditFilesConfig in Audit Files 8.3

Same name and namespace in other branches
  1. 8 src/Form/AuditFilesConfig.php \Drupal\auditfiles\Form\AuditFilesConfig
  2. 8.2 src/Form/AuditFilesConfig.php \Drupal\auditfiles\Form\AuditFilesConfig
  3. 4.x src/Form/AuditFilesConfig.php \Drupal\auditfiles\Form\AuditFilesConfig

Use this class to create configuration form for module.

Hierarchy

Expanded class hierarchy of AuditFilesConfig

1 string reference to 'AuditFilesConfig'
auditfiles.routing.yml in ./auditfiles.routing.yml
auditfiles.routing.yml

File

src/Form/AuditFilesConfig.php, line 15

Namespace

Drupal\auditfiles\Form
View source
class AuditFilesConfig extends ConfigFormBase {

  /**
   * The Stream Wrapper Manager service.
   *
   * @var \Drupal\Core\StreamWrapperInterface
   */
  protected $streamWrapperManager;

  /**
   * Class constructor.
   *
   * @param Drupal\Core\StreamWrapper\StreamWrapperManager $stream_wrapper
   *   The stream wrapper service.
   */
  public function __construct(StreamWrapperManager $stream_wrapper) {
    $this->streamWrapperManager = $stream_wrapper;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('stream_wrapper_manager'));
  }

  /**
   * Widget Id.
   */
  public function getFormId() {
    return 'auditfiles_config';
  }

  /**
   * Create configurations Name.
   */
  protected function getEditableConfigNames() {
    return [
      'auditfiles.settings',
    ];
  }

  /**
   * Create form for configurations.
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this
      ->config('auditfiles.settings');
    $form['auditfiles_file_system_paths'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('File system paths'),
      '#collapsible' => TRUE,
    ];

    // Show the file system path select list.
    $file_system_paths = $this->streamWrapperManager
      ->getWrappers(StreamWrapperInterface::LOCAL);
    $options = [];
    foreach ($file_system_paths as $file_system_path_id => $file_system_path) {
      $options[$file_system_path_id] = $file_system_path_id . ' : file_' . $file_system_path_id . '_path';
    }
    $form['auditfiles_file_system_paths']['auditfiles_file_system_path'] = [
      '#type' => 'select',
      '#title' => 'File system path',
      '#default_value' => $config
        ->get('auditfiles_file_system_path'),
      '#options' => $options,
      '#description' => $this
        ->t('Select the file system path to use when searching for and comparing files.'),
    ];
    $form['auditfiles_exclusions'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Exclusions'),
      '#collapsible' => TRUE,
    ];
    $form['auditfiles_exclusions']['auditfiles_exclude_files'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Exclude these files'),
      '#default_value' => $config
        ->get('auditfiles_exclude_files'),
      '#description' => $this
        ->t('Enter a list of files to exclude, each separated by the semi-colon character (;).'),
    ];
    $form['auditfiles_exclusions']['auditfiles_exclude_extensions'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Exclude these extensions'),
      '#default_value' => $config
        ->get('auditfiles_exclude_extensions'),
      '#description' => $this
        ->t('Enter a list of extensions to exclude, each separated by the semi-colon character (;). Do not include the leading dot.'),
    ];
    $form['auditfiles_exclusions']['auditfiles_exclude_paths'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Exclude these paths'),
      '#default_value' => $config
        ->get('auditfiles_exclude_paths'),
      '#description' => $this
        ->t('Enter a list of paths to exclude, each separated by the semi-colon character (;). Do not include the leading slash.'),
    ];
    $form['auditfiles_domains'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Domains'),
      '#collapsible' => TRUE,
    ];
    $form['auditfiles_domains']['auditfiles_include_domains'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Include references to these domains'),
      '#default_value' => $config
        ->get('auditfiles_include_domains'),
      '#size' => 80,
      '#maxlength' => 1024,
      '#description' => $this
        ->t('Enter a list of domains (e.g., www.example.com) pointing to your website, each separated by the semi-colon character (;). <br />When scanning content for file references (such as &lt;img&gt;tags), any absolute references using these domains will be included and rewritten to use relative references. Absolute references to domains not in this list will be considered to be external references and will not be audited or rewritten.'),
    ];
    $form['auditfiles_report_options'] = [
      '#type' => 'fieldset',
      '#title' => $this
        ->t('Report options'),
      '#collapsible' => TRUE,
    ];
    $date_types = DateFormat::loadMultiple();
    foreach ($date_types as $machine_name => $format) {
      $date_formats[$machine_name] = $machine_name;
    }
    $form['auditfiles_report_options']['auditfiles_report_options_date_format'] = [
      '#type' => 'select',
      '#title' => 'Date format',
      '#default_value' => $config
        ->get('auditfiles_report_options_date_format'),
      '#options' => $date_formats,
      '#description' => $this
        ->t('Select the date format to use when displaying file dates in the reports.'),
    ];
    $form['auditfiles_report_options']['auditfiles_report_options_items_per_page'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Number of items per page'),
      '#default_value' => $config
        ->get('auditfiles_report_options_items_per_page'),
      '#size' => 10,
      '#description' => $this
        ->t('Enter an integer representing the number of items to display on each page of a report.<br /> If there are more than this number on a page, then a pager will be used to display the additional items.<br /> Set this to 0 to show all items on a single page.'),
    ];
    $form['auditfiles_report_options']['auditfiles_report_options_maximum_records'] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Maximum records'),
      '#default_value' => $config
        ->get('auditfiles_report_options_maximum_records'),
      '#size' => 10,
      '#description' => $this
        ->t('Enter an integer representing the maximum number of records to return for each report.<br /> If any of the reports are timing out, set this to some positive integer to limit the number of records that are queried in the database. For reports where the limit is reached, a button to batch process the loading of the page will be available that will allow all records to be retrieved without timing out.<br /> Set this to 0 for no limit.'),
    ];
    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this
        ->t('Submit'),
    ];
    return parent::buildForm($form, $form_state);
  }

  /**
   * Submit popup after login configurations.
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this
      ->config('auditfiles.settings')
      ->set('auditfiles_file_system_path', trim($form_state
      ->getValue('auditfiles_file_system_path')))
      ->set('auditfiles_exclude_files', trim($form_state
      ->getValue('auditfiles_exclude_files')))
      ->set('auditfiles_exclude_extensions', trim($form_state
      ->getValue('auditfiles_exclude_extensions')))
      ->set('auditfiles_exclude_paths', trim($form_state
      ->getValue('auditfiles_exclude_paths')))
      ->set('auditfiles_include_domains', trim($form_state
      ->getValue('auditfiles_include_domains')))
      ->set('auditfiles_report_options_items_per_page', trim($form_state
      ->getValue('auditfiles_report_options_items_per_page')))
      ->set('auditfiles_report_options_maximum_records', trim($form_state
      ->getValue('auditfiles_report_options_maximum_records')))
      ->set('auditfiles_report_options_date_format', trim($form_state
      ->getValue('auditfiles_report_options_date_format')))
      ->save();
    parent::submitForm($form, $form_state);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AuditFilesConfig::$streamWrapperManager protected property The Stream Wrapper Manager service.
AuditFilesConfig::buildForm public function Create form for configurations. Overrides ConfigFormBase::buildForm
AuditFilesConfig::create public static function Instantiates a new instance of this class. Overrides ConfigFormBase::create
AuditFilesConfig::getEditableConfigNames protected function Create configurations Name. Overrides ConfigFormBaseTrait::getEditableConfigNames
AuditFilesConfig::getFormId public function Widget Id. Overrides FormInterface::getFormId
AuditFilesConfig::submitForm public function Submit popup after login configurations. Overrides ConfigFormBase::submitForm
AuditFilesConfig::__construct public function Class constructor. Overrides ConfigFormBase::__construct
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 62
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.