You are here

public function BackgroundImageForm::build in Background Image 2.0.x

Same name and namespace in other branches
  1. 8 src/Form/BackgroundImageForm.php \Drupal\background_image\Form\BackgroundImageForm::build()
  2. 2.x src/Form/BackgroundImageForm.php \Drupal\background_image\Form\BackgroundImageForm::build()

Builds the Background Image form.

File

src/Form/BackgroundImageForm.php, line 106

Class

BackgroundImageForm

Namespace

Drupal\background_image\Form

Code

public function build() {

  // Add necessary handlers.
  self::attachValidationHandler([
    self::class,
    'staticValidate',
  ], $this->form, $this->formState);
  self::attachSubmitHandler([
    self::class,
    'staticSubmit',
  ], $this->form, $this->formState);
  switch ($this->step) {

    // Type selection.
    case 1:
      $this
        ->buildTypeSelection();
      break;

    // Complete form.
    case 2:

      // Begin constructing the form. Use vertical tabs if this is not embedded
      // on another entity form.
      $this->subform['vertical_tabs'] = [
        '#type' => 'vertical_tabs',
        '#access' => !$this->inlineEntity,
      ];

      // Image.
      $this
        ->buildImage($this
        ->createGroup('image_group', $this->subform, [
        '#title' => $this
          ->t('Image'),
        '#group' => $this->inlineEntity ? NULL : 'vertical_tabs',
        '#type' => $this->inlineEntity ? 'container' : 'details',
        '#weight' => 10,
      ]));

      // Settings.
      $this
        ->buildSettings();
      break;
  }
}