calculateDependencies doesn't check $mode_entity if it is NULL

Created on 2 June 2016, over 8 years ago
Updated 5 March 2024, 8 months ago

Problem/Motivation

1. Created a feature exporting user field settings with the contributed D8 feature module
2. Various changes to the user fields
3. Incorporating my colleagues various changes into my repo
4. Running drush features-import produced this error:

[derp@der[ public]$ drush fia -y
Reverting Base User...
PHP Fatal error:  Call to a member function getConfigDependencyName() on null in /var/www/vhosts/derp.dev/releases/herp/public/core/lib/Drupal/Core/Entity/EntityDisplayBase.php on line 274
Drush command terminated abnormally due to an unrecoverable error

Proposed resolution

Wrap the add Dependency method call on line 274 with a quick !empty check

Remaining tasks

User interface changes

API changes

Data model changes

Original report by generalconsensus

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
EntityΒ  β†’

Last updated about 4 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States generalconsensus

Live updates comments and jobs are added and updated live.
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.

  • The Needs Review Queue Bot β†’ tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • Status changed to Needs review almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States bnjmnm Ann Arbor, MI
  • Status changed to Needs work almost 2 years ago
  • Thank you for this patch but I think it is actually not necessary to throw an exception for this issue.

    I think it is not relevant to fail in EntityDisplayBase::calculateDependencies() because it breaks the saving of a new display.

    Here is an example:

    function create_a_new_display_programatically() {
      $entity_type_id = 'block_content';
      $bundle_id = 'basic';
      $view_mode_id = 'teaser';
      $entity_display_repository = \Drupal::service('entity_display.repository');
    
      // This method tries to load the view mode and if not found, creates it but not saved yet.
      $display = $entity_display_repository->getViewDisplay($entity_type_id, $bundle_id, $view_mode_id);
    
      // Should be successful but actually throws the ConfigEntityDependencyException.
      // It became impossible to programmatically create a new entity display with this exception being thrown.
      return $display->save();
    }
    

    Not sure what the best approach is but we should find a way to allow saving of new display and calculating dependencies without throwing exception.

  • πŸ‡¬πŸ‡§United Kingdom rivimey

    Sounds like two actions are needed:
    1. add (a version of) the code in #44 as a test case, coupled with other rational variations if any.

    2. update the patch to permit (1) to be run, i.e. creating display programmatically.

    For (2) I suggest replacing the new 'throw' with setting a flag on the EntityDIsplayBase object signalling that dependencies are out of date, and then on save() if the flag is set then update the dependencies and _at that time_ throw the exception, as I would expect by then everything to exist.

    If this doesn't work I'm somewhat stumped - the exception is thrown when the entity display for this display mode can't be loaded, so in what circumstances is it ok to have a display config referencing an unloadable mode config?

  • last update about 1 year ago
    Patch Failed to Apply
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    #43 sadly doesn't apply anymore on D10.1.2

  • Merge request !6920Applied 2741429-43.patch β†’ (Open) created by Anybody
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Rerolled #43 against 11.x as MR.

    @matthieuscarset @rivimey I think we should then proceed there instead of patches.

  • Pipeline finished with Success
    8 months ago
    Total: 628s
    #111951
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    MR!6920 as patch file against 11.x (based on #43)

  • Merge request !6923Applied patch #43 β†’ (Open) created by Anybody
  • Pipeline finished with Failed
    8 months ago
    Total: 171s
    #111970
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Anybody β†’ changed the visibility of the branch 2741429-calculate-dependencies-doesnt-check-mode-entity-10.3.x to hidden.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Static patch from MR!6923 for Drupal 10.2.x attached!

  • Pipeline finished with Failed
    8 months ago
    Total: 598s
    #111971
Production build 0.71.5 2024