Support adding new entities when translating

Created on 28 October 2016, about 8 years ago
Updated 4 September 2024, 3 months ago

Line 360 of inline_entity_form/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php explicitly disables adding new references when translating. Commenting out this block of code appears to enable without issue (have only done a quick test with basic content types).

    // When in translation, the widget only supports editing (translating)
    // already added entities, so there's no need to show the rest.
    if ($element['#translating']) {
      if (empty($entities)) {
        // There are no entities available for translation, hide the widget.
        $element['#access'] = FALSE;
      }
      return $element;
    }

Is there a reason that I am missing/yet to hit for disabling adding new references to translated widgets?

โœจ Feature request
Status

Needs work

Version

3.0

Component

Code

Created by

๐Ÿ‡ฆ๐Ÿ‡บAustralia rakugaki Sydney

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

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

  • ๐Ÿ‡ฆ๐Ÿ‡นAustria drupalfan2

    Patch #89 does not work for 8.x-1.0-rc14 with Drupal 9.5.3 (it can be applied but it does not solve the problem).

    I did not find any other patch or any other solution.

    Does anyone have an idea how can I solve this?
    Thx.

  • ๐Ÿ‡ฆ๐Ÿ‡นAustria drupalfan2

    #93 solved:
    "Allow user to make asymmetric translation" has to be activated on Manage Form Display of the conent type.

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany hchonov ๐Ÿ‡ช๐Ÿ‡บ๐Ÿ‡ฉ๐Ÿ‡ช๐Ÿ‡ง๐Ÿ‡ฌ

    While testing this patch out I noticed that if the language of the content is changed this does not work quite well with referenced entities and sometimes their language gets changed as well or sometimes the entity remains in its original language and then differs from the one of the content after save ... We should not be assuming that we can simply change the language of the referenced entities since suddenly they might not get displayed in other places if they are reused. Instead, we should be translating them as this is the safe option. Worked on ๐Ÿ› Main entity language change does not propagate to nested paragraphs in preview mode Needs review for adding support for propagating the language change and adding support in the patch here as well. I am not sure if this is the right issue though or if another is needed for this.

  • The last submitted patch, 95: 2822764-95.patch, failed testing. View results โ†’
    - codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

  • ๐Ÿ‡จ๐Ÿ‡ดColombia waspper

    There is a failing test about the same langcode for child entities. IMHO, it's not "valid", because this patch is in the way to allow having asymmetric content. I've removed some lines. Feel free to improve/blame :)

  • The last submitted patch, 97: 2822764-97.patch, failed testing. View results โ†’
    - codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

  • ๐Ÿ‡จ๐Ÿ‡ดColombia waspper

    Forgot to remove a line.

  • The last submitted patch, 99: 2822764-99.patch, failed testing. View results โ†’
    - codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine quadrexdev Lutsk

    Updating version to the latest dev

  • @quadrexdev opened merge request.
  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine quadrexdev Lutsk

    I've prepared a merge request to the 2.0.x-dev branch with an updated patch. For me it works well, appreciate it if anyone else could test it.

    Also, attaching a file version of a patch in order to run some tests (cuz it seems for the 2.0.x-dev branch we have disabled tests running).

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.1.x + Environment: PHP 8.2 & MySQL 8
    last update over 1 year ago
    8 pass, 8 fail
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update over 1 year ago
    Composer require failure
  • Status changed to Needs review over 1 year ago
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update over 1 year ago
    Patch Failed to Apply
  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine quadrexdev Lutsk
  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine Goodmood

    I'm still using rerolled patch from #90 (due to the same reason which mentioned there) over rc15 and D10.

    With Drupal upgrade we have an exception when entity removed from ief widget and parent entity saved:
    "Entity queries must explicitly set whether the query should be access checked or not"
    This is because of absent accessCheck method on query in 'delete' method.
    Added this check to patch from #90

    Also this should be added to patch #99 because otherwise it'll throw an exception on D10 as well.

  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine Goodmood

    Sorry, wrong file was attached

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    8 pass, 8 fail
  • I create a new patch for drupal 10.1.x, thanks for @quadrexdev, the #103 is useful for me. At the same time, I merged the patch in this issue Parent form entity builders run on IEF resulting in fatal errors ๐Ÿ› Parent form entity builders run on IEF resulting in fatal errors Active into the new patch.
    And I added the code for checking entity langcode and form langcode to get the corresponding entity.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States drupalevangelist Detroit, MI

    I could not apply the #106 patch on Drupal 9.5.9 with PHP 8.1 on the 8.x-1.0-rc15 version. Was anyone able to use this patch cleanly?

  • ๐Ÿ‡ซ๐Ÿ‡ทFrance JulienVey

    Indeed the #106 patch is already based on the one you linked @drupalevangelist.

    Here's the one that does not need any pre-patch :)

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States drupalevangelist Detroit, MI

    Thank you! I was able to apply cleanly #111 patch on 8.x-1.0-rc15. But now I'm not encountering the following error when I try to create nodes using certain content types that has the Inline Entity Form widget configured:

    Error: Call to a member function bundle() on null in Drupal\views\Plugin\EntityReferenceSelection\ViewsSelection->stripAdminAndAnchorTagsFromResults() (line 289 of core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php).

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    2 pass, 14 fail
  • ๐Ÿ‡ง๐Ÿ‡ทBrazil adinancenci

    111 did not worked on 1.0-rc15 so I made some slight alterations for anyone interested.

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 8
    last update 11 months ago
    28 pass, 2 fail
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Thomas Cys

    Reroll against 3.0.0-rc19

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 5.6
    last update 10 months ago
    PHPLint Failed
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Thomas Cys

    Refactored patch because of failed tests in #114

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 8
    last update 10 months ago
    Patch Failed to Apply
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Thomas Cys

    Fixed broken tests

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.2.x + Environment: PHP 8.2 & MySQL 8
    last update 10 months ago
    12 pass, 3 fail
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.2.1 + Environment: PHP 8.1 & MySQL 8
    last update 10 months ago
    Patch Failed to Apply
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.2.x + Environment: PHP 8.2 & MySQL 8
    last update 10 months ago
    Patch Failed to Apply
  • ๐Ÿ‡ฑ๐Ÿ‡ปLatvia maijs

    Adding refactored patch for the 3.x branch (c753ec1).

    - The following code is reinstanted back to InlineEntityFormComplex.php file as removal of these caused namespace reference loss for existing code:

    use Drupal\Component\Utility\Tags;
    use Drupal\Core\Entity\Element\EntityAutocomplete;
  • ๐Ÿ‡ฑ๐Ÿ‡ปLatvia maijs

    Here's the follow-up update to the patch in #117.

    - The following code is reinstanted back to InlineEntityFormComplex.php file as removal of these caused namespace reference loss for existing code:

    use Drupal\Component\Utility\Tags;
    use Drupal\Core\Entity\Element\EntityAutocomplete;
  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands joshahubbers

    This is the patch is the same as #118, but rerolled for 3.x-rc19.

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update 7 months ago
    28 pass, 2 fail
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sarvjeetsingh

    The patch is same as #113, re--rolled it for 8.x-1.0-rc17

  • The last submitted patch, 120: 2822764-inline_entity_form-120.patch, failed testing. View results โ†’
    - codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Robin.Houtevelts

    robin.houtevelts โ†’ made their first commit to this issueโ€™s fork.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Robin.Houtevelts

    robin.houtevelts โ†’ changed the visibility of the branch 3.x to hidden.

  • Pipeline finished with Failed
    3 months ago
    Total: 734s
    #258572
  • First commit to issue fork.
  • Pipeline finished with Failed
    3 months ago
    Total: 434s
    #273005
  • achap ๐Ÿ‡ฆ๐Ÿ‡บ

    The latest commit of https://git.drupalcode.org/issue/inline_entity_form-2822764/-/tree/2822764-support-adding-new-entities-when-translating applies cleanly to 3.0.0-rc20 as a patch. I made a small change to remove @label from the translatable markup that was never actually getting replaced.

    The failing TranslationTest needs to be fixed and it seems to me that this patch has unintentionally changed the behavior even when allow asymmetric translations hasn't been enabled as the test fails on line 108 which is well before we enable it.

        // Both inline nodes should now be in English.
        $first_inline_node = $this->drupalGetNodeByTitle('Kann ein Kรƒยคnguru hรƒยถher als ein Haus springen?');
        $second_inline_node = $this->drupalGetNodeByTitle('Can a kangaroo jump higher than a house?');
        $this->assertSame('en', $first_inline_node->get('langcode')->value, 'The first inline entity has the correct langcode.');
        $this->assertEquals('en', $second_inline_node->get('langcode')->value, 'The second inline entity has the correct langcode.');
    
  • #126

    The website encountered an unexpected error. Try again later.

    Error: Call to a member function isTranslatable() on null in Drupal\inline_entity_form\Form\EntityInlineForm->delete() (line 346 of modules/contrib/inline_entity_form/src/Form/EntityInlineForm.php).
    Drupal\inline_entity_form\WidgetSubmit::doSubmit()
    call_user_func_array() (Line: 113)
    Drupal\inline_entity_form\ElementSubmit::doSubmit() (Line: 83)
    Drupal\inline_entity_form\ElementSubmit::trigger()
    call_user_func_array() (Line: 129)
    Drupal\Core\Form\FormSubmitter->executeSubmitHandlers() (Line: 67)
    Drupal\Core\Form\FormSubmitter->doSubmitForm() (Line: 597)
    Drupal\Core\Form\FormBuilder->processForm() (Line: 325)
    Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
    Drupal\Core\Controller\FormController->getContentResult() (Line: 39)
    Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult()
    call_user_func_array() (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
    Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
    Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 704)
    Drupal\Core\DrupalKernel->handle() (Line: 19)

  • Merge request !120Support adding new entities when translating โ†’ (Open) created by achap
  • Pipeline finished with Failed
    about 2 months ago
    Total: 435s
    #297676
  • Pipeline finished with Failed
    about 2 months ago
    Total: 495s
    #297682
  • Pipeline finished with Failed
    about 2 months ago
    Total: 677s
    #297695
  • Pipeline finished with Success
    about 2 months ago
    Total: 697s
    #297705
  • Pipeline finished with Success
    about 2 months ago
    Total: 510s
    #298543
  • achap ๐Ÿ‡ฆ๐Ÿ‡บ

    Looks like this patch was on the right path from #95 and then veered away from it. I strongly agree with #95 that we should be translating entities rather than changing their langcode as that is destructive and would confuse editors. I believe the fix in #52 might have been trying to address that but it may be redundant now. Also, it only prevents deleting entities used by the parent node but that could mean they are still deleted if referenced by other entities. Heavily based this MR off #95.

    Changes in MR 120:

    1) Inline entities are translated rather than having their language changed.
    2) Re-attached the submit handler from #95 that was removed and handled the case where the main entity form is submitted but the inline entity form hasn't been opened yet.
    3) Removed the deletion code that was trying to prevent entities being removed if referenced by the parent entity (I think that is probably better handled by something like entity_reference_integrity module). See above for reasons.
    4) Translations get their own created/updated timestamps when they are created rather than inheriting from the default translation. This helps them show up in the /admin/content view when the parent page is translated.
    5) Rename the testTranslation test to testSymmetricTranslation and added cases for translations and timestamps. Also created a new testAsymmetricTranslation test to test asymmetric behaviors which was more thorough than the previous behaviour.

    Feedback welcome.

    Regarding the comment in #127 the line number you indicated the error on doesn't match up with my MR so I don't think its related. Anyway I'm working on MR 120 now.

  • Pipeline finished with Success
    about 2 months ago
    Total: 670s
    #298559
  • Pipeline finished with Success
    about 2 months ago
    Total: 510s
    #298597
Production build 0.71.5 2024