You are here

protected function FormAssemblyEntitySettingsForm::buildProviderOptions in FormAssembly 8

Helper method to build the credential provider elements of the form.

Parameters

array $form: The configuration form.

1 call to FormAssemblyEntitySettingsForm::buildProviderOptions()
FormAssemblyEntitySettingsForm::buildForm in src/Form/FormAssemblyEntitySettingsForm.php
Defines the settings form for FormAssembly Form entities.

File

src/Form/FormAssemblyEntitySettingsForm.php, line 231

Class

FormAssemblyEntitySettingsForm
FormAssembly entity settings form.

Namespace

Drupal\formassembly\Form

Code

protected function buildProviderOptions(array &$form) {
  $credentials = $this->formassemblyConfig
    ->get('credentials');

  // Provide selectors for the api key credential provider.
  $form['credentials']['provider'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Credential provider'),
    '#default_value' => empty($credentials['provider']) ? 'formassembly' : $credentials['provider'],
    '#options' => [
      'formassembly' => 'FormAssembly Configuration',
      'key' => 'Key Module',
    ],
    '#attributes' => [
      'data-states-selector' => 'provider',
    ],
  ];
  $formassembly_state = [
    'required' => [
      ':input[data-states-selector="provider"]' => [
        'value' => 'formassembly',
      ],
    ],
    'visible' => [
      ':input[data-states-selector="provider"]' => [
        'value' => 'formassembly',
      ],
    ],
    'enabled' => [
      ':input[data-states-selector="provider"]' => [
        'value' => 'formassembly',
      ],
    ],
  ];
  $form['credentials']['cid']['#states'] = $formassembly_state;
  $form['credentials']['secret']['#states'] = $formassembly_state;
  $key_id = isset($credentials['data']['id']) ? $credentials['data']['id'] : '';
  $form['credentials']['id'] = [
    '#type' => 'key_select',
    '#title' => $this
      ->t('Select a Stored Key'),
    '#description' => $this
      ->t('Select the key you have configured to hold the Oauth Client ID and Secret.'),
    '#default_value' => $key_id,
    '#empty_option' => $this
      ->t('- Please select -'),
    '#key_filters' => [
      'type' => 'formassembly_oauth',
    ],
    '#states' => [
      'required' => [
        ':input[data-states-selector="provider"]' => [
          'value' => 'key',
        ],
      ],
      'visible' => [
        ':input[data-states-selector="provider"]' => [
          'value' => 'key',
        ],
      ],
      'enabled' => [
        ':input[data-states-selector="provider"]' => [
          'value' => 'key',
        ],
      ],
    ],
  ];
}