You are here

function entity_reference_layout_form_field_config_edit_form_alter in Entity Reference with Layout 8

Implements hook_form_FORM_ID_alter().

Indicate unsupported multilingual ERL field configuration.

See also

paragraphs_form_field_config_edit_form_alter

File

./entity_reference_layout.module, line 447
Contains entity_reference_layout.module.

Code

function entity_reference_layout_form_field_config_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  /* @var \Drupal\field\Entity\FieldConfig $field */
  $field = $form_state
    ->getFormObject()
    ->getEntity();
  if (!\Drupal::hasService('content_translation.manager')) {
    return;
  }
  $bundle_is_translatable = \Drupal::service('content_translation.manager')
    ->isEnabled($field
    ->getTargetEntityTypeId(), $field
    ->getTargetBundle());
  if (!$bundle_is_translatable || $field
    ->getType() != 'entity_reference_layout_revisioned' || $field
    ->getSetting('target_type') != 'paragraph') {
    return;
  }

  // This is a translatable ERL 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,
  ];
}