You are here

protected function ContentBuilderForm::buildFormPageTwo in Schema.org configuration tool (RDF UI) 8

Returns the form for the second page.

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.

1 call to ContentBuilderForm::buildFormPageTwo()
ContentBuilderForm::buildForm in rdf_builder/src/Form/ContentBuilderForm.php
@inheritdoc

File

rdf_builder/src/Form/ContentBuilderForm.php, line 163

Class

ContentBuilderForm

Namespace

Drupal\rdf_builder\Form

Code

protected function buildFormPageTwo(array $form, FormStateInterface $form_state) {
  $form['#title'] = $this
    ->t('Content types');
  $form['description'] = array(
    '#type' => 'item',
    '#title' => $this
      ->t('Choose fields to start with.'),
  );
  $rdf_type = $form_state
    ->get([
    'page_values',
    1,
    'rdf-type',
  ]);
  $properties = $this->converter
    ->getTypeProperties($rdf_type);
  $field_types = \Drupal::service('plugin.manager.field.field_type')
    ->getUiDefinitions();
  $field_type_options = array();
  foreach ($field_types as $name => $field_type) {

    // Skip field types which should not be added via user interface.
    if (empty($field_type['no_ui'])) {
      $field_type_options[$name] = $field_type['label'];
    }
  }
  asort($field_type_options);
  $table = array(
    '#type' => 'table',
    '#tree' => TRUE,
    '#header' => array(
      $this
        ->t('Enable'),
      $this
        ->t('Property'),
      $this
        ->t('Data Type'),
    ),
    '#regions' => array(),
    '#attributes' => array(
      'class' => array(
        'rdfui-field-mappings',
      ),
      'id' => Html::getId('rdf-builder'),
    ),
  );
  foreach ($properties as $key => $value) {
    $table[$key] = array(
      '#attributes' => array(
        'id' => Html::getClass($key),
      ),
      'enable' => array(
        '#type' => 'checkbox',
        '#title' => $this
          ->t('Enable'),
        '#title_display' => 'invisible',
      ),
      'property' => array(
        '#markup' => Html::escape($value),
      ),
      'type' => array(
        '#type' => 'select',
        '#title' => $this
          ->t('Data Type'),
        '#title_display' => 'invisible',
        '#options' => $field_type_options,
        '#default_value' => $this
          ->getDefaultFieldType($key),
        '#empty_option' => $this
          ->t('- Select a field type -'),
        '#attributes' => array(
          'class' => array(
            'field-type-select',
          ),
        ),
        '#cell_attributes' => array(
          'colspan' => 2,
        ),
      ),
    );
  }

  // Fields.
  $table['#regions']['content']['rows_order'] = array();
  foreach (Element::children($table) as $name) {
    $table['#regions']['content']['rows_order'][] = $name;
  }
  $form['fields'] = $table;
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#button_type' => 'primary',
    '#value' => $this
      ->t('Save'),
  );
  $form['actions']['previous'] = array(
    '#type' => 'submit',
    '#value' => $this
      ->t('< Back'),
    '#submit' => array(
      array(
        $this,
        'pageTwoBackSubmit',
      ),
    ),
    '#limit_validation_errors' => array(),
    '#validate' => array(
      array(
        $this,
        'pageTwoBackValidate',
      ),
    ),
    '#weight' => -1,
  );
  return $form;
}