library_manager-8.x-1.0/src/Form/SettingsForm.php
src/Form/SettingsForm.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | <?php namespace Drupal\library_manager\Form; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\library_manager\LibraryDiscoveryInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Library manager settings form. */ class SettingsForm extends ConfigFormBase { /** * The library discovery service. * * @var \Drupal\library_manager\LibraryDiscoveryInterface */ protected $libraryDiscovery ; /** * Constructs the form object. * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The factory for configuration objects. * @param \Drupal\library_manager\LibraryDiscoveryInterface $library_discovery * The discovery service. */ public function __construct(ConfigFactoryInterface $config_factory , LibraryDiscoveryInterface $library_discovery ) { parent::__construct( $config_factory ); $this ->libraryDiscovery = $library_discovery ; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container ) { return new static ( $container ->get( 'config.factory' ), $container ->get( 'library_manager.library_discovery' ) ); } /** * {@inheritdoc} */ public function getFormId() { return 'library_manager_settings' ; } /** * {@inheritdoc} */ protected function getEditableConfigNames() { return [ 'library_manager.settings' ]; } /** * {@inheritdoc} */ public function buildForm( array $form , FormStateInterface $form_state ) { $settings = $this ->config( 'library_manager.settings' )->get(); $form [ 'libraries_path' ] = [ '#type' => 'textfield' , '#title' => $this ->t( 'Libraries path' ), '#name' => 'file_public_path' , '#description' => $this ->t( 'A local file system path where library files will be stored. This directory should be accessible over the web.' ), '#after_build' => [ 'system_check_directory' ], '#default_value' => $settings [ 'libraries_path' ], ]; return parent::buildForm( $form , $form_state ); } /** * {@inheritdoc} */ public function submitForm( array & $form , FormStateInterface $form_state ) { $this ->config( 'library_manager.settings' ) ->set( 'libraries_path' , $form_state ->getValue( 'libraries_path' )) ->save(); $this ->libraryDiscovery->clearCachedDefinitions(); parent::submitForm( $form , $form_state ); } } |