You are here

private function AuthorizationProfileForm::buildConditionsForm in Authorization 8

Build the conditions form.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

1 call to AuthorizationProfileForm::buildConditionsForm()
AuthorizationProfileForm::form in src/Form/AuthorizationProfileForm.php
Gets the actual form array to be built.

File

src/Form/AuthorizationProfileForm.php, line 431

Class

AuthorizationProfileForm
Authorization profile form.

Namespace

Drupal\authorization\Form

Code

private function buildConditionsForm(array &$form, FormStateInterface $form_state) : void {
  $authorization_profile = $this
    ->getEntity();
  if (!$authorization_profile
    ->hasValidProvider() || !$authorization_profile
    ->hasValidConsumer()) {
    return;
  }
  if (!property_exists($this, 'provider') || !$this->provider) {
    $this->provider = $authorization_profile
      ->getProvider();
  }
  if (!property_exists($this, 'consumer') || !$this->consumer) {
    $this->consumer = $authorization_profile
      ->getConsumer();
  }
  $tokens = [];
  $tokens += $authorization_profile
    ->getProvider()
    ->getTokens();
  $tokens += $authorization_profile
    ->getConsumer()
    ->getTokens();
  $form['conditions'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Configure conditions'),
    '#open' => TRUE,
  ];
  $synchronization_modes = [];
  if ($this->provider
    ->isSyncOnLogonSupported()) {
    $synchronization_modes['user_logon'] = $this
      ->t('When a user logs on via <em>@provider_name</em>.', $tokens);
  }
  $form['conditions']['synchronization_modes'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('When should <em>@consumer_name</em> be granted/revoked from a user?', $tokens),
    '#options' => $synchronization_modes,
    '#default_value' => $authorization_profile
      ->get('synchronization_modes') ? $authorization_profile
      ->get('synchronization_modes') : [],
    '#description' => '',
  ];
  $synchronization_actions = [];
  if ($this->provider
    ->revocationSupported()) {
    $synchronization_actions['revoke_provider_provisioned'] = $this
      ->t('Revoke <em>@consumer_name</em> grants previously granted by <em>@provider_name</em> in this profile.', $tokens);
  }
  if ($this->consumer
    ->consumerTargetCreationAllowed()) {
    $synchronization_actions['create_consumers'] = $this
      ->t('Create <em>@consumer_name</em> targets if they do not exist.', $tokens);
  }
  $form['conditions']['synchronization_actions'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('What actions would you like performed when <em>@consumer_name</em> are granted/revoked from a user?', $tokens),
    '#options' => $synchronization_actions,
    '#default_value' => $authorization_profile
      ->get('synchronization_actions') ? $authorization_profile
      ->get('synchronization_actions') : [],
  ];
}