I can delete an entity browser even though a field is currently referencing it in its form display.

The entity browser entity should implement ConfigEntityInterface::calculateDependencies() and prevent this / warn that the field is going to be changed.

CommentFileSizeAuthor
#5 interdiff.txt792 bytesmarcoscano
#5 2807853-5.patch842 bytesmarcoscano
#3 2807853-3.patch1.6 KBmarcoscano

Comments

joachim created an issue. See original summary.

slashrsm’s picture

Category: Bug report » Task
Issue tags: +D8Media

I think that we should do it the other way around. Components that are using entity browsers should declare them as dependencies. Fields widgets that this module ships with are a good candidate it seems.

marcoscano’s picture

Status: Active » Needs review
StatusFileSize
new1.6 KB

Something like this?

Manually tested and it appears to work as expected, after this modification when deleting an entity browser being referenced, the confirmation screen is shown, indicating that the display settings on the node form will be updated.

Have a doubt though on the ->getSetting() call. Is it possible that this returns a non-empty but invalid value? (like an empty array or something like this) In this case it would be better to wrap this inside an !empty() check.

slashrsm’s picture

Status: Needs review » Needs work

Looks OK to me. Just a nitpik:

+++ b/src/Plugin/Field/FieldWidget/FileBrowserWidget.php
@@ -493,4 +493,19 @@ class FileBrowserWidget extends EntityReferenceBrowserWidget {
+  /**
+   * {@inheritdoc}
+   */
+  public function calculateDependencies() {
+    $dependencies = parent::calculateDependencies();

Since FileBrowserWidget extends EntityReferenceBrowserWidget we don't need to re-implement same logic again.

Have a doubt though on the ->getSetting() call. Is it possible that this returns a non-empty but invalid value? (like an empty array or something like this) In this case it would be better to wrap this inside an !empty() check.

You could try to load the entity browser to be sure. If this value is wrong there will be much more problems than just wrong dependencies though.

marcoscano’s picture

Status: Needs work » Needs review
StatusFileSize
new842 bytes
new792 bytes

True, sorry!

slashrsm’s picture

Status: Needs review » Fixed

Committed. Thanks!

  • slashrsm committed ccc949f on 8.x-1.x authored by marcoscano
    Issue #2807853 by marcoscano, slashrsm: Fields that are using Entity...

Status: Fixed » Closed (fixed)

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