conflict_paragraphs.module in Conflict 8.2
File
modules/conflict_paragraphs/conflict_paragraphs.module
View source
<?php
use Drupal\Core\Form\FormStateInterface;
use Drupal\conflict\Entity\EntityConflictHandlerInterface;
use Drupal\paragraphs\Plugin\Field\FieldWidget\ParagraphsWidget;
function conflict_paragraphs_field_widget_paragraphs_form_alter(&$element, FormStateInterface $form_state, $context) {
$items = $context['items'];
$delta = $context['delta'];
$widget = $context['widget'];
$widget_state = $widget::getWidgetState($element['#field_parents'], $items
->getName(), $form_state);
$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);
}
function conflict_paragraphs_field_widget_entity_reference_paragraphs_form_alter(&$element, FormStateInterface $form_state, $context) {
conflict_paragraphs_field_widget_paragraphs_form_alter($element, $form_state, $context);
}
function conflict_paragraphs_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if ($form_state
->get('conflict.build_conflict_resolution_form')) {
$manual_merge_conflicts = $form_state
->get('manual-merge-conflicts');
if ($manual_merge_conflicts) {
$entity = $form_state
->getFormObject()
->getEntity();
foreach ($manual_merge_conflicts as $field_name => $conflict_data) {
if (ParagraphsWidget::isApplicable($entity
->getFieldDefinition($field_name)) && isset($form[$field_name]['conflict_resolution'])) {
unset($form[$field_name]['conflict_resolution']);
}
}
}
}
}
function conflict_paragraphs_module_implements_alter(&$implementations, $hook) {
if ($hook === 'form_alter') {
$group = $implementations['conflict_paragraphs'];
unset($implementations['conflict_paragraphs']);
$implementations['conflict_paragraphs'] = $group;
}
}