No operation delete for webform submissions in WebformBase

Created on 25 March 2024, 6 months ago
Updated 4 April 2024, 6 months ago

Problem/Motivation

In the WebformElementBase class you will find the following $operations array, giving you every possible operation except "delete". As a user I would like to have a webform element overriding the access handing for deleting a webform submission. In normal situation you would not need this, but It comes on handy when you are able to override the delete access rule for webform submissions.

File: src/Plugin/WebformElementBase.php

    $operations = [
      'create' => [
        '#title' => $this->t('Create submission'),
        '#description' => $this->t('Select roles and users that should be able to populate this element when creating a new submission.'),
        '#open' => TRUE,
      ],
      'update' => [
        '#title' => $this->t('Update submission'),
        '#description' => $this->t('Select roles and users that should be able to update this element when updating an existing submission.'),
        '#open' => FALSE,
      ],
      'view' => [
        '#title' => $this->t('View submission'),
        '#description' => $this->t('Select roles and users that should be able to view this element when viewing a submission.'),
        '#open' => FALSE,
      ],    
    ];

Proposed resolution

A simple code change would make it possible that someone could create a webform element and using an option to override the general access rule for delete. A use case would be for the webform_workflows_element module β†’

API changes

    $operations = [
      'create' => [
        '#title' => $this->t('Create submission'),
        '#description' => $this->t('Select roles and users that should be able to populate this element when creating a new submission.'),
        '#open' => TRUE,
      ],
      'update' => [
        '#title' => $this->t('Update submission'),
        '#description' => $this->t('Select roles and users that should be able to update this element when updating an existing submission.'),
        '#open' => FALSE,
      ],
      'view' => [
        '#title' => $this->t('View submission'),
        '#description' => $this->t('Select roles and users that should be able to view this element when viewing a submission.'),
        '#open' => FALSE,
      ],    
      'delete' => [
        '#title' => $this->t('Delete submission'),
        '#description' => $this->t('Select roles and users that should be able to delete this element when deleting a submission.'),
        '#open' => FALSE,
      ],    
    ];
πŸ“Œ Task
Status

Closed: won't fix

Version

6.2

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom globexplorer

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @globexplorer
  • πŸ‡¬πŸ‡§United Kingdom globexplorer
  • Status changed to Needs review 6 months ago
  • Open on Drupal.org β†’
    Core: 10.1.4 + Environment: PHP 8.2 & MySQL 8
    last update 6 months ago
    Waiting for branch to pass
  • Status changed to Closed: won't fix 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY

    This change does not make sense to me.

    The create, view, update operations apply when a webform element is displayed on a submission, create, update, or view form/page. There is no use case for hiding/showing an element when a submission is being deleted.

    If there is a custom use for an element's delete operation it should be handled via custom code or dedicated contrib module.

Production build 0.71.5 2024