protected function MergeRemoteStructure::reorderWidgetState in Conflict 8.2
Reorders the widget state for the reordered item list.
Parameters
\Drupal\Core\Field\FieldItemListInterface $field_item_list: The reordered field item list.
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
1 call to MergeRemoteStructure::reorderWidgetState()
- MergeRemoteStructure::resolveConflictsContentEntity in modules/
conflict_paragraphs/ src/ ConflictResolution/ MergeRemoteStructure.php - Resolves conflicts on content entities.
File
- modules/
conflict_paragraphs/ src/ ConflictResolution/ MergeRemoteStructure.php, line 205
Class
Namespace
Drupal\conflict_paragraphs\ConflictResolutionCode
protected function reorderWidgetState(FieldItemListInterface $field_item_list, FormStateInterface $form_state) {
$field_name = $field_item_list
->getName();
$widget_state = ParagraphsWidget::getWidgetState([], $field_name, $form_state);
$old_widget_state_paragraphs = $widget_state['paragraphs'];
$widget_state['paragraphs'] = [];
foreach ($field_item_list as $new_delta => $item) {
$found = FALSE;
foreach ($old_widget_state_paragraphs as $old_delta => $old_delta_state) {
if ($item->target_id == $old_delta_state['entity']
->id()) {
$widget_state['paragraphs'][$new_delta] = $old_delta_state;
$widget_state['paragraphs'][$new_delta]['entity'] = $item->entity;
$found = TRUE;
}
}
// New entity.
if (!$found) {
$widget_state['paragraphs'][$new_delta]['entity'] = $item->entity;
}
}
$widget_state['items_count'] = count($widget_state['paragraphs']);
ParagraphsWidget::setWidgetState([], $field_name, $form_state, $widget_state);
}