foldershare-8.x-1.2/src/Form/AdminSettings.php
src/Form/AdminSettings.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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | <?php namespace Drupal\foldershare\Form; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\foldershare\Constants; /** * Creates a form to adjust the module's configuration. * * The module configuration form is intended for administrators. It enables * changes to how files are stored, uploaded, and accessed. It also provides * configuration reset forms and links to related forms. * * <B>Internal class</B> * This class is internal to the FolderShare module. The class's existance, * name, and content may change from release to release without any promise * of backwards compatability. * * <B>Access control</B> * The route to this form should restrict access to those with administration * administration permission. * * @ingroup foldershare */ final class AdminSettings extends ConfigFormBase { use AdminSettingsTraits\AdminSettingsAboutTab; use AdminSettingsTraits\AdminSettingsFilesTab; use AdminSettingsTraits\AdminSettingsInterfaceTab; use AdminSettingsTraits\AdminSettingsServicesTab; /*-------------------------------------------------------------------- * * Fields - dependency injection. * *--------------------------------------------------------------------*/ /** * The module handler, set at construction time. * * @var \Drupal\Core\Extension\ModuleHandlerInterface */ protected $moduleHandler ; /*-------------------------------------------------------------------- * * Construction. * *--------------------------------------------------------------------*/ /** * Constructs a new form. * * @param Drupal\Core\Config\ConfigFactoryInterface $configFactory * The configuration factory. * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler * The module handler. */ public function __construct( ConfigFactoryInterface $configFactory , ModuleHandlerInterface $moduleHandler ) { parent::__construct( $configFactory ); $this ->moduleHandler = $moduleHandler ; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container ) { return new static ( $container ->get( 'config.factory' ), $container ->get( 'module_handler' ) ); } /*--------------------------------------------------------------------- * * Form interface. * *---------------------------------------------------------------------*/ /** * {@inheritdoc} */ public function getFormId() { return str_replace ( '\\' , '_' , get_class( $this )); } /** * {@inheritdoc} */ protected function getEditableConfigNames() { return [Constants::SETTINGS]; } /*--------------------------------------------------------------------- * * Build form. * *---------------------------------------------------------------------*/ /** * Builds a form to adjust the module configuration. * * The form has multiple vertical tabs, each built by a separate function. * * @param array $form * An associative array containing the renderable structure of the form. * @param \Drupal\Core\Form\FormStateInterface $formState * (optional) The current state of the form. * * @return array * The form renderable array. */ public function buildForm( array $form , FormStateInterface $formState = NULL) { // // Vertical tabs // ------------- // Setup vertical tabs. For these to work, all of the children // must be of type 'details' and refer to the 'tabs' group. $form [ 'tabs' ] = [ '#type' => 'vertical_tabs' , '#attached' => [ 'library' => [ Constants::LIBRARY_MODULE, Constants::LIBRARY_ADMIN, ], ], ]; // Create each of the tabs. $this ->buildAboutTab( $form , $formState , 'tabs' ); $this ->buildFilesTab( $form , $formState , 'tabs' ); $this ->buildInterfaceTab( $form , $formState , 'tabs' ); $this ->buildServicesTab( $form , $formState , 'tabs' ); // Build and return the form. return parent::buildForm( $form , $formState ); } /*--------------------------------------------------------------------- * * Validate. * *---------------------------------------------------------------------*/ /** * Validates the form values. * * @param array $form * The form configuration. * @param \Drupal\Core\Form\FormStateInterface $formState * The entered values for the form. */ public function validateForm( array & $form , FormStateInterface $formState ) { parent::validateForm( $form , $formState ); $this ->validateAboutTab( $form , $formState ); $this ->validateFilesTab( $form , $formState ); $this ->validateInterfaceTab( $form , $formState ); $this ->validateServicesTab( $form , $formState ); } /*--------------------------------------------------------------------- * * Submit. * *---------------------------------------------------------------------*/ /** * Stores the submitted form values. * * @param array $form * The form configuration. * @param \Drupal\Core\Form\FormStateInterface $formState * The entered values for the form. */ public function submitForm( array & $form , FormStateInterface $formState ) { parent::submitForm( $form , $formState ); $this ->submitAboutTab( $form , $formState ); $this ->submitFilesTab( $form , $formState ); $this ->submitInterfaceTab( $form , $formState ); $this ->submitServicesTab( $form , $formState ); } /*--------------------------------------------------------------------- * * Utilities. * *---------------------------------------------------------------------*/ /** * Returns a lower case CSS-friendly version of a string. * * The string is converted to lower case. White space is replaced with * dashes. Punctuation characters are removed. * * @param string $str * The string to convert. * * @return string * The converted string. */ private static function makeCssSafe(string $str ) { $str = mb_convert_case( $str , MB_CASE_LOWER); $str = preg_replace( '/[[:space:]]+/' , '-' , $str ); return preg_replace( '/[^-_[:alnum:]]+/' , '' , $str ); } } |