You are here

public static function InlineParagraphsWidget::addTranslatabilityClue in Paragraphs 8

After-build callback for adding the translatability clue from the widget.

ContentTranslationHandler::addTranslatabilityClue() adds an "(all languages)" suffix to the widget title, replicate that here.

Parameters

array $element:

\Drupal\Core\Form\FormStateInterface $form_state:

Return value

array

File

src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php, line 1400

Class

InlineParagraphsWidget
Plugin implementation of the 'entity_reference paragraphs' widget.

Namespace

Drupal\paragraphs\Plugin\Field\FieldWidget

Code

public static function addTranslatabilityClue(array $element, FormStateInterface $form_state) {
  static $suffix, $fapi_title_elements;

  // Widgets could have multiple elements with their own titles, so remove the
  // suffix if it exists, do not recurse lower than this to avoid going into
  // nested paragraphs or similar nested field types.
  // Elements which can have a #title attribute according to FAPI Reference.
  if (!isset($suffix)) {
    $suffix = ' <span class="translation-entity-all-languages">(' . t('all languages') . ')</span>';
    $fapi_title_elements = array_flip([
      'checkbox',
      'checkboxes',
      'date',
      'details',
      'fieldset',
      'file',
      'item',
      'password',
      'password_confirm',
      'radio',
      'radios',
      'select',
      'textarea',
      'textfield',
      'weight',
    ]);
  }

  // Update #title attribute for all elements that are allowed to have a
  // #title attribute according to the Form API Reference. The reason for this
  // check is because some elements have a #title attribute even though it is
  // not rendered; for instance, field containers.
  if (isset($element['#type']) && isset($fapi_title_elements[$element['#type']]) && isset($element['#title'])) {
    $element['#title'] .= $suffix;
  }
  elseif ($children = Element::children($element)) {
    foreach ($children as $delta) {
      $element[$delta] = static::addTranslatabilityClue($element[$delta], $form_state);
    }
  }
  elseif (isset($element['#title'])) {
    $element['#title'] .= $suffix;
  }
  return $element;
}