You are here

public function FieldsSettingsForm::buildForm in Diff 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 ConfigFormBase::buildForm

File

src/Form/FieldsSettingsForm.php, line 107

Class

FieldsSettingsForm
Configure fields with their diff builder plugin settings.

Namespace

Drupal\diff\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildForm($form, $form_state);

  // The table containing all the field types discovered in the system.
  $form['fields'] = array(
    '#type' => 'table',
    '#tree' => TRUE,
    '#header' => $this
      ->getTableHeader(),
    '#empty' => $this
      ->t('No field types found.'),
    '#prefix' => '<div id="field-display-overview-wrapper">',
    '#suffix' => '</div>',
    '#attributes' => array(
      'class' => array(
        'field-ui-overview',
      ),
      'id' => 'field-display-overview',
    ),
  );

  // Build a row in the table for each field of each entity type. Get all the
  // field plugins.
  foreach ($this->entityTypeManager
    ->getDefinitions() as $entity_type_name => $entity_type) {

    // Exclude non-revisionable entities.
    if (!$entity_type
      ->isRevisionable()) {
      continue;
    }
    $field_definitions = $this->entityFieldManager
      ->getFieldStorageDefinitions($entity_type_name);
    foreach ($field_definitions as $field_name => $field_definition) {
      $show_diff = $this->diffBuilderManager
        ->showDiff($field_definition);
      if (!$show_diff) {
        continue;
      }
      $key = $entity_type_name . '__' . $field_name;

      // Build a row in the table for this field.
      $form['fields'][$key] = $this
        ->buildFieldRow($entity_type, $field_definition, $form_state);
    }
  }
  $this->diffBuilderManager
    ->clearCachedDefinitions();

  // Submit button for the form.
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#button_type' => 'primary',
    '#value' => $this
      ->t('Save'),
  );
  $form['#attached']['library'][] = 'field_ui/drupal.field_ui';
  $form['#attached']['library'][] = 'diff/diff.general';
  return $form;
}