public function HostForm::buildForm in http:BL 8
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides EntityForm::buildForm
File
- src/
Form/ HostForm.php, line 69
Class
- HostForm
- Form controller for the host entity Add/Edit form.
Namespace
Drupal\httpbl\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
/* @var $entity \Drupal\httpbl\Entity\Host */
$form = parent::buildForm($form, $form_state);
$entity = $this->entity;
$form['langcode'] = array(
'#title' => $this
->t('Language'),
'#type' => 'language_select',
'#default_value' => $entity
->getUntranslated()
->language()
->getId(),
'#languages' => Language::STATE_ALL,
);
$form['edit'] = array(
'#type' => 'details',
'#title' => t('Edit Http:BL Host'),
'#description' => t('Add / Edit an Http:BL host.'),
'#open' => TRUE,
);
$form['edit']['host_ip'] = array(
'#title' => $this
->t('Host IP'),
'#type' => 'textfield',
'#size' => 15,
'#default_value' => $entity->host_ip->value,
'#maxlength' => 15,
'#required' => TRUE,
);
// Get the expiry offset variables and prepare expiration values.
$safeOffset = \Drupal::state()
->get('httpbl.safe_offset');
$greyOffset = \Drupal::state()
->get('httpbl.greylist_offset');
$blackOffset = \Drupal::state()
->get('httpbl.blacklist_offset');
$safeExpires = \Drupal::service('date.formatter')
->formatTimeDiffUntil($safeOffset + \Drupal::time()
->getRequestTime());
$greyExpires = \Drupal::service('date.formatter')
->formatTimeDiffUntil($greyOffset + \Drupal::time()
->getRequestTime());
$blackExpires = \Drupal::service('date.formatter')
->formatTimeDiffUntil($blackOffset + \Drupal::time()
->getRequestTime());
// Show the current expiration options associated with each status.
$form['edit']['host_status'] = array(
'#title' => $this
->t('Host Status'),
'#type' => 'select',
'#options' => [
0 => $this
->t('White-listed - Expires in ' . $safeExpires),
2 => $this
->t('Grey-listed - Expires in ' . $greyExpires),
1 => $this
->t('Blacklisted - Expires in ' . $blackExpires),
],
'#default_value' => $entity->host_status->value,
'#description' => $this
->t('Uses expiry times configured in here.'),
'#required' => TRUE,
);
// Advise the user on current state of storage settings.
if ($storage = \Drupal::state()
->get('httpbl.storage') == HTTPBL_DB_HH_DRUPAL) {
$form['edit']['explain_auto'] = array(
'#title' => $this
->t('Auto-banning is enabled for Blacklisted hosts. Blacklisting a host will add it to core Ban_ip.'),
'#type' => 'item',
);
}
else {
$form['edit']['explain_auto'] = array(
'#title' => $this
->t('Auto banning is NOT enabled for blacklisted hosts.'),
'#type' => 'item',
);
}
return $form;
}