You are here

public function SimpleNodeImporterConfigForm::buildForm in Simple Node Importer 8

Builds config form.

Overrides ConfigFormBase::buildForm

File

src/Form/SimpleNodeImporterConfigForm.php, line 46

Class

SimpleNodeImporterConfigForm
Configuration Form for the Simple Node Importer.

Namespace

Drupal\simple_node_importer\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('simple_node_importer.settings');
  $content_type_selected = [];
  $content_type_select = $config
    ->get('content_type_select');
  $entity_type_options = [
    'node' => 'node',
    'user' => 'user',
    'taxonomy' => 'taxonomy',
  ];
  if (!empty($content_type_select)) {
    foreach ($content_type_select as $key => $value) {
      if ($value) {
        $content_type_selected[$key] = $value;
      }
    }
  }
  $form['fieldset_entity_type'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('entity type settings'),
    '#weight' => 1,
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  ];
  $form['fieldset_entity_type']['entity_type_select'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Select entity type'),
    '#default_value' => $config
      ->get('entity_type_select'),
    '#options' => $entity_type_options,
    '#description' => $this
      ->t('Configuration for the entity type to be selected.'),
    '#required' => FALSE,
  ];
  $form['fieldset_content_type'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Content type settings'),
    '#weight' => 1,
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#states' => [
      'visible' => [
        ':input[name="entity_type_select[node]"]' => [
          [
            'checked' => TRUE,
          ],
        ],
      ],
    ],
  ];
  $form['fieldset_content_type']['content_type_select'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Select content type'),
    '#default_value' => isset($content_type_selected) ? $content_type_selected : NULL,
    '#options' => $this->contentTypes,
    '#description' => $this
      ->t('Configuration for the content type to be selected.'),
    '#required' => FALSE,
  ];
  $form['fieldset_user_auto_create_settings'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('User Auto Creation Settings'),
    '#weight' => 1,
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  ];

  // The options to display in our form radio buttons.
  $options = [
    'admin' => $this
      ->t('Set Admin as default author.'),
    'current' => $this
      ->t('Set current user as default author.'),
    'new' => $this
      ->t('Create new user with authenticated role.'),
  ];
  $form['fieldset_user_auto_create_settings']['simple_node_importer_allow_user_autocreate'] = [
    '#type' => 'radios',
    '#options' => $options,
    '#default_value' => $config
      ->get('simple_node_importer_allow_user_autocreate'),
    '#description' => $this
      ->t('User will be set accordingly, if the provided value for author in csv is not avaiable in the system.'),
  ];
  $form['fieldset_taxonomy_term_type'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Taxonomy Term settings'),
    '#weight' => 1,
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  ];
  $form['fieldset_taxonomy_term_type']['simple_node_importer_allow_add_term'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Allow adding new taxonomy terms.'),
    '#default_value' => $config
      ->get('simple_node_importer_allow_add_term'),
    '#description' => $this
      ->t('Check to allow adding term for taxonomy reference fields, if term is not available.'),
  ];
  $form['fieldset_remove_importer'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Node remove settings'),
    '#weight' => 2,
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  ];

  // The options to display in our checkboxes.
  $option = [
    'option' => $this
      ->t('Delete import logs.'),
  ];
  $form['fieldset_remove_importer']['node_delete'] = [
    '#title' => '',
    '#type' => 'checkboxes',
    '#description' => $this
      ->t('Select the checkbox to delete all import logs permanently.'),
    '#options' => $option,
  ];
  return parent::buildForm($form, $form_state);
}