You are here

public function GathercontentContentImportConfirmForm::buildForm in GatherContent 8

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 GathercontentMultistepFormBase::buildForm

File

src/Form/GathercontentContentImportConfirmForm.php, line 28

Class

GathercontentContentImportConfirmForm
Class GathercontentContentImportConfirmForm.

Namespace

Drupal\gathercontent\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildForm($form, $form_state);
  $nodes = $this->store
    ->get('nodes');
  $form['title'] = array(
    'form_title' => array(
      '#type' => 'html_tag',
      '#tag' => 'h2',
      '#value' => \Drupal::translation()
        ->formatPlural(count($nodes), 'Confirm import selection (@count item)', 'Confirm import selection (@count items)'),
    ),
    'form_description' => array(
      '#type' => 'html_tag',
      '#tag' => 'p',
      '#value' => t('Please review your import selection before importing.'),
    ),
  );
  $header = array(
    'status' => t('Status'),
    'title' => t('Item name'),
    'template' => t('GatherContent Template'),
  );
  $options = array();
  $tmp_obj = new Template();
  $templates = $tmp_obj
    ->getTemplates($this->store
    ->get('project_id'));
  foreach ($nodes as $node) {
    $content_obj = new Content();
    $content = $content_obj
      ->getContent($node);
    $options[$content->id] = array(
      'status' => '<div style="width:20px; height: 20px; float: left; margin-right: 5px; background: ' . $content->status->data->color . ';"></div>' . $content->status->data->name,
      'title' => $content->name,
      'template' => $templates[$content->template_id],
    );
  }
  $form['table'] = array(
    '#type' => 'table',
    '#header' => $header,
    '#rows' => $options,
  );
  $options = array();
  $project_obj = new Project();
  $statuses = $project_obj
    ->getStatuses($this->store
    ->get('project_id'));
  foreach ($statuses as $status) {
    $options[$status->id] = $status->name;
  }
  $form['status'] = array(
    '#type' => 'select',
    '#options' => $options,
    '#title' => t('After successful import change status to:'),
    '#empty_option' => t("- Don't change status -"),
  );
  $form['actions']['submit']['#value'] = $this
    ->t('Import');
  $form['actions']['back'] = array(
    '#type' => 'submit',
    '#value' => $this
      ->t('Back'),
  );
  return $form;
}