Skip to content
Snippets Groups Projects
Commit c0248621 authored by Domen Šlogar's avatar Domen Šlogar Committed by Dave Reid
Browse files

Issue #3269454 by Dave Reid, slogar32: Replaced deprecated...

Issue #3269454 by Dave Reid, slogar32: Replaced deprecated hook_field_widget_form_alter() with hook_field_widget_single_element_form_alter() and simplified logic for entity language.
parent 27853bcb
No related branches found
No related tags found
1 merge request!3Issue #3269454: The deprecated alter hook hook_field_widget_form_alter() is implemented in these functions: entity_embed_field_widget_form_alter
......@@ -286,21 +286,15 @@ function entity_embed_filter_format_edit_form_validate($form, FormStateInterface
}
/**
* Implements hook_field_widget_form_alter().
* Implements hook_field_widget_single_element_form_alter().
*/
function entity_embed_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) {
function entity_embed_field_widget_single_element_form_alter(&$element, FormStateInterface $form_state, $context) {
// Add a `data-entity_embed-host-entity-langcode` attribute so that
// entity_embed's JavaScript can pass the host entity's language to
// EntityEmbedDialog, allowing it to present entities in the same language.
if (!empty($element['#type']) && $element['#type'] == 'text_format') {
if (!empty($context['items']) && $context['items'] instanceof FieldItemListInterface) {
$element['#attributes']['data-entity_embed-host-entity-langcode'] = $context['items']->getLangcode();
}
else {
$entity = $form_state->getFormObject()->getEntity();
if ($entity instanceof ContentEntityInterface) {
$element['#attributes']['data-entity_embed-host-entity-langcode'] = $entity->language()->getId();
}
}
if (isset($element['#type']) && $element['#type'] === 'text_format') {
/** @var FieldItemListInterface $items */
$items = $context['items'];
$element['#attributes']['data-entity_embed-host-entity-langcode'] = $items->getEntity()->language()->getId();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment