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
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
Comment #2
jeremyskinner commentedComment #3
jeremyskinner commentedComment #4
jeremyskinner commentedComment #5
marcus_johansson commentedComment #7
marcus_johansson commentedI 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.
Comment #8
jeremyskinner commentedThere was a typo in the field name (attachements instead of attachments), which I've fixed and pushed to the fork.
Comment #9
marcus_johansson commentedComment #10
andrewbelcher commented