You are here

public function SettingsForm::buildForm in Font Awesome Icons 8

Same name and namespace in other branches
  1. 8.2 src/Form/SettingsForm.php \Drupal\fontawesome\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 58

Class

SettingsForm
Defines a form that configures fontawesome settings.

Namespace

Drupal\fontawesome\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // Get current settings.
  $fontawesome_config = $this
    ->config('fontawesome.settings');

  // Load the fontawesome libraries so we can use its definitions here.
  $fontawesome_library = $this->libraryDiscovery
    ->getLibraryByName('fontawesome', 'fontawesome');
  $fontawesome_cdn_library = $this->libraryDiscovery
    ->getLibraryByName('fontawesome', 'fontawesome.cdn');
  $form['external'] = [
    '#type' => 'details',
    '#open' => TRUE,
    '#title' => $this
      ->t('External file configuration'),
    '#description' => $this
      ->t('These settings control the method by which the Font Awesome library is loaded. You can choose to use an external library by selecting a URL below, or you can use a local version of the file by leaving the box unchecked and downloading the library <a href=":remoteurl">:remoteurl</a> and installing locally at %installpath.', [
      ':remoteurl' => $fontawesome_library['remote'],
      '%installpath' => '/libraries',
    ]),
    'fontawesome_use_cdn' => [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Use external file?'),
      '#description' => $this
        ->t('Checking this box will cause the Font Awesome library to be loaded externally rather than from the local library file.'),
      '#default_value' => $fontawesome_config
        ->get('fontawesome_use_cdn'),
    ],
    'fontawesome_external_location' => [
      '#type' => 'textfield',
      '#title' => $this
        ->t('External Library Location'),
      '#default_value' => empty($fontawesome_config
        ->get('fontawesome_external_location')) ? $fontawesome_cdn_library['css'][0]['data'] : $fontawesome_config
        ->get('fontawesome_external_location'),
      '#size' => 80,
      '#description' => $this
        ->t('Enter a source URL for the external Font Awesome library you wish to use. This URL should point to the Font Awesome CSS file. Leave blank to use the default Font Awesome CDN.'),
      '#states' => [
        'disabled' => [
          ':input[name="fontawesome_use_cdn"]' => [
            'checked' => FALSE,
          ],
        ],
      ],
    ],
  ];
  return parent::buildForm($form, $form_state);
}