You are here

public function GathercontentMappingImportForm::form in GatherContent 8

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/GathercontentMappingImportForm.php, line 21

Class

GathercontentMappingImportForm
Class GathercontentMappingImportForm.

Namespace

Drupal\gathercontent\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $pr_obj = new Project();
  $projects = $pr_obj
    ->getProjects();
  $template_obj = new Template();
  $form['description'] = array(
    '#type' => 'html_tag',
    '#tag' => 'div',
    '#value' => t("Please select the GatherContent Templates you'd like \n    to map. Only Templates you've not selected will be listed."),
    '#attributes' => array(
      'class' => array(
        'description',
      ),
    ),
  );
  $form['projects'] = array(
    '#type' => 'vertical_tabs',
  );
  $created_mapping_ids = GathercontentMapping::loadMultiple();
  $local_templates = array();
  foreach ($created_mapping_ids as $mapping) {

    /** @var $mapping GathercontentMapping */
    $local_templates[$mapping
      ->getGathercontentTemplateId()] = $mapping
      ->getGathercontentTemplate();
  }
  foreach ($projects as $project_id => $project) {
    $remote_templates = $template_obj
      ->getTemplates($project_id);
    $templates = array_diff_assoc($remote_templates, $local_templates);
    if (empty($templates)) {
      continue;
    }
    $form['p' . $project_id] = array(
      '#type' => 'details',
      '#title' => $project,
      '#group' => 'projects',
      '#tree' => TRUE,
    );
    $form['p' . $project_id]['templates'] = array(
      '#type' => 'checkboxes',
      '#title' => $project,
      '#options' => $templates,
    );
  }
  return $form;
}