You are here

function fontscom_api_form_font_settings_alter in @font-your-face 8.3

Implements hook_form_alter().

File

modules/fontscom_api/fontscom_api.module, line 80
Fonts.com API module file.

Code

function fontscom_api_form_font_settings_alter(&$form, FormStateInterface $form_state) {
  $config = \Drupal::config('fontscom_api.settings');
  $form['fontscom_api'] = [
    '#type' => 'fieldset',
    '#title' => t('FONTS.COM SETTINGS'),
  ];
  $form['fontscom_api']['fontscom_api_token'] = [
    '#type' => 'textfield',
    '#title' => t('Fonts.com Authentication Key'),
    '#description' => t('Add your Fonts.com authentication key to import your projects. Available at <a target="_blank" href=":url">:url</a>', [
      ':url' => 'https://www.fonts.com/account#authentification-section',
    ]),
    '#default_value' => $config
      ->get('token'),
  ];
  if (!empty($config
    ->get('token'))) {
    $projects = fontscom_api_get_projects();
    if (count($projects) > 0) {
      $options = [
        '' => '-- Select a project --',
      ];
      foreach ($projects as $key => $project) {
        $options[$project->ProjectKey] = Html::escape($project->ProjectName);
      }
      $form['fontscom_api']['fontscom_api_project'] = [
        '#type' => 'select',
        '#title' => t('Project'),
        '#options' => $options,
        '#default_value' => $config
          ->get('project'),
        '#required' => TRUE,
      ];
    }
  }
  $form['#submit'][] = 'fontscom_api_form_font_settings_submit';
}