Error message

  • Warning: count(): Parameter must be an array or an object that implements Countable in _api_make_match_member_link() (line 1230 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).
  • Warning: count(): Parameter must be an array or an object that implements Countable in _api_make_match_member_link() (line 1230 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).
  • Notice: Undefined property: stdClass::$preferred in _api_make_match_link() (line 1075 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).
  • Notice: Undefined property: stdClass::$preferred in _api_make_match_link() (line 1079 of /home/projects/api/www/sites/all/modules/api/api.formatting.inc).

public static function InlineParagraphsWidget::addTranslatabilityClue

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

paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php, line 1418

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;
}