You are here

function conflict_paragraphs_field_widget_paragraphs_form_alter in Conflict 8.2

Implements hook_field_widget_WIDGET_TYPE_form_alter().

1 call to conflict_paragraphs_field_widget_paragraphs_form_alter()
conflict_paragraphs_field_widget_entity_reference_paragraphs_form_alter in modules/conflict_paragraphs/conflict_paragraphs.module
Implements hook_field_widget_WIDGET_TYPE_form_alter().

File

modules/conflict_paragraphs/conflict_paragraphs.module, line 10

Code

function conflict_paragraphs_field_widget_paragraphs_form_alter(&$element, FormStateInterface $form_state, $context) {

  /** @var \Drupal\entity_reference_revisions\EntityReferenceRevisionsFieldItemList $items */
  $items = $context['items'];
  $delta = $context['delta'];

  /** @var \Drupal\paragraphs\Plugin\Field\FieldWidget\ParagraphsWidget $widget */
  $widget = $context['widget'];
  $widget_state = $widget::getWidgetState($element['#field_parents'], $items
    ->getName(), $form_state);

  /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */
  $form_display = $widget_state['paragraphs'][$delta]['display'];
  $entity = $widget_state['paragraphs'][$delta]['entity'];
  $entity->{EntityConflictHandlerInterface::CONFLICT_FORM_DISPLAY} = $form_display;
  $subform =& $element['subform'];
  conflict_prepare_entity_form($subform, $form_state, $entity, TRUE);

  // auto merge
  //
  // if server version contains all our edited (edit open) entities, then take
  // server order and apply merge resolution.
  //
  // If server contains new entities then merge them into ours and flag them as
  // new in the form.
  //
  // if one of our edited entities was removed from the server version then add
  // it as last element and flag it that it has been removed on the server
  // version
}