Problem/Motivation

Custom blocks are now publishable, but the Custom block library page (/admin/structure/block/block-content) doesn't not reflect this change. Since the custom blocks as publish-able, make the UI close to node admin page (/admin/content):

This work was started In #2834546: UI for publishing/unpublishing block_content blocks, but it was decided to split the changes to block_content view and related into a follow up issue, because this requires an upgrade path.#2834546: UI for publishing/unpublishing block_content blocks should be committed before this issue gets in.

Proposed resolution

Introduce below changes:
1. Bulk operation form
2. Add published column
3. Add publish status filter

and write the upgrade path in this issue.

Remaining tasks

- Implementation - Done
- Manual testing - Done
- More reviews
- Commit!

User interface changes

Adds a bulk publish / unpublish actions and a new "published" column to the Custom block library page /admin/structure/block/block-content

API changes

None

Data model changes

None

CommentFileSizeAuthor
#106 2909435-diff-104-106.txt221.28 KBvijaycs85
#106 2909435-106.patch247.25 KBvijaycs85
#104 2909435-104.patch25.92 KBManuel Garcia
#104 interdiff-2909435-97-104.txt2.66 KBManuel Garcia
#100 views.view_.block_content.yml.txt13.32 KBvijaycs85
#97 2909435-97.patch24.32 KBManuel Garcia
#94 2909435-94.patch25.51 KBManuel Garcia
#90 2909435-diff-88-90.txt1.26 KBvijaycs85
#90 2909435-90.patch25.62 KBvijaycs85
#88 2909435-88.patch25.02 KBManuel Garcia
#88 interdiff-2909435-87-88.txt765 bytesManuel Garcia
#87 2909435-87.patch24.9 KBManuel Garcia
#87 interdiff-2909435-86-87.txt1.54 KBManuel Garcia
#86 2909435-86.patch24.6 KBManuel Garcia
#80 2909435-80.patch24.6 KBManuel Garcia
#80 interdiff-2909435-75-80.txt712 bytesManuel Garcia
#75 2909435-75.patch24.6 KBManuel Garcia
#75 reroll-diff-2909435-71-75.txt1.5 KBManuel Garcia
#71 2909435-71.patch24.57 KBchr.fritsch
#68 2909435-68.patch24.52 KBManuel Garcia
#66 2909435-66.patch24.51 KBchr.fritsch
#60 2909435-60.patch24.52 KBManuel Garcia
#60 interdiff-2909435-58-60.txt4.4 KBManuel Garcia
#58 2909435-58.patch24.47 KBManuel Garcia
#58 interdiff-2909435-54-58.txt3.37 KBManuel Garcia
#54 2909435-54.patch26.67 KBManuel Garcia
#54 interdiff-2909435-50-54.txt3.36 KBManuel Garcia
#52 2909435-52-one-published-via-bulk-operation.png246.34 KBvijaycs85
#52 2909435-52-both-unpublished.png180.19 KBvijaycs85
#52 2909435-52-both-published.png316.18 KBvijaycs85
#52 2909435-52-observation-list-page.png148.74 KBvijaycs85
#52 2909435-52-observation-revision.png185.05 KBvijaycs85
#52 2909435-52-updb.png64.09 KBvijaycs85
#50 2909435-50.patch26.71 KBManuel Garcia
#50 interdiff-2909435-48-50.txt950 bytesManuel Garcia
#48 2909435-48.patch26.7 KBManuel Garcia
#48 interdiff-2909435-46-48.txt1.96 KBManuel Garcia
#46 2909435-46.patch26.81 KBManuel Garcia
#46 interdiff-2909435-44-46.txt844 bytesManuel Garcia
#44 2909435-44.patch26.74 KBManuel Garcia
#44 interdiff-2909435-40-44.txt11.26 KBManuel Garcia
#40 2909435-40.patch24.56 KBManuel Garcia
#40 interdiff-2909435-39-40.txt816 bytesManuel Garcia
#39 2909435-39.patch24.59 KBManuel Garcia
#39 interdiff-2909435-37-39.txt1.81 KBManuel Garcia
#37 2909435-37.patch24.68 KBManuel Garcia
#37 interdiff-2909435-34-37.txt11.56 KBManuel Garcia
#34 2909435-34.patch24.1 KBManuel Garcia
#34 interdiff-2909435-31-34.txt749 bytesManuel Garcia
#31 2909435-31.patch24.1 KBManuel Garcia
#31 interdiff-2909435-23-31.txt4.28 KBManuel Garcia
#23 2909435-23.patch19.82 KBManuel Garcia
#23 interdiff-2909435-19-23.txt5.31 KBManuel Garcia
#20 Screenshot from 2018-01-28 18-20-02.png19.36 KBManuel Garcia
#19 interdiff-18-19.txt5.58 KBgnuschichten
#19 2909435-19.patch19.53 KBgnuschichten
#18 Screenshot from 2018-01-26 16-21-39.png54.55 KBManuel Garcia
#18 2909435-18.patch18.07 KBManuel Garcia
#18 interdiff-2909435-16-18.txt5.68 KBManuel Garcia
#16 2909435-16.patch12.39 KBManuel Garcia
#16 interdiff-2909435-13-16.txt728 bytesManuel Garcia
#13 2909435-14.patch13.11 KBManuel Garcia
#13 interdiff-2909435-4-14.patch2.81 KBManuel Garcia
#8 2909435.png455.48 KBvijaycs85
#4 2909435-4.patch14.64 KBManuel Garcia
#2 2909435-2.patch14.6 KBManuel Garcia
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Manuel Garcia created an issue. See original summary.

