Conflict with the tmgmt module

Created on 26 January 2017, almost 8 years ago
Updated 5 February 2023, almost 2 years ago

Hi everyone,

I'm having compatibility problems with the Translation Management Tool. The code needs at least a couple of condition check in the better_formats_filter_process_format function.

 if ($form_object instanceof Drupal\Core\Entity\ContentEntityForm) {
    $entity = $element['#entity'];
    $entity_type = $entity->getEntityTypeId();
    $field_name = $element['#field_name'];
    $field_definition = $entity->getFieldDefinition($field_name);

The $entity['#entity'] value doesn't exists in some cases.

Thank you

🐛 Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

🇪🇸Spain aerrasti

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇧🇷Brazil renatog Campinas
    +++ b/better_formats.module
    @@ -10,6 +10,25 @@ use Drupal\Core\Form\FormStateInterface;
    +function better_formats_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) {
    +  $field_definition = $context['items']->getFieldDefinition();
    +  if (better_formats_is_text_format($field_definition->getType())) {
    +    // Since $form object cannot be trusted to retrieve $entity and $field_name
    +    // in better_formats_filter_process_format when using embed entities
    +    // (with paragraphs, or inline_entity_form), let's handle it in field_widget_alter,
    +    // where we can work with $context.
    +    $element['#entity'] = $context['items']->getEntity();
    +    $element['#field_name'] = $context['items']->getName();
    +  }
    +}
    

    I'd say that we can improve this logic with early return

  • 🇧🇷Brazil renatog Campinas

    The patch needs to be updated as well because it was implementing a hook_field_widget_form_alter but currently already have this hook at 8.x-1.x https://git.drupalcode.org/project/better_formats/-/blob/8.x-1.x/better_...

Production build 0.71.5 2024