Problem/Motivation

It would be nice to clear out contact message entities in bulk.

Proposed resolution

Maybe alter/change the views data handler for Message.

Remaining tasks

?

User interface changes

Yes, add some bulk ops to default view.

API changes

Views data handler changes.

Data model changes

Default view gets bulk ops.

CommentFileSizeAuthor
#33 interdiff-2693281-30-33.txt897 bytesnaveenvalecha
#33 2693281-33.patch22.35 KBnaveenvalecha
#32 interdiff-2693281-30-32.txt1.33 KBnaveenvalecha
#32 2693281-32.patch22.42 KBnaveenvalecha
#30 interdiff-2693281-27-30.txt512 bytesnaveenvalecha
#30 2693281-30.patch22.37 KBnaveenvalecha
#27 interdiff-2693281-23-27.txt459 bytesnaveenvalecha
#27 2693281-27.patch22.33 KBnaveenvalecha
#23 interdiff-2693281-19-23.txt2.19 KBnaveenvalecha
#23 2693281-23.patch22.32 KBnaveenvalecha
#21 interdiff-2693281-19-21.txt2.5 KBnaveenvalecha
#21 2693281-21.patch22.41 KBnaveenvalecha
#18 interdiff-2693281-15-18.txt3.22 KBnaveenvalecha
#18 2693281-18.patch22.23 KBnaveenvalecha
#15 2693281-15.patch21.58 KBnaveenvalecha
#13 interdiff-2693281-11-13.txt11.64 KBnaveenvalecha
#13 2693281-13.patch21.46 KBnaveenvalecha
#11 interdiff-2693281-10-11.txt579 bytesnaveenvalecha
#11 2693281-11.patch12.15 KBnaveenvalecha
#10 interdiff-2693281-7-10.txt9.91 KBnaveenvalecha
#10 2693281-10.patch12.17 KBnaveenvalecha
#7 interdiff-2693281-5-7.txt295 bytesnaveenvalecha
#7 2693281-7.patch15.07 KBnaveenvalecha
#5 2693281-5.patch15.09 KBnaveenvalecha
#2 2693281-1.png71.26 KBBambell
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mradcliffe created an issue. See original summary.

Bambell’s picture

FileSize
71.26 KB

That's a use case I encountered today, so I definitely agree. That's not so trivial, but I believe the best approach to this would be to add a "SELECT" column to the tables containing the forms / messages with a checkbox for each entity and a "Delete selected" button as well as a "Select all" button. A "Display per page" dropdown menu to select how many elements to display per page with an "All" option would also be needed.

Berdir’s picture

The bulk operations support is generic in views.

To get it for an entity type, all you need is to have actions (action plugin + action config entity). See how node.module defines the delete action plugin and the config entity for it. Define those, re-install the module and you should be able to add that to the view.

larowlan’s picture

Issue tags: +drupalcon, +sprint
naveenvalecha’s picture

give it a shot.
Questions :

1. will we make contact_form entity translatable ? any existing issue for it ? The translations has been taken care in DeleteMultiple message form as I have borrowed the code from DeleteMultiple node action form ?
2. What other actions do we need ?

Pending items :

1. Do we need the hook_post_update_NAME for views changes ?
2. Need tests.

The code is workable and it can be tested.

naveenvalecha’s picture

Status: Active » Needs review

let' s give the candy to testbot :)

naveenvalecha’s picture

naveenvalecha’s picture

Status: Needs review » Needs work

N/W for #5

jibran’s picture

Re #5 Questions:

  1. Let's keep this simple now. Message is not translatable so let's not make delete action translatable.
  2. I don't think there is any other action we can add at this point.

Re #5 Pending Items:

  1. We need an update hook to enable the action and then update the currently installed view to use this action.
  2. Always.

I think we should not add this action to current view to avoid upgrade path hassle for view. Just add the default action and enable it in update hook so that it'll be available as views field.

naveenvalecha’s picture

Status: Needs work » Needs review
FileSize
12.17 KB
9.91 KB

