public function MiconForm::form in Micon 8
Same name and namespace in other branches
- 2.x 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 19
Class
- MiconForm
- Class MiconForm.
Namespace
Drupal\micon\FormCode
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 = array(
'file_validate_extensions' => array(
'zip',
),
'file_validate_size' => array(
file_upload_max_size(),
),
);
$form['file'] = array(
'#type' => 'file',
'#title' => $micon
->isNew() ? $this
->t('IcoMoon Font Package') : $this
->t('Replace IcoMoon Font Package'),
'#description' => array(
'#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' => array(
'class' => array(
'file-import-input',
),
),
);
$form['#entity_builders']['update_status'] = [
$this,
'updateStatus',
];
return $form;
}