/**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $form = parent::form($form, $form_state);
     $keys = $this->key_repository->getKeys();
     if (empty($keys)) {
         drupal_set_message('No system keys (admin/config/system/key) are installed to manage encryption profiles.');
     }
     /** @var $encryption_profile \Drupal\encrypt\Entity\EncryptionProfile */
     $encryption_profile = $this->entity;
     $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $encryption_profile->label(), '#description' => $this->t("Label for the encryption profile."), '#required' => TRUE);
     $form['id'] = array('#type' => 'machine_name', '#default_value' => $encryption_profile->id(), '#machine_name' => array('exists' => '\\Drupal\\encrypt\\Entity\\EncryptionProfile::load'), '#disabled' => !$encryption_profile->isNew());
     /** @var $key \Drupal\key\Entity\KeyInterface */
     foreach ($keys as $key) {
         $key_id = $key->id();
         $key_title = $key->label();
         $keys[$key_id] = (string) $key_title;
     }
     if ($profile_key = $encryption_profile->getEncryptionKey()) {
         $default_key = $profile_key;
     }
     $form['encryption_key'] = array('#type' => 'select', '#title' => $this->t('Encryption Key'), '#description' => $this->t('Select the key used for encryption.'), '#options' => $keys, '#default_value' => empty($default_key) ? NULL : $default_key, '#required' => TRUE);
     $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' => $encryption_profile->getEncryptionMethod());
     return $form;
 }
示例#2
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->keyRepository->getKeys($key_ids);
     $this->assertEquals(count($keys), count($entities));
 }