class FileSystemForm

Same name in other branches
  1. 9 core/modules/system/src/Form/FileSystemForm.php \Drupal\system\Form\FileSystemForm
  2. 8.9.x core/modules/system/src/Form/FileSystemForm.php \Drupal\system\Form\FileSystemForm
  3. 10 core/modules/system/src/Form/FileSystemForm.php \Drupal\system\Form\FileSystemForm

Configure file system settings for this site.

@internal

Hierarchy

Expanded class hierarchy of FileSystemForm

1 string reference to 'FileSystemForm'
system.routing.yml in core/modules/system/system.routing.yml
core/modules/system/system.routing.yml

File

core/modules/system/src/Form/FileSystemForm.php, line 24

Namespace

Drupal\system\Form
View source
class FileSystemForm extends ConfigFormBase {
    use RedundantEditableConfigNamesTrait;
    
    /**
     * The date formatter service.
     *
     * @var \Drupal\Core\Datetime\DateFormatterInterface
     */
    protected $dateFormatter;
    
    /**
     * The stream wrapper manager.
     *
     * @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface
     */
    protected $streamWrapperManager;
    
    /**
     * The file system.
     *
     * @var \Drupal\Core\File\FileSystemInterface
     */
    protected $fileSystem;
    
    /**
     * Constructs a FileSystemForm object.
     *
     * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
     *   The factory for configuration objects.
     * @param \Drupal\Core\Config\TypedConfigManagerInterface $typedConfigManager
     *   The typed config manager.
     * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
     *   The date formatter service.
     * @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager
     *   The stream wrapper manager.
     * @param \Drupal\Core\File\FileSystemInterface $file_system
     *   The file system.
     */
    public function __construct(ConfigFactoryInterface $config_factory, TypedConfigManagerInterface $typedConfigManager, DateFormatterInterface $date_formatter, StreamWrapperManagerInterface $stream_wrapper_manager, FileSystemInterface $file_system) {
        parent::__construct($config_factory, $typedConfigManager);
        $this->dateFormatter = $date_formatter;
        $this->streamWrapperManager = $stream_wrapper_manager;
        $this->fileSystem = $file_system;
    }
    
    /**
     * {@inheritdoc}
     */
    public static function create(ContainerInterface $container) {
        return new static($container->get('config.factory'), $container->get('config.typed'), $container->get('date.formatter'), $container->get('stream_wrapper_manager'), $container->get('file_system'));
    }
    
    /**
     * {@inheritdoc}
     */
    public function getFormId() {
        return 'system_file_system_settings';
    }
    