#9
1. Addressed, remove the translatable code from message deletion form.
2. Okay Thanks!

#5 Pending Items are still left. Leaving this open for others to pickup to work the pending stuff.I'll probably get back on this on tuesday.

naveenvalecha’s picture

larowlan’s picture

Issue tags: +Needs tests

Looking great, just some minor observations.
Only thing missing is some tests.

  1. +++ b/contact_storage.routing.yml
    @@ -0,0 +1,6 @@
    +    _permission: 'administer contact forms'
    

    We need to add this to our follow-up (in the queue around adding more permissions). Because deleting shouldn't need the uber-permission.

  2. +++ b/src/Form/DeleteMultiple.php
    @@ -0,0 +1,125 @@
    +      $this->privateTempStoreFactory->get('message_multiple_delete_confirm')->delete(\Drupal::currentUser()->id());
    

    We can inject the current user service too

  3. +++ b/src/Form/DeleteMultiple.php
    @@ -0,0 +1,125 @@
    +      drupal_set_message(\Drupal::translation()->formatPlural($count, 'Deleted 1 message.', 'Deleted @count messages.'));
    

    Nit: we could put this in a protected method to isolate it for when it gets deprecated.

naveenvalecha’s picture

Addressed #12.2, #12.3
#12.1, For permissions I'm working on a sandbox project here https://www.drupal.org/sandbox/naveenvalecha/2725179 I'll take care in the patch.

Addressed #5.2 Added tests
#5.1 can you elaborate little bit more.Do you mean to add/create the action config entity in hook_update ?

Status: Needs review » Needs work

The last submitted patch, 13: 2693281-13.patch, failed testing.

naveenvalecha’s picture

Status: Needs work » Needs review
FileSize
21.58 KB

Status: Needs review » Needs work

The last submitted patch, 15: 2693281-15.patch, failed testing.

jibran’s picture

