Implements hook_form_FORM_ID_alter().
Indicate unsupported multilingual paragraphs field configuration.
function paragraphs_form_field_config_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$field = $form_state
->getFormObject()
->getEntity();
if (\Drupal::hasService('content_translation.manager')) {
$bundle_is_translatable = \Drupal::service('content_translation.manager')
->isEnabled($field
->getTargetEntityTypeId(), $field
->getTargetBundle());
if ($bundle_is_translatable && $field
->getType() === 'entity_reference_revisions' && $field
->getSetting('target_type') === 'paragraph') {
// This is a translatable ERR field pointing to a paragraph.
$message_display = 'warning';
$message_text = t('Paragraphs fields do not support translation. See the <a href=":documentation">online documentation</a>.', [
':documentation' => Url::fromUri('https://www.drupal.org/node/2735121')
->toString(),
]);
if ($form['translatable']['#default_value'] == TRUE) {
$message_display = 'error';
}
$form['paragraphs_message'] = [
'#type' => 'container',
'#markup' => $message_text,
'#attributes' => [
'class' => [
'messages messages--' . $message_display,
],
],
'#weight' => 0,
];
}
}
if ($field
->getType() == 'entity_reference') {
$selector = 'field_storage[subform][settings][target_type]';
// Add a note about paragraphs if selected.
$form['field_storage']['subform']['settings']['paragraph_warning_wrapper'] = [
'#type' => 'container',
'#states' => [
'visible' => [
':input[name="' . $selector . '"]' => [
'value' => 'paragraph',
],
],
],
'warning' => [
'#theme' => 'status_messages',
'#message_list' => [
'warning' => [
t('Note: Regular paragraph fields should use the revision based reference fields, entity reference fields should only be used for cases when an existing paragraph is referenced from somewhere else.'),
],
],
'#status_headings' => [
'error' => t('Warning'),
],
],
];
}
}