예제 #1
0
 /**
  * Test load by multiple key ids.
  *
  * @group key
  * @dataProvider getKeysProvider
  */
 public function testGetKeys(array $key_ids, array $keys)
 {
     // Mock the loadMultiple to return results per the behavior documented in
     // \Drupal\Core\Entity\EntityStorageBase::loadMultiple().
     $this->configStorage->expects($this->any())->method('loadMultiple')->with($key_ids)->willReturn($keys);
     // Assert that the array count is the same for the scenario provided by the
     // data provider above.
     $entities = $this->keyManager->getKeys($key_ids);
     $this->assertEquals(count($keys), count($entities));
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $config = $this->config('encrypt.settings');
     $keys = [];
     foreach ($this->key_manager->getKeys() as $key) {
         $key_id = $key->id();
         $key_title = $key->label();
         $keys[$key_id] = (string) $key_title;
     }
     $form['encryption_key'] = array('#type' => 'select', '#title' => $this->t('Encryption Key'), '#description' => $this->t('Select the key used for encryption'), '#options' => $keys, '#default_value' => $config->get('encryption_key'));
     $enc_methods = [];
     foreach ($this->encrypt_service->loadEncryptionMethods() as $plugin_id => $definition) {
         $enc_methods[$plugin_id] = (string) $definition['title'];
     }
     $form['encryption_method'] = array('#type' => 'select', '#title' => $this->t('Encryption Method'), '#description' => $this->t('Select the method used for encryption'), '#options' => $enc_methods, '#default_value' => $config->get('encryption_method'));
     return parent::buildForm($form, $form_state);
 }