Skip to content
Snippets Groups Projects

Issue #3329641: Drupal Coding Standards Issues | phpcs

Open Charchil Khandelwal requested to merge issue/quicklink-3329641:2.0.x into 2.0.x
5 files
+ 39
31
Compare changes
  • Side-by-side
  • Inline
Files
5
@@ -2,14 +2,14 @@
namespace Drupal\quicklink\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class QuicklinkConfig.
* Provide a configuration form for administrators.
*/
class QuicklinkConfigForm extends ConfigFormBase {
@@ -59,20 +59,23 @@ class QuicklinkConfigForm extends ConfigFormBase {
return 'quicklink_config';
}
/**
* The validateForm method for the QuicklinkConfigForm.
*/
public function quicklink_config_form_validate($form, &$form_state) {
$parameterFieldsToValidate = array(
$parameterFieldsToValidate = [
'total_request_limit',
'concurrency_throttle_limit',
'viewport_delay',
'idle_wait_timeout',
);
];
foreach ($parameterFieldsToValidate as $value) {
$formValue = $form_state['values'][$value];
if ($formValue !== '' && (!is_numeric($formValue) || intval($formValue) != $formValue || $formValue < 0)) {
form_set_error($value, t('%name must be a positive integer or zero.', array(
form_set_error($value, $this->t('%name must be a positive integer or zero.', [
'%name' => $form['throttle_options'][$value]['#title'],
)));
]));
}
}
}
@@ -203,14 +206,14 @@ class QuicklinkConfigForm extends ConfigFormBase {
// Parameters tab.
$form['throttle_options'] = [
'#type' => 'details',
'#title' => t('Throttle Options'),
'#description' => t('On this tab, set parameters to adjust how Quicklink loads content.'),
'#title' => $this->t('Throttle Options'),
'#description' => $this->t('On this tab, set parameters to adjust how Quicklink loads content.'),
'#group' => 'settings',
];
$form['throttle_options']['total_request_limit'] = [
'#type' => 'number',
'#title' => t('Set request limit'),
'#description' => t('Enter the total number of requests that can be
'#title' => $this->t('Set request limit'),
'#description' => $this->t('Enter the total number of requests that can be
prefetched for a given page. Set to 0 for unlimited. <br><em>Warning</em>: this may not
work when Concurrency Throttle is also enabled (see
<a href="https://github.com/GoogleChromeLabs/quicklink/issues/235">https://github.com/GoogleChromeLabs/quicklink/issues/235</a>.'),
@@ -220,32 +223,32 @@ class QuicklinkConfigForm extends ConfigFormBase {
];
$form['throttle_options']['concurrency_throttle_limit'] = [
'#type' => 'number',
'#title' => t('Set concurrency throttle'),
'#description' => t('Enter a limit for the simultaneous requests that can be made while prefetching. Set to 0 for unlimited.'),
'#title' => $this->t('Set concurrency throttle'),
'#description' => $this->t('Enter a limit for the simultaneous requests that can be made while prefetching. Set to 0 for unlimited.'),
'#maxlength' => 10,
'#size' => 10,
'#default_value' => $config->get('concurrency_throttle_limit', 0),
];
$form['throttle_options']['viewport_delay'] = [
'#type' => 'number',
'#title' => t('Viewport Delay'),
'#field_suffix' => t('ms'),
'#description' => t('Amount of time each link needs to stay inside the viewport before being prefetched. Default is 0 ms.'),
'#title' => $this->t('Viewport Delay'),
'#field_suffix' => $this->t('ms'),
'#description' => $this->t('Amount of time each link needs to stay inside the viewport before being prefetched. Default is 0 ms.'),
'#maxlength' => 10,
'#size' => 10,
'#default_value' => $config->get('viewport_delay', 0),
];
$form['throttle_options']['idle_wait_timeout'] = [
'#type' => 'number',
'#title' => t('Set idle timeout value'),
'#field_suffix' => t('ms'),
'#description' => t('Amount of time the browser must be idle before prefetching, in milliseconds. Default is 2000 ms.'),
'#title' => $this->t('Set idle timeout value'),
'#field_suffix' => $this->t('ms'),
'#description' => $this->t('Amount of time the browser must be idle before prefetching, in milliseconds. Default is 2000 ms.'),
'#maxlength' => 10,
'#size' => 10,
'#default_value' => $config->get('idle_wait_timeout', 2000),
];
// Prefetch Paths Only Tab
// Prefetch Paths Only Tab.
$form['paths_only'] = [
'#type' => 'details',
'#title' => $this->t('Prefetch Paths Only'),
@@ -311,19 +314,19 @@ class QuicklinkConfigForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$parameterFieldsToValidate = array(
$parameterFieldsToValidate = [
'total_request_limit',
'concurrency_throttle_limit',
'viewport_delay',
'idle_wait_timeout',
);
];
foreach ($parameterFieldsToValidate as $value) {
$formValue = $form_state->getValues()[$value];
if ($formValue !== '' && (!is_numeric($formValue) || intval($formValue) != $formValue || $formValue < 0 || $formValue < '')) {
$form_state->setErrorByName($value, t('%name must be a positive integer or zero.', array(
$form_state->setErrorByName($value, $this->t('%name must be a positive integer or zero.', [
'%name' => $form['throttle_options'][$value]['#title'],
)));
]));
}
}
parent::validateForm($form, $form_state);
Loading