Manuel Garcia’s picture

Status: Active » Needs review
FileSize
14.6 KB

Here the part of the patch that we've split off of #2834546: UI for publishing/unpublishing block_content blocks

Quoting @dawehner on there (comment #52):

The update path should update individual bits of the view, aka. set the additional field and add the filters instead of replacing the entire view.
The update path test should then test some basic behaviour of the view.

Status: Needs review » Needs work

The last submitted patch, 2: 2909435-2.patch, failed testing. View results

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
14.64 KB
jibran’s picture

Title: Enhance Custom block library page now that custom blocks are publishable » Add bulk form operations to custom block library page
Category: Feature request » Task
jibran’s picture

Status: Needs review » Needs work
--- /dev/null
+++ b/core/modules/block_content/config/install/system.action.block_content_publish_action.yml

--- /dev/null
+++ b/core/modules/block_content/config/install/system.action.block_content_unpublish_action.yml

Let's add delete action as well.

Manuel Garcia’s picture

Re #6

Let's add delete action as well.

While I totally agree this would be useful to have, is this in scope? Only reason I could agree on that is to avoid having to write two upgrade paths & tests.

Also, this patch is not only adding bulk operations, it is also adding a Published column to the view, so the title is not reflecting the intention here (which is to adjust the page to the fact that custom blocks are now publishable.).

vijaycs85’s picture

Title: Add bulk form operations to custom block library page » Update block library page to adapt publishable block content implementation
Issue summary: View changes
FileSize
455.48 KB

Probably we have to make changes to reflect the changes in IS (just added) as part of this ticket.

chr.fritsch’s picture

Please don't implement your own action plugins. Better wait and push #2916740: Add generic entity actions and #2670730: Provide a delete action for each content entity type

Manuel Garcia’s picture

Status: Needs work » Postponed

Ow very cool @chr.fritsch!

I say we postpone this until that gets in, and then clean up the patch here.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

chr.fritsch’s picture

Status: Postponed » Needs work

Unpostponed since #2916740: Add generic entity actions landed

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
2.81 KB
13.11 KB

Brilliant, here is #4 making use of the generic entity actions.

chr.fritsch’s picture

Nice one 👏

#2670730: Provide a delete action for each content entity type is really close, so should a delete action implemented here as well?

chr.fritsch’s picture

Status: Needs review » Needs work
+++ b/core/modules/block_content/config/schema/block_content.schema.yml
@@ -16,3 +16,11 @@ block_content.type.*:
+
+action.configuration.block_content_publish_action:
+  type: action_configuration_default
+  label: 'Publish selected block content configuration'
+
+action.configuration.block_content_unpublish_action:
+  type: action_configuration_default
+  label: 'Unpublish selected block content configuration'

Could also be deleted

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
728 bytes
12.39 KB

Addressing #15.

Re #14 I think we could do that for all entities that have this bulk form as a follow up once that #2670730: Provide a delete action for each content entity type has landed. This issue's scope is only to deal with publish/unpublish. That said, if it lands quickly, it'd be simple enough to expand the scope here. Whatever the committers prefer I suppose, either way is fine with me.

chr.fritsch’s picture

Delete actions are in.

Manuel Garcia’s picture

Here is a start on the upgrade path. I'm not sure if this is the right way to go about it.

It currently has two problems:
1. The order of the fields is not set properly.
2. The actions are not showing up as even selectable in the UI.

Please have a look at the screenshot to see the problems, taken after a fresh install of 8.6.x, applying #16, and running the update hook.

gnuschichten’s picture

I have added the bulk actions to the install process and move bulk selections fields to the top.

Manuel Garcia’s picture

Status: Needs review » Needs work
FileSize
19.36 KB

Brilliant thanks @gnuschichten!
I tested the patch, and the bulk operations show up, in the right place, and fully working - we're getting close here!

One thing we still need to fix in the upgrade path is the order of the Published field, since it isn't showing up in the right place yet (see screenshot) - setting to needs work for that, and the tests we'll need to add here.

tstoeckler’s picture

Status: Needs work » Needs review

I also considered now that #2670730: Provide a delete action for each content entity type is in, whether we should also add a "Delete" action to the Custom block library. Theoretically it could be considered out of scope, but since this already contains an upgrade path to enable the bulk form, this would just be another action we would have to add as part of the upgrade path. Thoughts?

tstoeckler’s picture

Status: Needs review » Needs work
Issue tags: -Needs update path

Oops, didn't mean to change the status. Also removing "Needs update path" tag, as that seems to be part of the patch by now.

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
5.31 KB
19.82 KB

Addressing the position of the published field in the update path. With this, I believe the update path to be done.

Now we just need the update path tests.

I am opened to including here a delete operation @tstoeckler, however we are not just adding bulk operations to this view, we are also adding the published field, so not sure what the title should be of this issue if we include the delete operation... Happy to do it here, but I'd like a committer to agree to this before putting in the time to do it.

Status: Needs review » Needs work

The last submitted patch, 23: 2909435-23.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

chr.fritsch’s picture

  1. +++ b/core/modules/block_content/block_content.install
    @@ -138,3 +138,236 @@ function block_content_update_8400() {
    +function block_content_update_8600() {
    

    I think this should be done in a post_update hook where we are able to use the full API

  2. +++ b/core/modules/block_content/block_content.install
    @@ -138,3 +138,236 @@ function block_content_update_8400() {
    +  $publish_action = \Drupal::service('config.factory')->getEditable('system.action.block_content_publish_action');
    +  $config_data_publish = [
    +    "langcode" => "en",
    +    "status" => true,
    +    "dependencies" => [
    +      "module" => [
    +          "block_content"
    +        ]
    +    ],
    +    "id" => "block_content_publish_action",
    +    "label" => "Publish block content",
    +    "type" => "block_content",
    +    "plugin" => "entity:publish_action:block_content",
    +    "configuration" => []
    +  ];
    +  $publish_action->setData($config_data_publish);
    +  $publish_action->save();
    

    Not sure about writing the complete config object here again. May we could do something like this:

    $value = $this->extensionConfigStorage->read($full_name);
    
    $entity_storage = $this->entityManager->getStorage($type);
    $entity = $entity_storage->createFromStorageRecord($value);
    $entity->save();
    

    This code block is copied from config_update module.

tstoeckler’s picture

Status: Needs work » Needs review

Re #25: Generally we try to avoid reading runtime information during updates, because you don't know when they will be run. I.e. some system may not run the update until months/years later when the runtime information (in this case the block library view) has changed again. That is definitely the case for normal (non-post-)update functions. I can see how it is less relevant for post-updates, but I haven't seen something like #25 in core before. Maybe someone more into the update system (@alexpott ?!) can clarify.

In general though I think you are absolutely correct that this makes sense to do in a post-update.

tstoeckler’s picture

Status: Needs review » Needs work

Tss... somehow my browser reeallly thinks this issue needs review... sorry for the noise.

Manuel Garcia’s picture

Status: Needs work » Needs review

Thanks guys for taking the time to review this!

The change to needs work was done by the bot who had a test failure unrelated to this patch. #23 is passing so changing back to needs review.

Last night I started to do the update as described in #25, but made little progress. What @tstoeckler argues in #26 makes a lot of sense though, so I will stop that work and leave the patch as is for now.

amateescu’s picture

Loading, updating and then saving views in a post update function has proven to be problematic (see #2917006: Views referencing missing roles fail views_post_update_revision_metadata_fields(), which is being caused by the upgrade path added in #2248983: Define the revision metadata base fields in the entity annotation in order for the storage to create them only in the revision table) because some views might be in a broken state and as a consequence they can not be saved via the (config) entity API.

So the patch from #23 is correct on both points from #25:
- it updates the views config files directly using a regular update function
- it doesn't use runtime information for generating the action config entities

Manuel Garcia’s picture

Status: Needs review » Needs work

Thanks @amateescu that settles it I think then. Setting the status to Needs work for the update path tests.

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
4.28 KB
24.1 KB

Here's the update path test, let me know what you think :)

Manuel Garcia’s picture

andypost’s picture

Manuel Garcia’s picture

Thanks for RTBCing, just noticed a small mistake on an assertion message of the update path test, fixing it here.

Manuel Garcia’s picture

There was mention in this conversation of using this patch to also add the delete action that is now also available, because we already have an update path (and doing this as a follow up would require another update path). See #6 #14 and #21. I have left this out for now because I feel that's not in scope for this issue (we are not just adding actions, but a Published exposed filter and a Published column to the table).

I leave this to the maintainers to decide on whether to do it here or as a follow up. Happy to work on it whichever way.

amateescu’s picture

The patch looks great to me! I just found a few nitpicks :)

  1. +++ b/core/modules/block_content/block_content.install
    @@ -138,3 +138,236 @@ function block_content_update_8400() {
    +      'exclude' => false,
    ...
    +        'word_boundary' => true,
    

    We need to convert all the lowercase true and false to uppercase :)

  2. +++ b/core/modules/block_content/block_content.install
    @@ -138,3 +138,236 @@ function block_content_update_8400() {
    +      'id' => 'status',
    ...
    +    'id' => 'status',
    ...
    +  $view->set('display.default.display_options.filters.status', $status_filter);
    

    Let's try to avoid a conflict with a possible pre-existing status field or filter, and use ViewExecutable::generateHandlerId() to generate the views handler ID. You can see an example of that in the interdiff from #2880149-115: Convert taxonomy terms to be revisionable.

  3. +++ b/core/modules/block_content/tests/src/Functional/Update/BlockContentUpdateTest.php
    @@ -66,4 +67,75 @@ public function testStatusFieldAddition() {
    +    $edit =[];
    ...
    +    $edit =[];
    ...
    +    $edit =[];
    ...
    +    $edit =[];
    

    Coding standards nit, we need a space before [].

  4. +++ b/core/modules/block_content/block_content.install
    @@ -138,3 +138,236 @@ function block_content_update_8400() {
    +function block_content_update_8600() {
    +
    +  $view = \Drupal::service('config.factory')->getEditable('views.view.block_content');
    

    No need for this blank line.

  5. +++ b/core/modules/block_content/tests/src/Functional/Update/BlockContentUpdateTest.php
    @@ -66,4 +67,75 @@ public function testStatusFieldAddition() {
    +    $user =  $this->drupalCreateUser(['administer blocks', 'administer block_content display']);
    

    Extra space here after =.

  6. +++ b/core/modules/block_content/tests/src/Functional/Update/BlockContentUpdateTest.php
    @@ -66,4 +67,75 @@ public function testStatusFieldAddition() {
    +    $this->drupalPostForm('block/add/basic', $edit, t('Save'));
    ...
    +    $this->drupalPostForm('admin/structure/block/block-content', $edit, t('Apply to selected items'));
    ...
    +    $this->drupalPostForm('admin/structure/block/block-content', $edit, t('Apply'));
    ...
    +    $this->drupalPostForm('admin/structure/block/block-content', $edit, t('Apply'));
    

    We don't need to use t() in tests :)

Manuel Garcia’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
11.56 KB
24.68 KB

Thank you so much for the review @amateescu!
Addressing #36 here.

amateescu’s picture

Nice! Just a few things left:

  1. +++ b/core/modules/block_content/block_content.install
    @@ -138,3 +139,238 @@ function block_content_update_8400() {
    +  $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
    +  $entity_type = $definition_update_manager->getEntityType('block_content');
    

    Since you are not using $definition_update_manager again in this function, these two lines can be merged into one :)

  2. +++ b/core/modules/block_content/block_content.install
    @@ -138,3 +139,238 @@ function block_content_update_8400() {
    +      'id' => ViewExecutable::generateHandlerId($published_key, $view->get("display.default.display_options.fields")),
    

    You can use the $fields variable defined above instead of getting it again from the config object.

  3. +++ b/core/modules/block_content/block_content.install
    @@ -138,3 +139,238 @@ function block_content_update_8400() {
    +      'entity_field' => 'status',
    ...
    +    'entity_field' => 'status',
    

    You can use $published_key here as well.

Manuel Garcia’s picture

Thanks again @amateescu - all good points. Addressing #38 here :)

Manuel Garcia’s picture

Actually addressing #38.1 properly...

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

I don't have anything else to complain about :)

Manuel Garcia’s picture

plach’s picture

Status: Reviewed & tested by the community » Needs work

Overall this is looking great, however it seems we are lacking explicit test coverage for the bulk operations we are adding. Actually, we have it in the update test but not in BlockContentListViewsTest. Maybe we could add a trait to perform the same assertions in both places?

I think deferring bulk deletion to a follow-up is a good idea, we can modify the logic in block_content_update_8600() to cover also that, as long as this happens before 8.6.0 is released.

Aside from that, here's a code review, mostly nitpicks:

  1. +++ b/core/modules/block_content/block_content.install
    @@ -138,3 +139,236 @@ function block_content_update_8400() {
    +  $fields_to_set = array_merge(array_slice($combined_fields, 0, $position), $status, array_slice($combined_fields, $position));
    

    Can't we just use array_splice width length 0 here?

  2. +++ b/core/modules/block_content/block_content.install
    @@ -138,3 +139,236 @@ function block_content_update_8400() {
    +      "module" => [
    +          "block_content"
    +        ]
    

    Wrong indentation.

    There are also quite a few missing trailing commmas. It would be nice to fix them for consistency :)

  3. +++ b/core/modules/block_content/tests/src/Functional/Update/BlockContentUpdateTest.php
    @@ -66,4 +67,75 @@ public function testStatusFieldAddition() {
    +    $this->assertText('Yes', "Block displayed as published");
    

    Not a huge fan of raw-asserting yes/no this way: it feels fragile. Can we use xpath with some more specific selector instead?

    Also, we're mixing quote types here :)

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
11.26 KB
26.74 KB

Thanks @plach for the review, all good points.

Introducing here the new trait, please have a look. Hopefully I'm on the right track as to what you meant here, also, naming things is hard :)

#43.1 Always thought that was a bit of a mess, and your suggestion is much cleaner, thanks.
#43.2 Fixed, cleaned up everything I saw.
#43.3 Good point, re-factored that into a method on the new trait, using xpath.

Besides this, I also added test coverage for the status filter to BlockContentListViewsTest, and avoided using calls to deprecated methods on the update test.

Status: Needs review » Needs work

The last submitted patch, 44: 2909435-44.patch, failed testing. View results

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
844 bytes
26.81 KB

It appears that array_splice does not preserve the keys from the replacement array. Quoting the PHP documentation page:

Note that keys in replacement array are not preserved.

Indeed, if you do this:

$input = array("red" => "red", "green" => "green", "blue" => "blue", "yellow" => "yellow");
array_splice($input, 3, 0, array("purple" => "purple"));

Then $input becomes:

Array
(
    [red] => red
    [green] => green
    [blue] => blue
    [0] => purple
    [yellow] => yellow
)

Which is what seems to be happening now on block_content_update_8600.

Reverting here to what we had before.

Status: Needs review » Needs work

The last submitted patch, 46: 2909435-46.patch, failed testing. View results

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
1.96 KB
26.7 KB

When we use the publish actions the status filter gets reset, causing the failures on #46. This should hopefully fix it.

Status: Needs review » Needs work

The last submitted patch, 48: 2909435-48.patch, failed testing. View results

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
950 bytes
26.71 KB

Test was failing on the xpath selector, because the update test uses bartik, and BlockContentListViewsTest doesn't. Let's see if this selector does the trick. It's more specific so it should be less fragile I believe.

Manuel Garcia’s picture

Awesome, back to green :D

I wanted to note that the first version of this patch was split off of #2834546: UI for publishing/unpublishing block_content blocks, and that other people worked on it as well. Imho they should be credited here too, timmillwood, amateescu, and possibly others for their helpful reviews.

vijaycs85’s picture

Manual testing
Existing site
  1. Installed 8.6.x HEAD without patch
  2. Applied patch (from #50)
  3. Ran drush updb(screenshot )
  4. Created two blocks and placed them in sidebar first
  5. Bulk publish/unpublish works as expected(both published, both unpublished and one published via bulk operation)
Fresh install with patch
  1. Installed 8.6.x HEAD with patch
  2. Followed step 4 and 5 as per existing site instructions above and produced same results.
Other observations

1. Revision tab looks bit weird when checkbox is not ticked. screenshot
2. Labels and fields have mismatch with content list page. screenshot

We might not able to address them in this issue, just adding here to discuss.

Code review
  1. +++ b/core/modules/block_content/tests/src/Functional/BlockContentTestBulkOperationsTrait.php
    @@ -0,0 +1,45 @@
    +trait BlockContentTestBulkOperationsTrait {
    

    nice!

  2. +++ b/core/modules/block_content/tests/src/Functional/BlockContentTestBulkOperationsTrait.php
    @@ -0,0 +1,45 @@
    +  protected function assertUnpublishUsingBulkAction() {
    ...
    +  protected function assertPublishUsingBulkAction() {
    

    Minor: these assert methods are doing bit more than just asserting. they are doing certain action and asserting.

  3. +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php
    @@ -78,7 +78,7 @@ protected function getEntityCounts() {
    -      'action' => 23,
    +      'action' => 25,
    
    +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php
    @@ -78,7 +78,7 @@ protected function getEntityCounts() {
    -      'action' => 17,
    +      'action' => 19,
    

    Not sure, if they are automated update. if not, feels irrelevant to this issue.


Over all, Big +1 to RTBC!
vijaycs85’s picture

Issue summary: View changes
Manuel Garcia’s picture

Thank you @vijaycs85 for the manual testing, issue summary updates and suggestions.

#52.2 You're right, renaming those here.
#52.3 - That was introduced to the patch on https://www.drupal.org/project/drupal/issues/2834546#comment-12246154 - otherwise those tests fail with these changes.

vijaycs85’s picture

@Manuel Garcia #54 looks good to me. +1 to RTBC.

chr.fritsch’s picture

+++ b/core/modules/block_content/src/Plugin/views/field/BlockContentBulkForm.php
@@ -0,0 +1,21 @@
+<?php
+
+namespace Drupal\block_content\Plugin\views\field;
+
+use Drupal\system\Plugin\views\field\BulkForm;
+
+/**
+ * Defines a block content operations bulk form element.
+ *
+ * @ViewsField("block_content_bulk_form")
+ */
+class BlockContentBulkForm extends BulkForm {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function emptySelectedMessage() {
+    return $this->t('No block content selected.');
+  }
+
+}

Do we really need that? We didn't add one for media recently as well. And with #2909423: Get rid of BulkForm subclasses when they just override emptySelectedMessage we would get a nicer message and would have to deprecate this class again.

vijaycs85’s picture

#56 +1

Manuel Garcia’s picture

Re #56 you're absolutely right, we do not need this now that #2909423: Get rid of BulkForm subclasses when they just override emptySelectedMessage is getting close.

So removing that and all the things that implied, which brings down the patch size a bit. Thanks @chr.fritsch!

amateescu’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/block_content/block_content.install
    @@ -138,3 +139,236 @@ function block_content_update_8400() {
    +  $view->save();
    ...
    +  $publish_action->save();
    ...
    +  $unpublish_action->save();
    

    We should pass TRUE here to signal the fact that we're dealing with trusted data.

  2. +++ b/core/modules/block_content/tests/src/Functional/BlockContentListViewsTest.php
    @@ -10,6 +10,7 @@
     class BlockContentListViewsTest extends BlockContentTestBase {
    +  use BlockContentTestBulkOperationsTrait;
    

    Could use an empty line :)

  3. +++ b/core/modules/block_content/tests/src/Functional/BlockContentListViewsTest.php
    @@ -67,13 +68,27 @@ public function testListing() {
    +    $this->assertEqual(count($elements), 6, 'Correct number of table row cells found.');
    

    We could use assertCount() here.

  4. +++ b/core/modules/block_content/tests/src/Functional/BlockContentTestBulkOperationsTrait.php
    @@ -0,0 +1,45 @@
    + * @package Drupal\Tests\block_content\Functional
    

    I don't we use the @package annotation in core, let's remove it.

  5. +++ b/core/modules/block_content/tests/src/Functional/BlockContentTestBulkOperationsTrait.php
    @@ -0,0 +1,45 @@
    +   * Unpublish a block using the unpublish action.
    ...
    +   * Publish a block using the publish action.
    

    Needs the 3rd person form of the verb :)

  6. +++ b/core/modules/block_content/tests/src/Functional/Update/BlockContentUpdateTest.php
    @@ -11,6 +13,7 @@
     class BlockContentUpdateTest extends UpdatePathTestBase {
    +  use BlockContentTestBulkOperationsTrait;
    

    Same as above, a new line will help with visibility.

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
4.4 KB
24.52 KB

Thank you @amateescu for the review, all good points, addressing them here.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

Nice, I can't find anything else to complain about, so RTBC :)

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 60: 2909435-60.patch, failed testing. View results

Mixologic’s picture

Status: Needs work » Reviewed & tested by the community

Testbot Snafu.

vijaycs85’s picture

Looks good since my last review. +1 to RTBC. did a manual test of one of the happy path (i.e. with update db) and it works as expected.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 60: 2909435-60.patch, failed testing. View results

chr.fritsch’s picture

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

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 66: 2909435-66.patch, failed testing. View results

Manuel Garcia’s picture

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

Thanks @chr.fritsch - looks like that got reverted though, so re-uploading #60 here.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 68: 2909435-68.patch, failed testing. View results

chr.fritsch’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
24.57 KB
alexpott’s picture

Status: Reviewed & tested by the community » Needs review

I'm not sure I agree with #29. Yes updates that fix views to work with the current code base should be hook_update_N() but updates that are adding things that you could do via the UI should be post updates. There is never a time that post updates should be working with broken views and if they are then something has gone wrong.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

@alexpott, since Views doesn't enforce data integrity for the configuration of its plugins (like the problem discovered in #2917006: Views referencing missing roles fail views_post_update_revision_metadata_fields()), I don't think we can ever rely on being able to do CRUD operations on views' config entities in a post_update function, so the only option left is to update the view config objects "manually" in a regular hook_update_N() function.

jibran’s picture

+++ b/core/modules/block_content/block_content.install
@@ -138,3 +139,239 @@ function block_content_update_8400() {
+  $view->save(TRUE);
...
+  $publish_action->save(TRUE);
...
+  $unpublish_action->save(TRUE);

I think actions should be saved before the view is being updated, just like we normally do via UI. Am I missing something here?

Manuel Garcia’s picture

Manuel Garcia’s picture

@jibran re #74 It'd be a 2min change to the patch, but the bulk update field is configured to use All actions, except selected, so saving the actions after the view causes no problems with the view itself.

alexpott’s picture

since Views doesn't enforce data integrity for the configuration of its plugins

- but we need to move to a world where it does.

amateescu’s picture

Agreed, but not in this issue I would hope :)

amateescu’s picture

+++ b/core/modules/block_content/tests/src/Functional/Update/BlockContentUpdateTest.php
@@ -67,4 +71,61 @@ public function testStatusFieldAddition() {
+   * @see block_content_update_8600()

This needs to be updated to 8700 now..

Manuel Garcia’s picture

Good catch @amateescu :)

larowlan’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d6/MigrateUpgrade6Test.php
@@ -82,7 +82,7 @@ protected function getEntityCounts() {
-      'action' => 23,
+      'action' => 25,

+++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MigrateUpgrade7Test.php
@@ -82,7 +82,7 @@ protected function getEntityCounts() {
-      'action' => 17,
+      'action' => 19,

unrelated?

@alexpott's comments from #72 haven't been addressed yet either

Manuel Garcia’s picture

Status: Needs work » Needs review

Re #81:

  • The bump of the action entity counts is because we are adding two new actions in the patch (block content publish & unpublish).
  • Regarding @alexpott's comment on #72, @amateescu replied to it on #73.
vijaycs85’s picture

Issue tags: +DistributedSprintUK18

Tested manually on both scenarios (install with patch & install, apply patch & drush updb) and can see the publish checkbox on both cases. +1 to RTBC.

Only difference between this issue and #2834546: UI for publishing/unpublishing block_content blocks is, this one runs update and #2834546: UI for publishing/unpublishing block_content blocks runs post-update.

amateescu’s picture

Status: Needs review » Reviewed & tested by the community

@larowlan's feedback has been answered, back to RTBC :)

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/block_content/block_content.install
@@ -138,3 +138,236 @@ function block_content_update_8400() {
+  $view = \Drupal::service('config.factory')->getEditable('views.view.block_content');

It's possible the view has been deleted or does not exist.

Also this issue poses an interesting question. Why do we have an update path? It is possible the user has customised their view so that doing these updates is unnecessary and will cause duplicate columns. I think

  • Maybe we should only updating if the view matches the original configuration - we can use the _core hash key to determine this.
  • Consider whether we should be doing the update at all

Also I'm still not completely sold on @amateescu's arguments for this being hook_update_N - yes there are issues with views dependencies and they way some views plugin over store things in config but they are bugs that we should fix when we come across them.

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
24.6 KB

Rerolled, there was a conflict on MigrateUpgrade6Test which a 3 way merge was able to fix.

Setting to needs review to trigger the tests bot, though this is still needs work (see #85).

Upgrade path is to add the new features to the block content admin form, where we are not only adding the status field, but also the block_content_bulk_form field with the new publish/unpublish actions added in this patch. So in my opinion we do need an update path to add these.

Perhaps we can first check if the status field already exists on the view, and only add it if its not already there?

Manuel Garcia’s picture

Perhaps something like this? (only adding the status field if its not there already).

Manuel Garcia’s picture

Addressing what was mentioned in #85 - checking that the view exists prior to altering it. Not 100% sure this is the right way to do it, please have a look :)

The last submitted patch, 86: 2909435-86.patch, failed testing. View results

vijaycs85’s picture

Status: Needs review » Needs work

The last submitted patch, 90: 2909435-90.patch, failed testing. View results

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Manuel Garcia’s picture

Issue tags: +Needs reroll
Manuel Garcia’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
25.51 KB

Reroll of #90

Status: Needs review » Needs work

The last submitted patch, 94: 2909435-94.patch, failed testing. View results

vijaycs85’s picture

Status: Needs work » Needs review

Retesting the patch in #94 as the failing test (Drupal\Tests\block_content\Functional\Update\BlockContentUpdateTest::testBlockContentPublishableUIUpdate) doesn't exist in HEAD anymore.

Manuel Garcia’s picture

Rerolled, 3 way merge did the trick.

Status: Needs review » Needs work

The last submitted patch, 97: 2909435-97.patch, failed testing. View results

Manuel Garcia’s picture

@vijaycs85 re #96 - testBlockContentPublishableUIUpdate is added in this patch :)

vijaycs85’s picture

#99my bad :)

Drupal\Tests\block_content\Functional\Update\BlockContentUpdateTest::testBlockContentPublishableUIUpdate is failing because the test is trying to use the DB dump from drupal-8.bare.standard.php.gz which has the config views.view.block_content and doesn't match with what we have current config (i.e. changes went in in config but weren't updated in drupal-8.bare.standard.php.gz)

I am attaching the views.view.block_content.yml for reference.

Next step would be sync the config except the changes introduced in this issue to drupal-8.bare.standard.php.gz and run tests again.

P.S: the config file generated by below code:


$str = '[serialized data from config table]';

$config = unserialize($str);

$yml = \Drupal\Core\Serialization\Yaml::encode($config);
print_r($yml);
// Save it as test.php
// then run
// drush scr test.php > views.view.block_content.yml.txt
vijaycs85’s picture

Status: Needs work » Postponed

after further testing found that the config in DB update doesn't match with the one installed on the HEAD and I created #3062291: Config entity changes as part of install which turns out to be a duplicate of #3059545: Improve \Drupal\KernelTests\Config\DefaultConfigTest to install all optional configuration. Probably a good idea to wait for #3059545: Improve \Drupal\KernelTests\Config\DefaultConfigTest to install all optional configuration to land. it is RTBC anyway.

vijaycs85’s picture

Status: Needs review » Needs work

The last submitted patch, 97: 2909435-97.patch, failed testing. View results

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
2.66 KB
25.92 KB

I think the issue with BlockContentUpdateTest will still remain though this should fix some of the failing tests.

Status: Needs review » Needs work

The last submitted patch, 104: 2909435-104.patch, failed testing. View results

vijaycs85’s picture

Here is an update on the update test. Works locally. I am not sure how it would help for the review as the patch and interdiff with changes on gz file are not readable.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

capysara’s picture

Is there any interest in resurrecting this? If so, I can test the last patch (and the patch in https://www.drupal.org/project/drupal/issues/2834546).

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work

This will need a reroll for 9.5

smustgrave’s picture

Status: Needs work » Postponed

This one needs a lot of work still I think

The update hook failed.
The bulk feature for the view I think needs a handler.

But postponing until https://www.drupal.org/project/drupal/issues/2834546 is complete.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Postponed » Closed (outdated)

Combing with #2834546: UI for publishing/unpublishing block_content blocks

Will move over appropriate credit.