You are here

public function LocalFontConfigEntityForm::form in @font-your-face 8.3

Gets the actual form array to be built.

Overrides EntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

modules/local_fonts/src/Form/LocalFontConfigEntityForm.php, line 20

Class

LocalFontConfigEntityForm
Config form to set the local fonts.

Namespace

Drupal\local_fonts\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $local_font_config_entity = $this->entity;
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#maxlength' => 255,
    '#default_value' => $local_font_config_entity
      ->label(),
    '#description' => $this
      ->t("Name of the Custom Font. Note that while Font Family is not necessarily unique, this name is."),
    '#required' => TRUE,
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#default_value' => $local_font_config_entity
      ->id(),
    '#machine_name' => [
      'exists' => '\\Drupal\\local_fonts\\Entity\\LocalFontConfigEntity::load',
    ],
    '#disabled' => !$local_font_config_entity
      ->isNew(),
  ];
  $form['font_family'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Font family'),
    '#default_value' => isset($local_font_config_entity->font_family) ? $local_font_config_entity->font_family : '',
    '#description' => $this
      ->t('The CSS Font Family. The @font-face name will be based on this.'),
    '#size' => 60,
    '#maxlength' => 128,
    '#required' => TRUE,
  ];
  $form['font_style'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Font Style'),
    '#options' => [
      'normal' => $this
        ->t('Normal'),
      'italic' => $this
        ->t('Italics'),
    ],
    '#default_value' => isset($local_font_config_entity->font_style) ? $local_font_config_entity->font_style : 'normal',
  ];
  $form['font_weight'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Font Weight'),
    '#options' => [
      '100' => $this
        ->t('100 (Thin)'),
      '200' => $this
        ->t('200 (Extra Light, Ultra Light)'),
      '300' => $this
        ->t('300 (Light)'),
      'normal' => $this
        ->t('400 (Normal, Book, Regular)'),
      '500' => $this
        ->t('500 (Medium)'),
      '600' => $this
        ->t('600 (Semi Bold, Demi Bold)'),
      '700' => $this
        ->t('700 (Bold)'),
      '800' => $this
        ->t('800 (Extra Bold, Ultra Bold)'),
      '900' => $this
        ->t('900 (Black, Heavy)'),
    ],
    '#default_value' => isset($local_font_config_entity->font_weight) ? $local_font_config_entity->font_weight : '400',
  ];
  $form['font_classification'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Font Classification'),
    '#description' => $this
      ->t('This is mostly useful for filtering.'),
    '#options' => [
      'serif' => $this
        ->t('Serif'),
      'sans-serif' => $this
        ->t('Sans Serif'),
      'slab-serif' => $this
        ->t('Slab Serif'),
      'handwriting' => $this
        ->t('Handwriting'),
      'decorative' => $this
        ->t('Decorative'),
      'monospace' => $this
        ->t('Monospace'),
    ],
    '#default_value' => isset($local_font_config_entity->font_classification) ? $local_font_config_entity->font_classification : [],
  ];
  $form['font_file'] = [
    '#type' => 'managed_file',
    '#title' => $this
      ->t('Font File'),
    '#description' => $this
      ->t('The font file must be in WOFF format since that is accepted by all modern browsers.'),
    '#size' => 50,
    '#upload_validators' => [
      'file_validate_extensions' => [
        'woff',
      ],
      'file_validate_size' => [
        Environment::getUploadMaxSize(),
      ],
      'file_validate_name_length' => [],
    ],
  ];
  return $form;
}