|
1 | 1 | <?php |
2 | 2 |
|
3 | | -// phpcs:disable DrupalPractice.General.OptionsT.TforValue |
4 | | -// phpcs:disable DrupalPractice.Objects.GlobalDrupal.GlobalDrupal |
5 | | - |
6 | 3 | namespace Drupal\media_fits\Form; |
7 | 4 |
|
8 | 5 | use Drupal\Core\Form\ConfigFormBase; |
9 | 6 | use Drupal\Core\Form\FormStateInterface; |
| 7 | +use Drupal\Core\Config\ConfigFactoryInterface; |
| 8 | +use Drupal\Core\Entity\EntityFieldManagerInterface; |
| 9 | +use Drupal\Core\Entity\EntityTypeManagerInterface; |
| 10 | +use Symfony\Component\DependencyInjection\ContainerInterface; |
10 | 11 |
|
11 | 12 | /** |
12 | 13 | * Class MediaFitsConfigForm definition. |
13 | 14 | */ |
14 | 15 | class MediaFitsConfigForm extends ConfigFormBase { |
15 | 16 |
|
| 17 | + /** |
| 18 | + * The entity field manager service. |
| 19 | + * |
| 20 | + * @var \Drupal\Core\Entity\EntityFieldManagerInterface |
| 21 | + */ |
| 22 | + protected $entityFieldManager; |
| 23 | + |
| 24 | + /** |
| 25 | + * The entity type manager service. |
| 26 | + * |
| 27 | + * @var \Drupal\Core\Entity\EntityTypeManagerInterface |
| 28 | + */ |
| 29 | + protected $entityTypeManager; |
| 30 | + |
| 31 | + /** |
| 32 | + * Constructs a MediaFitsConfigForm object. |
| 33 | + * |
| 34 | + * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory |
| 35 | + * The config factory service. |
| 36 | + * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager |
| 37 | + * The entity field manager service. |
| 38 | + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager |
| 39 | + * The entity type manager service. |
| 40 | + */ |
| 41 | + public function __construct( |
| 42 | + ConfigFactoryInterface $config_factory, |
| 43 | + EntityFieldManagerInterface $entity_field_manager, |
| 44 | + EntityTypeManagerInterface $entity_type_manager, |
| 45 | + ) { |
| 46 | + parent::__construct($config_factory); |
| 47 | + $this->entityFieldManager = $entity_field_manager; |
| 48 | + $this->entityTypeManager = $entity_type_manager; |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * {@inheritdoc} |
| 53 | + */ |
| 54 | + public static function create(ContainerInterface $container) { |
| 55 | + return new static( |
| 56 | + $container->get('config.factory'), |
| 57 | + $container->get('entity_field.manager'), |
| 58 | + $container->get('entity_type.manager') |
| 59 | + ); |
| 60 | + } |
| 61 | + |
16 | 62 | /** |
17 | 63 | * {@inheritdoc} |
18 | 64 | */ |
@@ -51,9 +97,9 @@ public function buildForm(array $form, FormStateInterface $form_state) { |
51 | 97 | '#type' => 'select', |
52 | 98 | '#title' => 'Select Fits method:', |
53 | 99 | '#options' => [ |
54 | | - 0 => '-- Select --', |
55 | | - 'remote' => 'FITS Web Service', |
56 | | - 'local' => 'FITS from the command-line', |
| 100 | + 0 => $this->t('-- Select --'), |
| 101 | + 'remote' => $this->t('FITS Web Service'), |
| 102 | + 'local' => $this->t('FITS from the command-line'), |
57 | 103 | ], |
58 | 104 | '#required' => TRUE, |
59 | 105 | '#ajax' => [ |
@@ -100,7 +146,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { |
100 | 146 | ]; |
101 | 147 |
|
102 | 148 | $queues = ['0' => "-- Select --"]; |
103 | | - $queues = array_merge($queues, \Drupal::entityQuery('advancedqueue_queue')->execute()); |
| 149 | + $queues = array_merge($queues, $this->entityTypeManager->getStorage('advancedqueue_queue')->getQuery()->execute()); |
104 | 150 | $form['container']['fits-services-config']['op-config']['advancedqueue-id'] = [ |
105 | 151 | '#type' => 'select', |
106 | 152 | '#name' => 'advancedqueue-id', |
@@ -137,7 +183,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { |
137 | 183 | ]; |
138 | 184 |
|
139 | 185 | // Select default fits fields. |
140 | | - $field_map = \Drupal::service('entity_field.manager')->getFieldMap(); |
| 186 | + $field_map = $this->entityFieldManager->getFieldMap(); |
141 | 187 | $node_field_map = $field_map['file']; |
142 | 188 | $fields = array_keys($node_field_map); |
143 | 189 | $fits_fields = []; |
@@ -189,7 +235,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { |
189 | 235 | * Query existing File types. |
190 | 236 | */ |
191 | 237 | public function getFileTypes() { |
192 | | - $contentTypes = \Drupal::service('entity_type.manager')->getStorage('file_type')->loadMultiple(); |
| 238 | + $contentTypes = $this->entityTypeManager->getStorage('file_type')->loadMultiple(); |
193 | 239 | $types = []; |
194 | 240 | foreach ($contentTypes as $contentType) { |
195 | 241 | $types[$contentType->id()] = $contentType->label(); |
|
0 commit comments