function SettingsForm::buildForm

Same name in this branch
  1. 10 core/modules/media_library/src/Form/SettingsForm.php \Drupal\media_library\Form\SettingsForm::buildForm()
Same name in other branches
  1. 9 core/modules/media_library/src/Form/SettingsForm.php \Drupal\media_library\Form\SettingsForm::buildForm()
  2. 9 core/modules/aggregator/src/Form/SettingsForm.php \Drupal\aggregator\Form\SettingsForm::buildForm()
  3. 8.9.x core/modules/media_library/src/Form/SettingsForm.php \Drupal\media_library\Form\SettingsForm::buildForm()
  4. 8.9.x core/modules/aggregator/src/Form/SettingsForm.php \Drupal\aggregator\Form\SettingsForm::buildForm()
  5. 11.x core/modules/media_library/src/Form/SettingsForm.php \Drupal\media_library\Form\SettingsForm::buildForm()
  6. 11.x core/modules/navigation/src/Form/SettingsForm.php \Drupal\navigation\Form\SettingsForm::buildForm()

Overrides ConfigFormBase::buildForm

File

core/modules/navigation/src/Form/SettingsForm.php, line 117

Class

SettingsForm
Configure Navigation settings for this site.

Namespace

Drupal\navigation\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) : array {
    $config = $this->config('navigation.settings');
    $form['#attached']['library'][] = 'core/drupal.states';
    $form['logo'] = [
        '#type' => 'fieldset',
        '#title' => $this->t('Logo options'),
    ];
    $form['logo']['logo_provider'] = [
        '#type' => 'radios',
        '#title' => $this->t('Choose logo handling'),
        '#title_display' => 'invisible',
        '#options' => [
            NavigationRenderer::LOGO_PROVIDER_DEFAULT => $this->t('Default logo'),
            NavigationRenderer::LOGO_PROVIDER_HIDE => $this->t('Hide logo'),
            NavigationRenderer::LOGO_PROVIDER_CUSTOM => $this->t('Custom logo'),
        ],
        '#default_value' => $config->get('logo_provider'),
    ];
    $form['logo']['image'] = [
        '#type' => 'container',
        '#states' => [
            'visible' => [
                ':input[name="logo_provider"]' => [
                    'value' => NavigationRenderer::LOGO_PROVIDER_CUSTOM,
                ],
            ],
        ],
    ];
    $allowed = 'png jpg jpeg';
    $current_logo_managed_fid = $config->get('logo_managed');
    $max_navigation_allowed = $config->get('logo_max_filesize');
    $max_system_allowed = Environment::getUploadMaxSize();
    $max_allowed = $max_navigation_allowed < $max_system_allowed ? $max_navigation_allowed : $max_system_allowed;
    $upload_validators = [
        'FileExtension' => [
            'extensions' => $allowed,
        ],
        'FileSizeLimit' => [
            'fileLimit' => $max_allowed,
        ],
    ];
    $file_upload_help = [
        '#theme' => 'file_upload_help',
        '#description' => $this->t('Recommended image dimension 40 x 40 pixels.'),
        '#upload_validators' => $upload_validators,
        '#cardinality' => 1,
    ];
    $form['logo']['image']['logo_managed'] = [
        '#type' => 'managed_file',
        '#title' => t('Choose custom logo'),
        '#upload_validators' => $upload_validators,
        '#upload_location' => 'public://navigation-logo',
        '#description' => $this->renderer
            ->renderInIsolation($file_upload_help),
        '#default_value' => $current_logo_managed_fid,
        '#multiple' => FALSE,
    ];
    return parent::buildForm($form, $form_state);
}

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