Nice work @naveenvalecha.

  1. +++ b/contact_storage.post_update.php
    @@ -0,0 +1,23 @@
    +/**
    + * Enable the contact form delete multiple action
    + */
    +function contact_storage_post_update_enable_action() {
    +
    +}
    

    Let's make this an update hook and add the action to active config.
    Something like this

    @@ -125,5 +127,34 @@ function contact_storage_update_N() {
      $entity_type_manager = \Drupal::entityTypeManager();
    
      // Save the bulk delete action to config.
      $config_install_path = $module_handler->getModule('contact_storage')->getPath() . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
      $storage = new FileStorage($config_install_path);
      $entity_type_manager
        ->getStorage('action')
        ->create($storage->read('system.action.message_delete_action'))
        ->save();
    
  2. --- /dev/null
    +++ b/config/install/system.action.message_delete_action.yml
    

    Should it be named system.action or contact_storage.action?

  3. +++ b/src/Form/DeleteMultiple.php
    @@ -0,0 +1,140 @@
    +      return new RedirectResponse($this->getCancelUrl()->setAbsolute()->toString());
    

    I think this can be just Url object no need to convert it to string.

  4. +++ b/src/Form/DeleteMultiple.php
    @@ -0,0 +1,140 @@
    +      $this->logger('content')->notice('Deleted @count messages.', ['@count' => $count]);
    

    I think content logger is not correct logging service here.

  5. +++ b/src/Plugin/views/field/MessageBulkForm.php
    @@ -0,0 +1,21 @@
    +    return $this->t('No message selected.');
    

    Can we add a quick assert about this as well in the test?

naveenvalecha’s picture

Status: Needs work » Needs review
FileSize
22.23 KB
3.22 KB

#17.1
Added Thanks!
#17.2
It would be the system.action
#17.3
it should be string see https://github.com/symfony/http-foundation/blob/master/RedirectResponse....
#17.4
Used the contact logger.
#17.5
Added

jibran’s picture

Priority: Minor » Normal
Status: Needs review » Reviewed & tested by the community

This is ready imo. Thanks @naveenvalecha for addressing the feedback.

andypost’s picture

Just minor nits, could be fixed on commit

  1. +++ b/src/Form/DeleteMultiple.php
    @@ -0,0 +1,140 @@
    +    return $this->formatPlural(count($this->messages), 'Are you sure you want to delete this item?', 'Are you sure you want to delete these items?');
    ...
    +      drupal_set_message($this->stringTranslation->formatPlural($count, 'Deleted 1 message.', 'Deleted @count messages.'));
    

    inconsistency

  2. +++ b/src/Form/DeleteMultiple.php
    @@ -0,0 +1,140 @@
    +    $form = parent::buildForm($form, $form_state);
    +
    +    return $form;
    

    could be oneliner

naveenvalecha’s picture

Fixed nits mentioned in #20
Also fixed some of the docs.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 21: 2693281-21.patch, failed testing.

naveenvalecha’s picture

Status: Needs work » Needs review
FileSize
22.32 KB
2.19 KB
andypost’s picture

Status: Needs review » Reviewed & tested by the community

Now looks great for me! Thanx a lot @naveenvalecha

jibran’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/contact_storage.install
@@ -43,3 +46,19 @@ function _contact_storage_ensure_fields() {
+    ->create($storage->read('system.action.message_delete_action'))

We need an uninstall hook to remove this from active storage as well.

Berdir’s picture

No need for uninstall hook, just add an enforced config dependency on this module so it gets removed automatically.

http://drupal.stackexchange.com/questions/195173/delete-a-content-type-p... (works for all config entities)

naveenvalecha’s picture

Status: Needs work » Needs review
FileSize
22.33 KB
459 bytes

just add an enforced config dependency on this module so it gets removed automatically.

nice!, Enforced config dependency in system.action.message_delete_action

jibran’s picture

+++ b/config/install/system.action.message_delete_action.yml
@@ -2,7 +2,7 @@ langcode: en
+    - contact_storage

In my experience this doesn't work all the time. Can we add a test to verify that it really works?

Berdir’s picture

Status: Needs review » Needs work
+++ b/config/install/system.action.message_delete_action.yml
@@ -2,7 +2,7 @@ langcode: en
   module:
-    - contact
+    - contact_storage
 id: message_delete_action
 label: 'Delete message'

this is not an enforced dependency, it is a normal dependency. See the example I linked. You don't want to touch what is added automatically but add yours in enforced.

naveenvalecha’s picture

Status: Needs work » Needs review
FileSize
22.37 KB
512 bytes

reverted previous change in #27.
Addressed #29

#28,
I have seen at couple of places in core about the enforced config removal.

andypost’s picture

  1. +++ b/config/install/system.action.message_delete_action.yml
    @@ -0,0 +1,13 @@
    +  module:
    +    - contact
    
    +++ b/src/Plugin/Action/DeleteMessage.php
    @@ -0,0 +1,93 @@
    + *   id = "message_delete_action",
    

    action defined in contact_storage module so why it depends on contact?
    The enforced here is only for reason to uninstall this config when module uninstalled

  2. +++ b/src/Tests/BulkFormTest.php
    @@ -0,0 +1,78 @@
    +    'contact',
    ...
    +    'contact_storage',
    +    'views',
    

    contact_storage already depends on contact and views so I suppose they are not needed

naveenvalecha’s picture

#31.1 Moved the action dependency to contact_storage.
#31.2 yup, agree accommodated the changes accordingly.

naveenvalecha’s picture

ignore previous patch.

andypost’s picture

Now looks ready

andypost’s picture

Status: Needs review » Reviewed & tested by the community
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Fixed, thanks - rerolled on commit

Status: Fixed » Closed (fixed)

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

HongPong’s picture

How to delete multiple form submissions? VBO isn't available on D8 and I can't spot on documentation. Ah.. it's a view.

To this guy: /admin/structure/views/view/contact_messages
add field:
Contact message: Message operations bulk form (Message operations bulk form)
And save. Works. Becomes available as checkbox and a delete dropdown just as needed. Should probably get on the readme.