66use Drupal \Core \Form \FormBase ;
77use Drupal \Core \Form \FormStateInterface ;
88use Drupal \Core \Url ;
9+ use Symfony \Component \DependencyInjection \ContainerInterface ;
10+ use Drupal \Core \Database \Connection ;
911
1012/**
1113 * Implements an assignment form.
1214 */
1315class AssignmentDatesForm extends FormBase {
1416
17+ /**
18+ * The database connection.
19+ *
20+ * @var \Drupal\Core\Database\Connection
21+ */
22+ protected $ database ;
23+
24+ /**
25+ * Constructs a assignment form object.
26+ *
27+ * @param \Drupal\Core\Database\Connection $database
28+ * The database connection.
29+ */
30+ public function __construct (Connection $ database ) {
31+ $ this ->database = $ database ;
32+ }
33+
34+ /**
35+ * {@inheritdoc}
36+ */
37+ public static function create (ContainerInterface $ container ) {
38+ return new static (
39+ $ container ->get ('database ' )
40+ );
41+ }
42+
1543 /**
1644 * {@inheritdoc}
1745 */
@@ -36,13 +64,11 @@ public function buildForm(array $form, FormStateInterface $form_state) {
3664 ];
3765
3866 // For php >8.1.
39- // phpcs:ignore -- \Drupal calls should be avoided in classes, use dependency injection instead
40- if (!isset (\Drupal::database ()->getConnectionOptions ()['prefix ' ])) {
67+ if (!isset ($ this ->database ->getConnectionOptions ()['prefix ' ])) {
4168 return $ form ;
4269 }
4370
44- // phpcs:ignore -- \Drupal calls should be avoided in classes, use dependency injection instead
45- $ prf = \Drupal::database ()->getConnectionOptions ()['prefix ' ];
71+ $ prf = $ this ->database ->getConnectionOptions ()['prefix ' ];
4672 $ node = $ prf . 'node ' ;
4773 $ node_field_data = $ prf . 'node_field_data ' ;
4874 $ conn = Database::getConnection ();
0 commit comments