function DateFormatFormBase::form

Same name in other branches
  1. 9 core/modules/system/src/Form/DateFormatFormBase.php \Drupal\system\Form\DateFormatFormBase::form()
  2. 10 core/modules/system/src/Form/DateFormatFormBase.php \Drupal\system\Form\DateFormatFormBase::form()
  3. 11.x core/modules/system/src/Form/DateFormatFormBase.php \Drupal\system\Form\DateFormatFormBase::form()

Overrides EntityForm::form

1 call to DateFormatFormBase::form()
DateFormatEditForm::form in core/modules/system/src/Form/DateFormatEditForm.php
Gets the actual form array to be built.
1 method overrides DateFormatFormBase::form()
DateFormatEditForm::form in core/modules/system/src/Form/DateFormatEditForm.php
Gets the actual form array to be built.

File

core/modules/system/src/Form/DateFormatFormBase.php, line 75

Class

DateFormatFormBase
Provides a base form for date formats.

Namespace

Drupal\system\Form

Code

public function form(array $form, FormStateInterface $form_state) {
    $form['label'] = [
        '#type' => 'textfield',
        '#title' => 'Name',
        '#maxlength' => 100,
        '#description' => t('Name of the date format'),
        '#default_value' => $this->entity
            ->label(),
    ];
    $form['id'] = [
        '#type' => 'machine_name',
        '#description' => t('A unique machine-readable name. Can only contain lowercase letters, numbers, and underscores.'),
        '#disabled' => !$this->entity
            ->isNew(),
        '#default_value' => $this->entity
            ->id(),
        '#machine_name' => [
            'exists' => [
                $this,
                'exists',
            ],
            'replace_pattern' => '([^a-z0-9_]+)|(^custom$)',
            'error' => $this->t('The machine-readable name must be unique, and can only contain lowercase letters, numbers, and underscores. Additionally, it can not be the reserved word "custom".'),
        ],
    ];
    $form['date_format_pattern'] = [
        '#type' => 'textfield',
        '#title' => t('Format string'),
        '#maxlength' => 100,
        '#description' => $this->t('A user-defined date format. See the <a href="http://php.net/manual/function.date.php">PHP manual</a> for available options.'),
        '#required' => TRUE,
        '#attributes' => [
            'data-drupal-date-formatter' => 'source',
        ],
        '#field_suffix' => ' <small class="js-hide" data-drupal-date-formatter="preview">' . $this->t('Displayed as %date_format', [
            '%date_format' => '',
        ]) . '</small>',
    ];
    $form['langcode'] = [
        '#type' => 'language_select',
        '#title' => t('Language'),
        '#languages' => LanguageInterface::STATE_ALL,
        '#default_value' => $this->entity
            ->language()
            ->getId(),
    ];
    $form['#attached']['drupalSettings']['dateFormats'] = $this->dateFormatter
        ->getSampleDateFormats();
    $form['#attached']['library'][] = 'system/drupal.system.date';
    return parent::form($form, $form_state);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.