You are here

public function PoolForm::form in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.1.x src/Form/PoolForm.php \Drupal\cms_content_sync\Form\PoolForm::form()
  2. 2.0.x src/Form/PoolForm.php \Drupal\cms_content_sync\Form\PoolForm::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/PoolForm.php, line 129

Class

PoolForm
Form handler for the Pool add and edit forms.

Namespace

Drupal\cms_content_sync\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $form['#tree'] = false;
  $defaults = $this
    ->getDefaults($form_state);
  if (!empty($defaults['backend_url'])) {
    $form['default_backend_url'] = [
      '#type' => 'hidden',
      '#value' => $defaults['backend_url'],
    ];
  }
  if (!empty($defaults['name'])) {
    $form['default_name'] = [
      '#type' => 'hidden',
      '#value' => $defaults['name'],
    ];
  }
  if (!empty($defaults['id'])) {
    $form['default_id'] = [
      '#type' => 'hidden',
      '#value' => $defaults['id'],
    ];
  }

  /**
   * @var \Drupal\cms_content_sync\Entity\Pool $pool
   */
  $pool = $this->entity;

  // Check if the site id or backend_url got set within the settings*.php.
  if (!is_null($pool->id)) {
    $this->configMachineName = $pool->id;
    $cms_content_sync_settings = Settings::get('cms_content_sync');
    if (!is_null($cms_content_sync_settings) && isset($cms_content_sync_settings['pools'][$pool->id]['backend_url'])) {
      $this->backendUrl = $cms_content_sync_settings['pools'][$pool->id]['backend_url'];
    }
  }
  if (!isset($this->configMachineName)) {
    $this->configMachineName = '<machine_name_of_the_configuration>';
  }
  $step = $this
    ->getCurrentFormStep($form_state);
  if (self::STEP_SYNC_CORE === $step) {
    $elements = $this
      ->syncCoreForm($form, $form_state);
  }
  else {
    $elements = $this
      ->poolForm($form, $form_state);
  }
  $form['elements'] = array_merge([
    '#prefix' => '<div id="' . self::CONTAINER_ID . '">',
    '#suffix' => '</div>',
    'step' => [
      '#type' => 'hidden',
      '#value' => $step,
    ],
  ], $elements);
  return $form;
}