You are here

public function ConflictResolutionDialogFormBuilder::processForm in Conflict 8.2

Adds the conflict resolution overview to the form.

Parameters

$form: The form array.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

File

src/Form/ConflictResolutionDialogFormBuilder.php, line 45

Class

ConflictResolutionDialogFormBuilder

Namespace

Drupal\conflict\Form

Code

public function processForm(&$form, FormStateInterface $form_state) {
  if ($form_state
    ->get('conflict.build_conflict_resolution_form') || $form_state
    ->get('conflict.processing')) {
    $form['conflict_overview_form'] = [
      '#type' => 'container',
      '#title' => t('Conflict resolution'),
      '#id' => 'conflict-overview-form',
      '#attributes' => [
        'title' => t('Conflict resolution'),
      ],
    ];
    $form['conflict_overview_form']['description'] = [
      '#type' => 'container',
      '#markup' => t('The content has either been modified by another user, or you have already submitted modifications. In order to save your changes a manual conflict resolution should be performed by clicking on "Resolve conflicts".'),
      '#attributes' => [
        'class' => [
          'conflict-overview-form-description',
        ],
      ],
    ];
    $header = [
      [
        'data' => t('Conflicts'),
      ],
    ];
    $rows = [];
    $conflict_paths = $form_state
      ->get('conflict.paths');
    foreach (array_keys($conflict_paths) as $path) {
      $path_titles = [];
      $path_entities = static::getEntitiesForPropertyPath($path, $form_state);
      foreach ($path_entities as $path_entity) {
        $path_titles[] = $path_entity
          ->getEntityType()
          ->getLabel() . ': "' . $path_entity
          ->label() . '"';
      }
      $path_title = [
        '#type' => 'details',
        '#title' => end($path_titles),
        '#open' => FALSE,
        'preview' => static::buildNestedItemList($path_titles, TRUE, t('Conflict path')),
      ];
      $rows[] = [
        'data' => [
          [
            'data' => $path_title,
          ],
        ],
      ];
    }
    $form['conflict_overview_form']['conflicts'] = [
      '#type' => 'table',
      '#header' => $header,
      '#rows' => $rows,
    ];
    $form['conflict_overview_form']['resolve_conflicts'] = [
      '#type' => 'submit',
      '#value' => t('Resolve conflicts'),
      '#name' => 'conflict-resolve-conflicts',
      '#limit_validation_errors' => [],
      '#validate' => [],
      '#submit' => [
        [
          $this,
          'resolveConflictsSubmit',
        ],
      ],
      '#ajax' => [
        'callback' => [
          $this,
          'resolveConflictsAjax',
        ],
      ],
    ];
    $form['conflict_overview_form']['reset_changes'] = [
      '#type' => 'button',
      '#value' => t('Start over'),
      '#name' => 'conflict-reset-changes',
    ];
    $form['conflict_overview_form']['#attached']['library'][] = 'conflict/drupal.conflict_resolution';
  }
}