Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Berdir’s picture

Issue summary: View changes
Issue tags: +Entity Field API, +Novice

Should be as easy as adding #access => $entity->access('delete') for the delete form submit element?

sandipmkhairnar’s picture

First drafted patch.

sandipmkhairnar’s picture

Status: Active » Needs review
Berdir’s picture

You should be able to use $this->entity, this is already done in actionsElement()

sandipmkhairnar’s picture

Ohhhh....Thanks Berdir for comment. Updated patch as per comment.

sandipmkhairnar’s picture

Assigned: Unassigned » sandipmkhairnar

Status: Needs review » Needs work

The last submitted patch, 5: set-delete-access-2084323-5.patch, failed testing.

The last submitted patch, 2: set-delete-access-2084323-2.patch, failed testing.

sandipmkhairnar’s picture

Status: Needs work » Needs review
Berdir’s picture

$this->entity->access(), not $this->access()

Status: Needs review » Needs work

The last submitted patch, 5: set-delete-access-2084323-5.patch, failed testing.

The last submitted patch, 5: set-delete-access-2084323-5.patch, failed testing.

sandipmkhairnar’s picture

updated patch.

sandipmkhairnar’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 13: set-delete-access-2084323-13.patch, failed testing.

sandipmkhairnar’s picture

Berdir’s picture

Status: Needs work » Needs review
Issue tags: -Novice
FileSize
1.13 KB

Awww, bad contact message entity :)

tim.plunkett’s picture

+++ b/core/lib/Drupal/Core/Entity/EntityFormController.php
@@ -247,6 +247,7 @@ protected function actions(array $form, array &$form_state) {
+        '#access' => $this->entity->access('delete'),

In actionsElement, we have

  // We cannot delete an entity that has not been created yet.
    if ($this->entity->isNew()) {
      unset($element['delete']);
    }

Either that should be moved here, or this should be moved there. But not both please.

Berdir’s picture

Xano’s picture

FileSize
2.39 KB
1.22 KB

Discussed this change with Berdir and it makes sense to let the entity access controller deny delete access in general if the entity is new.

tim.plunkett’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

This should have been reproducible with NodeType, except it explicitly added checks in NodeTypeFormController::actions().

I think we can delete that line, and write a test for it that fails without this fix.

Berdir’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
10.38 KB
7.99 KB

Ah, great hint, made me go through our form controllers and it turns out that a ton of them manually check delete access, so a lot of custom overrides that we can remove.

A number of them remove the delete button unconditionally, like date format edit and actions edit, didn't touch them.

Also added the test coverage, found a place where it nicely fit in I think.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Beautiful! Thanks.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 22: drupal_2084323_22.patch, failed testing.

Jalandhar’s picture

Status: Needs work » Needs review
FileSize
10.4 KB

Updating the patch with re-roll. Please review.

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

Re-roll looks good, thanks.

catch’s picture

25: drupal8-2084323-25.patch queued for re-testing.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 25: drupal8-2084323-25.patch, failed testing.

Berdir’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
10.34 KB

git rebase re-roll, shortcut files were moved.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 29: drupal8-2084323-29.patch, failed testing.

Berdir’s picture

Status: Needs work » Needs review

29: drupal8-2084323-29.patch queued for re-testing.

catch’s picture

Status: Needs review » Reviewed & tested by the community

Back to green.

Berdir’s picture

Yes, previous fail was a bot hickup (the "failed to create directory" kind of fails)

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 29: drupal8-2084323-29.patch, failed testing.

Berdir’s picture

Status: Needs work » Needs review
FileSize
10.34 KB

Re-roll, but let's get #2238077: Rename EntityFormController to EntityForm in first.

Note that delete is now a link, but we can still control access for the link...

Status: Needs review » Needs work

The last submitted patch, 35: drupal8-2084323-35.patch, failed testing.

Berdir’s picture

Status: Needs work » Needs review
FileSize
8.93 KB
1.04 KB

Re-roll, fixed the node type tests now that the label is different and is a link. Reverted changes to ProfileForm (not in interdiff), #216064: Entity form "Delete" button triggers server-side + HTML5 form validation; change "Delete" button to a link messed that up, as it is now no longer there by default as it's only added if there's a delete-form, so it's defines a new form element. Opened #2250377: ProfileForm::actions() defines new delete element instead of altering it as it expects.

Xano’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

tim.plunkett’s picture

Title: EntityFormController::actions() adds 'delete' without checking access » EntityForm::actions() adds 'delete' without checking access
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.x, thanks!

  • Commit 5c2dc50 on 8.x by catch:
    Issue #2084323 by Berdir, sandipmkhairnar, Xano, Jalandhar: EntityForm::...

Status: Fixed » Closed (fixed)

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