You are here

public function MiconForm::form in Micon 2.x

Same name and namespace in other branches
  1. 8 src/Form/MiconForm.php \Drupal\micon\Form\MiconForm::form()

Gets the actual form array to be built.

Overrides EntityForm::form

See also

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

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

File

src/Form/MiconForm.php, line 20

Class

MiconForm
Class MiconForm.

Namespace

Drupal\micon\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $micon = $this->entity;
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#maxlength' => 255,
    '#default_value' => $micon
      ->label(),
    '#description' => $this
      ->t("A descriptive label for the Micon package."),
    '#required' => TRUE,
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#title' => $this
      ->t('Class prefix'),
    '#description' => $this
      ->t('The unique selector prefix of this package. It will be used for rendering the icons within class names and paths. It will replace any class prefix or font names specified within the IcoMoon zip package.'),
    '#default_value' => $micon
      ->id(),
    '#field_prefix' => '.',
    '#machine_name' => [
      'label' => $this
        ->t('Class prefix'),
      'exists' => '\\Drupal\\micon\\Entity\\Micon::load',
      'replace_pattern' => '[^a-z0-9-]+',
      'replace' => '-',
      'field_prefix' => '.',
    ],
    '#disabled' => !$micon
      ->isNew(),
  ];
  $validators = [
    'file_validate_extensions' => [
      'zip',
    ],
    'file_validate_size' => [
      Environment::getUploadMaxSize(),
    ],
  ];
  $form['file'] = [
    '#type' => 'file',
    '#title' => $micon
      ->isNew() ? $this
      ->t('IcoMoon Font Package') : $this
      ->t('Replace IcoMoon Font Package'),
    '#description' => [
      '#theme' => 'file_upload_help',
      '#description' => $this
        ->t('An IcoMoon font package. <a href="https://icomoon.io">Generate & Download</a>'),
      '#upload_validators' => $validators,
    ],
    '#size' => 50,
    '#upload_validators' => $validators,
    '#attributes' => [
      'class' => [
        'file-import-input',
      ],
    ],
  ];
  $form['#entity_builders']['update_status'] = [
    $this,
    'updateStatus',
  ];
  return $form;
}