public BanAdmin::buildForm(array $form, FormStateInterface $form_state, $default_ip = '')
Parameters
string $default_ip: (optional) IP address to be passed on to \Drupal::formBuilder()->getForm() for use as the default value of the IP address form field.
Overrides FormInterface::buildForm
File
- core/modules/ban/src/Form/BanAdmin.php, line 54
Class
- BanAdmin
- Displays banned IP addresses.
Namespace
Drupal\ban\Form
Code
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 | public function buildForm( array $form , FormStateInterface $form_state , $default_ip = '' ) { $rows = array (); $header = array ( $this ->t( 'banned IP addresses' ), $this ->t( 'Operations' )); $result = $this ->ipManager->findAll(); foreach ( $result as $ip ) { $row = array (); $row [] = $ip ->ip; $links = array (); $links [ 'delete' ] = array ( 'title' => $this ->t( 'Delete' ), 'url' => Url::fromRoute( 'ban.delete' , [ 'ban_id' => $ip ->iid]), ); $row [] = array ( 'data' => array ( '#type' => 'operations' , '#links' => $links , ), ); $rows [] = $row ; } $form [ 'ip' ] = array ( '#title' => $this ->t( 'IP address' ), '#type' => 'textfield' , '#size' => 48, '#maxlength' => 40, '#default_value' => $default_ip , '#description' => $this ->t( 'Enter a valid IP address.' ), ); $form [ 'actions' ] = array ( '#type' => 'actions' ); $form [ 'actions' ][ 'submit' ] = array ( '#type' => 'submit' , '#value' => $this ->t( 'Add' ), ); $form [ 'ban_ip_banning_table' ] = array ( '#type' => 'table' , '#header' => $header , '#rows' => $rows , '#empty' => $this ->t( 'No blocked IP addresses available.' ), '#weight' => 120, ); return $form ; } |
Please login to continue.