You are here

public function PullForm::buildForm in Entity Share 8.3

Same name and namespace in other branches
  1. 8 modules/entity_share_client/src/Form/PullForm.php \Drupal\entity_share_client\Form\PullForm::buildForm()
  2. 8.2 modules/entity_share_client/src/Form/PullForm.php \Drupal\entity_share_client\Form\PullForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

modules/entity_share_client/src/Form/PullForm.php, line 191

Class

PullForm
Form controller to pull entities.

Namespace

Drupal\entity_share_client\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // Build the Import configuration selector.
  $select_element = $this
    ->buildSelectElement($form_state, 'import_config');
  if ($select_element) {
    $select_element['#title'] = $this
      ->t('Import configuration');
    $form['import_config'] = $select_element;
  }
  else {
    $url = Url::fromRoute('entity.import_config.collection');
    if ($url
      ->renderAccess($url
      ->toRenderArray())) {
      $this
        ->messenger()
        ->addError($this
        ->t('Please configure <a href=":url">Import configuration</a> before trying to import content.', [
        ':url' => $url
          ->toString(),
      ]));
    }
    else {
      $this
        ->messenger()
        ->addError($this
        ->t('There are no "Import configuration" available. Please contact the website administrator.'));
    }
  }

  // Build the Remote selector.
  $select_element = $this
    ->buildSelectElement($form_state, 'remote');
  if ($select_element) {
    $select_element['#title'] = $this
      ->t('Remote website');
    $select_element['#ajax'] = [
      'callback' => [
        get_class($this),
        'buildAjaxChannelSelect',
      ],
      'effect' => 'fade',
      'method' => 'replace',
      'wrapper' => 'channel-wrapper',
    ];
    $form['remote'] = $select_element;
  }

  // Container for the AJAX.
  $form['channel_wrapper'] = [
    '#type' => 'container',
    // Force an id because otherwise default id is changed when using AJAX.
    '#attributes' => [
      'id' => 'channel-wrapper',
    ],
  ];
  $this
    ->buildChannelSelect($form, $form_state);
  return $form;
}