    /**
     * {@inheritdoc}
     */
    public function buildForm(array $form, FormStateInterface $form_state) {
        $form['file_public_path'] = [
            '#type' => 'item',
            '#title' => $this->t('Public file system path'),
            '#markup' => PublicStream::basePath(),
            '#description' => $this->t('A local file system path where public files will be stored. This directory must exist and be writable by Drupal. This directory must be relative to the Drupal installation directory and be accessible over the web. This must be changed in settings.php'),
        ];
        $form['file_public_base_url'] = [
            '#type' => 'item',
            '#title' => $this->t('Public file base URL'),
            '#markup' => PublicStream::baseUrl(),
            '#description' => $this->t('The base URL that will be used for public file URLs. This can be changed in settings.php'),
        ];
        $form['file_assets_path'] = [
            '#type' => 'item',
            '#title' => $this->t('Optimized assets file system path'),
            '#markup' => AssetsStream::basePath(),
            '#description' => $this->t('A local file system path where optimized assets files will be stored. This directory must exist and be writable by Drupal. This directory must be relative to the Drupal installation directory and be accessible over the web. This must be changed in settings.php'),
        ];
        $form['file_private_path'] = [
            '#type' => 'item',
            '#title' => $this->t('Private file system path'),
            '#markup' => PrivateStream::basePath() ? PrivateStream::basePath() : $this->t('Not set'),
            '#description' => $this->t('An existing local file system path for storing private files. It should be writable by Drupal and not accessible over the web. This must be changed in settings.php'),
        ];
        $form['file_temporary_path'] = [
            '#type' => 'item',
            '#title' => $this->t('Temporary directory'),
            '#markup' => $this->fileSystem
                ->getTempDirectory(),
            '#description' => $this->t('A local file system path where temporary files will be stored. This directory should not be accessible over the web. This must be changed in settings.php.'),
        ];
        // Any visible, writable wrapper can potentially be used for the files
        // directory, including a remote file system that integrates with a CDN.
        $options = $this->streamWrapperManager
            ->getDescriptions(StreamWrapperInterface::WRITE_VISIBLE);
        if (!empty($options)) {
            $form['file_default_scheme'] = [
                '#type' => 'radios',
                '#title' => $this->t('Default download method'),
                '#config_target' => 'system.file:default_scheme',
                '#options' => $options,
                '#description' => $this->t('This setting is used as the preferred download method. The use of public files is more efficient, but does not provide any access control.'),
            ];
        }
        $intervals = [
            0,
            21600,
            43200,
            86400,
            604800,
            2419200,
            7776000,
        ];
        $period = array_combine($intervals, array_map([
            $this->dateFormatter,
            'formatInterval',
        ], $intervals));
        $period[0] = $this->t('Never');
        $form['temporary_maximum_age'] = [
            '#type' => 'select',
            '#title' => $this->t('Delete temporary files after'),
            '#config_target' => 'system.file:temporary_maximum_age',
            '#options' => $period,
            '#description' => $this->t('Temporary files are not referenced, but are in the file system and therefore may show up in administrative lists. <strong>Warning:</strong> If enabled, temporary files will be permanently deleted and may not be recoverable.'),
        ];
        return parent::buildForm($form, $form_state);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
ConfigFormBase::checkConfigOverrides public function Form #after_build callback: Adds message if overrides exist.
ConfigFormBase::CONFIG_KEY_TO_FORM_ELEMENT_MAP protected constant The $form_state key which stores a map of config keys to form elements.
ConfigFormBase::copyFormValuesToConfig private static function Copies form values to Config keys.
ConfigFormBase::doStoreConfigMap protected function Helper method for #after_build callback ::storeConfigKeyToFormElementMap().
ConfigFormBase::formatMultipleViolationsMessage protected function Formats multiple violation messages associated with a single form element. 1
ConfigFormBase::loadDefaultValuesFromConfig public function Process callback to recursively load default values from #config_target.
ConfigFormBase::storeConfigKeyToFormElementMap public function #after_build callback which stores a map of element names to config keys.
ConfigFormBase::submitForm public function Overrides FormInterface::submitForm 24
ConfigFormBase::typedConfigManager protected function Returns the typed config manager service.
ConfigFormBase::validateForm public function Overrides FormBase::validateForm 13
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FileSystemForm::$dateFormatter protected property The date formatter service.
FileSystemForm::$fileSystem protected property The file system.
FileSystemForm::$streamWrapperManager protected property The stream wrapper manager.
FileSystemForm::buildForm public function Overrides ConfigFormBase::buildForm
FileSystemForm::create public static function Overrides ConfigFormBase::create
FileSystemForm::getFormId public function Overrides FormInterface::getFormId
FileSystemForm::__construct public function Constructs a FileSystemForm object. Overrides ConfigFormBase::__construct
FormBase::$configFactory protected property The config factory. 2
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. 2
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user. 2
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.
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.
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. 16
MessengerTrait::messenger public function Gets the messenger. 16
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 2
RedirectDestinationTrait::getDestinationArray protected function Prepares a &#039;destination&#039; 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.
RedundantEditableConfigNamesTrait::getEditableConfigNames protected function Overrides ConfigFormBaseTrait::getEditableConfigNames
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
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.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.