Problem/Motivation

Since https://www.drupal.org/project/minikanban/issues/3529811 was merged, if a task has more than 1 attachment a php fatal error occurs when saving the task.

PHP Fatal error:  Nesting level too deep - recursive dependency? in /var/www/html/docroot/modules/contrib/minikanban/src/Entity/Task.php on line 166

Steps to reproduce

// Load files that already exist.
$file = \Drupal\file\Entity\File::load(1);
$file2 = \Drupal\file\Entity\File::load(2);

// Create a new task.
$mytask = \Drupal\minikanban\Entity\Task::create();

// Add the file to the task and save.
$mytask->get('attachments')->appendItem($file);
$mytask->get('attachments')->appendItem($file2);

// Should save, but generates a php fatal.
$mytask->save();

Proposed resolution

The above is caused due to the array_unique call in Task::preSave (line 166), as array_unique converts objects to strings to do the comparison.

Doing a uniqueness check on the file IDs rather than the file entities themselves should resolve this, but this would require ensuring that the files have already been saved before adding them to the attachments collection and I'm unsure if this is a safe assumption.

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork minikanban-3530491

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jeremyskinner created an issue. See original summary.

jeremyskinner’s picture

Title: PHP fatal recursion error when saving comments » PHP fatal recursion error when saving tasks with attachments
jeremyskinner’s picture

Title: PHP fatal recursion error when saving tasks with attachments » PHP fatal error when saving tasks with attachments
Issue summary: View changes
jeremyskinner’s picture

marcus_johansson’s picture

Assigned: Unassigned » marcus_johansson

marcus_johansson’s picture

Status: Active » Needs review

I changed to set the file id as array key, so we do not have to do a check if its unique. Then just get the array values when its saved.

jeremyskinner’s picture

Status: Needs review » Reviewed & tested by the community

There was a typo in the field name (attachements instead of attachments), which I've fixed and pushed to the fork.

marcus_johansson’s picture

Assigned: marcus_johansson » Unassigned
andrewbelcher’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.