You are here

public function YamlForm::getPages in YAML Form 8

Get form wizard pages.

Return value

array An associative array of form pages.

Overrides YamlFormInterface::getPages

1 call to YamlForm::getPages()
YamlForm::getPage in src/Entity/YamlForm.php
Get form wizard page.

File

src/Entity/YamlForm.php, line 1063

Class

YamlForm
Defines the form entity.

Namespace

Drupal\yamlform\Entity

Code

public function getPages() {
  if (isset($this->pages)) {
    return $this->pages;
  }
  $wizard_properties = [
    '#title' => '#title',
    '#prev_button_label' => '#prev_button_label',
    '#next_button_label' => '#next_button_label',
  ];
  $elements = $this
    ->getElementsInitialized();

  // Add form page containers.
  $this->pages = [];
  if (is_array($elements)) {
    foreach ($elements as $key => $element) {
      if (isset($element['#type']) && $element['#type'] == 'yamlform_wizard_page') {
        $this->pages[$key] = array_intersect_key($element, $wizard_properties);
      }
    }
  }

  // Add preview page.
  $settings = $this
    ->getSettings();
  if ($settings['preview'] != DRUPAL_DISABLED) {

    // If there is no start page, we must define one.
    if (empty($this->pages)) {
      $this->pages['start'] = [
        '#title' => $this
          ->getSetting('wizard_start_label') ?: \Drupal::config('yamlform.settings')
          ->get('settings.default_wizard_start_label'),
      ];
    }
    $this->pages['preview'] = [
      '#title' => $this
        ->t('Preview'),
    ];
  }

  // Only add complete page, if there are some pages.
  if ($this->pages && $this
    ->getSetting('wizard_complete')) {
    $this->pages['complete'] = [
      '#title' => $this
        ->getSetting('wizard_complete_label') ?: \Drupal::config('yamlform.settings')
        ->get('settings.default_wizard_complete_label'),
    ];
  }
  return $this->pages;
}