You are here

public function SettingsForm::buildForm in Opigno Moxtra 3.x

Same name and namespace in other branches
  1. 8 src/Form/SettingsForm.php \Drupal\opigno_moxtra\Form\SettingsForm::buildForm()

Form constructor.

Parameters

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

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

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/SettingsForm.php, line 97

Class

SettingsForm
Implements the Opigno Moxtra settings form.

Namespace

Drupal\opigno_moxtra\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('opigno_moxtra.settings');
  $org_id = $config
    ->get('org_id');
  $form['content'] = [
    '#type' => 'container',
    '#attributes' => [
      'class' => [
        'row',
      ],
    ],
  ];
  $form['content']['left'] = [
    '#type' => 'container',
    '#attributes' => [
      'class' => [
        'col-4',
      ],
    ],
  ];
  $form['content']['right'] = [
    '#type' => 'container',
    '#attributes' => [
      'class' => [
        'col-8',
      ],
    ],
  ];
  $form['content']['right']['title'] = [
    '#type' => 'html_tag',
    '#tag' => 'h2',
    '#value' => $this
      ->t('Moxtra API Settings'),
  ];
  if (empty($org_id)) {
    $form['content']['left']['text'] = [
      '#type' => 'container',
      'text' => [
        '#markup' => $this
          ->t('You need to register on'),
      ],
    ];
    $renew_title = $this
      ->t('Moxtra');
    $renew_uri = 'https://moxtra.com/';
    $renew_url = Url::fromUri($renew_uri)
      ->setOptions([
      'target' => '_blank',
    ]);
    $renew = Link::fromTextAndUrl($renew_title, $renew_url)
      ->toRenderable();
    $form['content']['left']['renew'] = $renew;
  }
  else {
    $form['content']['left']['text'] = [
      '#type' => 'container',
      'text' => [
        '#markup' => $this
          ->t('Add all users to Moxtra'),
      ],
    ];
    $form['content']['left']['text']['add'] = [
      '#type' => 'submit',
      '#attributes' => [
        'name' => 'add',
      ],
      '#value' => $this
        ->t('Register all'),
      '#submit' => [
        [
          $this,
          'registerAllSubmit',
        ],
      ],
    ];
  }
  $form['content']['right']['info'] = [
    '#type' => 'container',
    '#attributes' => [
      'class' => [
        'moxtra-info',
        'col-8',
      ],
    ],
  ];
  $form['content']['right']['info']['moxtra_url'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Your Moxtra URL'),
    '#default_value' => $config
      ->get('url'),
    '#description' => $this
      ->t('Example: @url', [
      '@url' => 'https://opigno-dev.moxtra.com',
    ]),
  ];
  $form['content']['right']['info']['org_id'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Organization ID'),
    '#default_value' => $config
      ->get('org_id'),
  ];
  $form['content']['right']['info']['client_id'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Client ID'),
    '#default_value' => $config
      ->get('client_id'),
  ];
  $form['content']['right']['info']['client_secret'] = [
    '#type' => 'password',
    '#title' => $this
      ->t('Client Secret'),
    '#default_value' => $config
      ->get('client_secret'),
    '#post_render' => [
      [
        $this,
        'rebuildPass',
      ],
    ],
  ];
  $form['content']['right']['info']['moxtra_login'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Email'),
    '#default_value' => $config
      ->get('email'),
  ];
  $form['content']['right']['info']['agreement'] = [
    '#type' => 'checkbox',
    '#required' => TRUE,
    '#title' => $this
      ->t('I understand and expressly Consent to the transfer of the following data to Moxtra Inc., a company located in the United States of America : URL of my website, email address of the website administrator, name of the website, total number of users of the website and my username, ID and timezone'),
    '#wrapper_attributes' => [
      'class' => [
        'inline-checkbox',
      ],
    ],
    '#default_value' => $config
      ->get('agreement'),
  ];
  $form['content']['right']['info']['save'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save'),
    '#submit' => [
      [
        $this,
        'settingsSubmitForm',
      ],
    ],
  ];
  $form['#attached'] = [
    'library' => [
      'opigno_moxtra/settings_form',
    ],
  ];
  $form['#attached']['library'][] = 'opigno_moxtra/settings_form';
  $form['#attached']['library'][] = 'opigno_moxtra/moxtra.js';
  return $form;
}