Skip to content
Snippets Groups Projects

Issue #3269454: The deprecated alter hook hook_field_widget_form_alter() is implemented in these functions: entity_embed_field_widget_form_alter

Merged Issue #3269454: The deprecated alter hook hook_field_widget_form_alter() is implemented in these functions: entity_embed_field_widget_form_alter
+ 6
12
@@ -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();
}
}
Loading