Skip to content
Snippets Groups Projects

3356277-fix-phpcs-issue: Resolve phpcs issues.

3 files
+ 150
54
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -2,15 +2,54 @@
namespace Drupal\password_notification\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Delete Password Changed History.
*/
class PasswordChangedHistoryDeleteForm extends FormBase {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
/**
* The configuration factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Constructs a PasswordChangedHistoryDeleteForm object.
*
* @param \Drupal\Core\Database\Connection $database
* The database connection.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory.
*/
public function __construct(Connection $database, ConfigFactoryInterface $config_factory) {
$this->database = $database;
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('database'),
$container->get('config.factory')
);
}
/**
* {@inheritdoc}
*/
@@ -26,7 +65,7 @@ class PasswordChangedHistoryDeleteForm extends FormBase {
$record_exist = FALSE;
// Get Records Count.
$db = \Drupal::database();
$db = $this->database;
$get_result_count = $db->select('password_changed_history', 'p')
->fields('p', ['id'])
->countQuery()
@@ -42,7 +81,7 @@ class PasswordChangedHistoryDeleteForm extends FormBase {
if ($record_exist == TRUE) {
$form['submit'] = [
'#type' => 'submit',
'#value' => t('Delete Records'),
'#value' => $this->t('Delete Records'),
];
$form['help_text'] = [
'#markup' => '<div>Note: By Default Delete Records Limit is 1000. To Update Limit go to and Update the Limit.</div>',
@@ -55,10 +94,9 @@ class PasswordChangedHistoryDeleteForm extends FormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = \Drupal::config('password_notification.settings');
$config = $this->configFactory->get('password_notification.settings');
$limit = $config->get('delete_records_limit');
$db = \Drupal::database();
$db = $this->database;
$query = $db->select('password_changed_history', 'p');
$query->fields('p', ['id']);
$query->range(0, $limit);
@@ -70,11 +108,11 @@ class PasswordChangedHistoryDeleteForm extends FormBase {
];
}
$batch = [
'title' => t('Batch Operation'),
'title' => $this->t('Batch Operation'),
'operations' => $operations,
'init_message' => t('Batch Operation starting...'),
'progress_message' => t('Processed @current out of @total.'),
'error_message' => t('Fix has encountered an error.'),
'init_message' => $this->t('Batch Operation starting...'),
'progress_message' => $this->t('Processed @current out of @total.'),
'error_message' => $this->t('Fix has encountered an error.'),
'finished' => $this->finishedCallback(),
];
batch_set($batch);
@@ -84,7 +122,7 @@ class PasswordChangedHistoryDeleteForm extends FormBase {
* Batch Operation Callback.
*/
public function batchFunction($id) {
$db = \Drupal::database();
$db = $this->database;
$db->delete('password_changed_history')
->condition('id', $id, '=')
->execute();
@@ -94,7 +132,7 @@ class PasswordChangedHistoryDeleteForm extends FormBase {
* Batch Operation Finished Callback..
*/
public function finishedCallback() {
drupal_set_message('Delete Process Completed.');
drupal_set_message($this->t('Delete Process Completed.'));
}
}
Loading