Updated: Comment #N

Problem/Motivation

In #2056513: Remove PluginUI subsystem, provide block plugins UI as one-off, blocks were given a 'category', it is currently filled in by the block provider.
This means that blocks like "Recent Comments" fall under 'Views' and not 'Comment'.

Proposed resolution

Expose the block category on the view edit form for block displays.

Remaining tasks

User interface changes

A new property for block displays

API changes

N/A

#1938062: Convert the recent_comments block to a view
#2060859: Make Block plugin's "category" a translatable string

CommentFileSizeAuthor
#45 interdiff.txt2.93 KBtim.plunkett
#45 vdc-2071019-45.patch21.22 KBtim.plunkett
#43 interdiff.txt5.61 KBtim.plunkett
#43 vdc-2071019-43-FAIL.patch20.79 KBtim.plunkett
#43 vdc-2071019-43-PASS.patch20.84 KBtim.plunkett
#41 block-vdc-2071019-41.patch19.2 KBolli
#41 interdiff.txt813 bytesolli
#38 Screen Shot 2013-09-10 at 11.14.36 AM.png46.64 KBtim.plunkett
#38 interdiff.txt7.18 KBtim.plunkett
#38 block-vdc-2071019-38.patch19.63 KBtim.plunkett
#37 Add_new_view___Site-Install.png68.86 KBwebchick
#37 Screen_Shot_2013-09-10_at_12.03.59_AM.png67.81 KBwebchick
#37 Screen_Shot_2013-09-10_at_12.07.19_AM.png61.03 KBwebchick
#37 Screen_Shot_2013-09-10_at_12.09.05_AM.png73.13 KBwebchick
#35 block-2071019-35.patch13.26 KBtim.plunkett
#35 interdiff.txt570 bytestim.plunkett
#32 interdiff.txt1.59 KBolli
#32 vdc-2071019-32.patch13.19 KBolli
#30 vdc-2071019-30.patch12.25 KBtim.plunkett
#30 interdiff.txt983 bytestim.plunkett
#27 vdc-2071019-27.patch12.26 KBtim.plunkett
#27 interdiff.txt1.6 KBtim.plunkett
#25 vdc-2071019-25.patch12.07 KBtim.plunkett
#25 interdiff.txt978 bytestim.plunkett
#21 vdc-2071019-21.patch12.07 KBtim.plunkett
#21 interdiff.txt991 bytestim.plunkett
#16 vdc-2071019-16.patch12.06 KBtim.plunkett
#11 vdc-2071019-11.patch12.06 KBtim.plunkett
#11 interdiff.txt7.67 KBtim.plunkett
#9 vdc-2071019-9-FAIL.patch2.38 KBtim.plunkett
#9 vdc-2071019-9-PASS.patch8.67 KBtim.plunkett
#9 interdiff.txt5.78 KBtim.plunkett
#5 interdiff.txt4.58 KBtim.plunkett
#5 vdc-2071019-5.patch5.09 KBtim.plunkett
#1 vdc-2071019-1.patch3.41 KBtim.plunkett

Comments

tim.plunkett’s picture

Status: Active » Needs review
Issue tags: +Needs tests
StatusFileSize
new3.41 KB

Until #2060859: Make Block plugin's "category" a translatable string goes in, this doesn't make much sense, but here it is.

dawehner’s picture

Status: Needs review » Needs work

You have to adapt the schema as well. The rest looks perfect. It seems to be that webchick requires to use the base table as the default value?

tstoeckler’s picture

+++ b/core/modules/block/lib/Drupal/block/Plugin/views/display/Block.php
@@ -173,6 +180,14 @@ public function buildOptionsForm(&$form, &$form_state) {
+          '#description' => t('This will appear as the category of this block in administer >> structure >> blocks.'),

I think this should be something like:
"... as the category of this block on the blocks placement page" (or whatever that page is called).

damiankloip’s picture

  1. +++ b/core/modules/block/lib/Drupal/block/Plugin/views/display/Block.php
    @@ -108,12 +109,18 @@ public function optionsSummary(&$categories, &$options) {
    +      'value' => views_ui_truncate($block_category, 24),
    

    Using a views_ui method here bugs me. That is not the fault of this patch though, I might make an issue to sort that out.

  2. +++ b/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsBlock.php
    @@ -90,6 +90,7 @@ public function getDerivativeDefinitions(array $base_plugin_definition) {
    +          $category = $display->getOption('block_category');
    
    @@ -100,6 +101,7 @@ public function getDerivativeDefinitions(array $base_plugin_definition) {
    +            'category' => $category,
    

    Might as well just not assign the $category variable?

I agree with #3, but maybe tweaked; something like 'The category this block will appear under on the blocks placement page' ?

tim.plunkett’s picture

Component: views.module » views_ui.module
Status: Needs work » Needs review
StatusFileSize
new5.09 KB
new4.58 KB

I even found a bug!

dawehner’s picture

+++ b/core/modules/block/lib/Drupal/block/Plugin/views/display/Block.php
@@ -46,7 +47,10 @@ protected function defineOptions() {
+    $base_tables = Views::viewsData()->fetchBaseTables();
+    $base_table = $this->view->storage->get('base_table');
+    $block_category = isset($base_tables[$base_table]['title']) ? $base_tables[$base_table]['title'] : t('Views');
+    $options['block_category'] = array('default' => $block_category, 'translatable' => TRUE);

You are a lucky guy that this does not break anything. My previous attempts to use configuration in defineOptions all went into the problem that at some point defineOptions is called again. I am feared that this could bite us at some point.

Additional I think we should not use translated values here as default values.

olli’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/block/lib/Drupal/block/Plugin/views/display/Block.php
    @@ -173,6 +184,14 @@ public function buildOptionsForm(&$form, &$form_state) {
    +          '#description' => t('The category this block will appear under on the <a href="@href">blocks placement page</a>.', array('@href' => 'admin/structure/blocks')),
    

    The link doesn't work, it takes me to admin/structure/views/view/archive/edit/admin/structure/blocks.

  2. +++ b/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsBlock.php
    @@ -100,6 +100,7 @@ public function getDerivativeDefinitions(array $base_plugin_definition) {
    +            'category' => $display->getOption('block_category'),
    

    I think we need to sanitize the category if it's user input.

tim.plunkett’s picture

Yeah, I was pretty sure that would break something. Hm...

And yes, I meant to remove the t(), that's just habit :)

tim.plunkett’s picture

Assigned: Unassigned » tim.plunkett
Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new5.78 KB
new8.67 KB
new2.38 KB

Thanks for the reviews. I've also added tests.

dawehner’s picture

+++ b/core/modules/block/lib/Drupal/block/Tests/Views/DisplayBlockTest.php
@@ -47,6 +47,43 @@ protected function setUp() {
+    $elements = $this->xpath('//details[@id=:id]//ul[contains(@class, "block-list")]/li[contains(@class, :li_class)]/a[contains(@href, :href) and text()=:text]', $arguments);
...
+    $elements = $this->xpath('//details[@id=:id]//ul[contains(@class, "block-list")]/li[contains(@class, :li_class)]/a[contains(@href, :href) and text()=:text]', $arguments);

Is it just me that we test the actual produced HTML? I don't know but it feels better to not add everything into the select chain?

tim.plunkett’s picture

StatusFileSize
new7.67 KB
new12.06 KB

In IRC, @dawehner clarified his comment in #6.
For the most part, defineOptions() has only static values, nothing dynamic, and certainly nothing pulling from an external service.
In order to maintain that, I've switched this around to determine the base table when adding a new block, either from the wizard, or while editing a view.

I also removed some of the irrelevant HTML as mentioned in #10.

Additionally, we're testing the wizard, instead of using a shipped block.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/modules/block/lib/Drupal/block/Tests/Views/DisplayBlockTest.php
@@ -52,20 +52,30 @@ protected function setUp() {
+      ':href' => 'admin/structure/block/add/views_block%3A' . $edit['id'] . '-block_1/stark',

Is there already a follow up to fix the ":" in URLs problems?

tim.plunkett’s picture

tstoeckler’s picture

+++ b/core/modules/block/lib/Drupal/block/Plugin/views/display/Block.php
@@ -188,8 +189,8 @@ public function buildOptionsForm(&$form, &$form_state) {
+          '#description' => t('The category this block will appear under on the <a href="@href">blocks placement page</a>.', array('@href' => '/admin/structure/blocks')),

I think the standard is to use url() in these kinds of situations. Since we're still using t() also, I think that would be OK, even nowadays.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

Patch no longer applies

tim.plunkett’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs reroll
StatusFileSize
new12.06 KB

#14, I copied this straight from core.

grep -nr '<a href="@' core | wc -l
308

Straight reroll, just use statements conflict.

Status: Reviewed & tested by the community » Needs work
Issue tags: -VDC, -Block UI overhaul

The last submitted patch, vdc-2071019-16.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review

#16: vdc-2071019-16.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +VDC, +Block UI overhaul

The last submitted patch, vdc-2071019-16.patch, failed testing.

tstoeckler’s picture

Re #16: Sorry for not being more precise. Embedding the <a> tag in the string is correct indeed. But for the t() placeholder I think it makes sense to use url('admin/structure/blocks') instead of embedding the path directly. That's what's done throughout core.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new991 bytes
new12.07 KB

AHHH!
@tstoeckler++
That explains why it doesn't fail for me, because testbot is installed in a subdir.

tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community

Right, of course I was totally arguing on a technical level and not for mere consistency/nit-picking-reasons... ;-P

If this was RTBC before, it certainly is now. Unless bot disagrees again.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, vdc-2071019-21.patch, failed testing.

tim.plunkett’s picture

Oh wait, that has nothing to do with this fail. But I cannot reproduce via Simpletest UI, and I don't know how to debug xpath from the CLI.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new978 bytes
new12.07 KB

This worked with run-tests locally

Status: Needs review » Needs work

The last submitted patch, vdc-2071019-25.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new1.6 KB
new12.26 KB

me--

Status: Needs review » Needs work
Issue tags: -VDC, -Block UI overhaul

The last submitted patch, vdc-2071019-27.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
Issue tags: +VDC, +Block UI overhaul

#27: vdc-2071019-27.patch queued for re-testing.

tim.plunkett’s picture

StatusFileSize
new983 bytes
new12.25 KB

Right now this random fails. But I found it!

$string = 'D,{Loq8/';
var_dump(drupal_html_class(check_plain($string)));
string(6) "dloq8-"
var_dump(drupal_html_id(check_plain($string)));
string(5) "dloq8"
tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community

Wow, nice debugging!

Still looks good.

olli’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new13.19 KB
new1.59 KB

Sorry, found two small bugs while simplytesting.

  1. +++ b/core/modules/block/lib/Drupal/block/Plugin/views/display/Block.php
    @@ -173,6 +182,14 @@ public function buildOptionsForm(&$form, &$form_state) {
    +          '#description' => t('The category this block will appear under on the <a href="@href">blocks placement page</a>.', array('@href' => url('admin/structure/blocks'))),
    

    The path is admin/structure/block.

  2. +++ b/core/modules/block/lib/Drupal/block/Plugin/views/display/Block.php
    @@ -173,6 +182,14 @@ public function buildOptionsForm(&$form, &$form_state) {
    +          '#default_value' => String::checkPlain($this->getOption('block_category')),
    

    String::checkPlain is not needed here and would cause double escaping.

  3. Should we add block_category to views.display.schema.yml?
dawehner’s picture

Status: Needs review » Reviewed & tested by the community

We totally should add the schema, see my review in #2 :)

webchick’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs followup

No longer applies. :(

+++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php
@@ -2662,6 +2666,12 @@ public function validate() {
   /**
+   * Reacts on adding a display.
+   */
+  public function newDisplay() {
+  }

+++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewEditFormController.php
@@ -790,7 +791,8 @@ public function submitDisplayAdd($form, &$form_state) {
-    $display_id = $view->addDisplay($display_type);
+    $display = $view->newDisplay($display_type);

It is not clear what addDisplay() vs. newDisplay() is. I approached bikeshedding this with Tim a bit, but he pointed out that this confusion is a pre-existing condition (newDisplay is defined on the View object, this is simply re-propogating it here where it's needed). So let's get a follow-up to fix this from a more holistic POV, and also fix the docs so they refer to where this method is properly documented.

Otherwise, this looks good code-wise. Haven't had a chance to manually test yet.

tim.plunkett’s picture

Status: Needs work » Needs review
Issue tags: -Needs followup
StatusFileSize
new570 bytes
new13.26 KB
dawehner’s picture

Status: Needs review » Reviewed & tested by the community

That is fine for now.

webchick’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs followup
StatusFileSize
new73.13 KB
new61.03 KB
new67.81 KB
new68.86 KB

Ok, now played around with this as a user. Overall, it worked great! Here's a walkthrough:

I LOVE this, since it picks a smart default that'll work in 90% of cases, most likely:

In Views Wizard, the type of view will correspond to...
...the default block category!

However...

Category is a text field

A text field for this isn't going to fly; it opens a site up to data integrity issues. Since we lack a "select or add one" pattern in core to employ here, we should fall back to autocomplete as a workaround. Needs work for that.

I also found one other weird thing:

' by default

I've no idea why we are exposing this kind of implementation detail. We don't prefix other blocks with "Module:" or "Custom:" From talking to Tim, this is a historical artifact from Views D7 and below, since often you'd end up in a situation where there was both a "Core" Recent comments block and also a "Views" Recent comments block, and you needed to differentiate between them. However, with Views in core, and with an initiative well underway to try and convert all of those crappy listing blocks to Views, I don't think this makes sense anymore. However, it wasn't introduced in this patch, so marking "Needs followup" for that.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new19.63 KB
new7.18 KB
new46.64 KB

Agreed that we should revisit the "View: " prefix on blocks.

Here's autocomplete, with a unit test. No point in a test-only patch, since it will try to use a class that doesn't exist...

Screen Shot 2013-09-10 at 11.14.36 AM.png

jibran’s picture

+++ b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php
@@ -108,4 +108,18 @@ protected function t($string, array $args = array(), array $options = array()) {
+    $categories = array_unique(array_values(array_map(function ($definition) {
+      return $definition['category'];
+    }, $this->getDefinitions())));

Oh I like this part.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php
@@ -108,4 +108,18 @@ protected function t($string, array $args = array(), array $options = array()) {
+    natcasesort($categories);

That function sounds a bit like net cheese in german.

olli’s picture

StatusFileSize
new813 bytes
new19.2 KB
+++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php
@@ -768,6 +768,10 @@ public function getPath() {
+
+    if ($this->getOption('link_display') == 'custom_url' && $link_url = $this->getOption('link_url')) {
+      return $link_url;
+    }

Oh, cr.. #32. This was for another issue, sorry!

tim.plunkett’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewEditFormController.php
@@ -768,7 +768,8 @@ public function submitDisplayDuplicate($form, &$form_state) {
+    $display = $view->newDisplay($displays[$display_id]['display_plugin']);

@@ -790,7 +791,8 @@ public function submitDisplayAdd($form, &$form_state) {
+    $display = $view->newDisplay($display_type);

@@ -810,7 +812,8 @@ public function submitCloneDisplayAsType($form, &$form_state) {
+    $display = $view->newDisplay($display_type);

These are called on the wrong object after #2082157: Move View::newDisplay() to ViewExecutable. Working on more test coverage

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new20.84 KB
new20.79 KB
new5.61 KB

Added more test coverage.

olli’s picture

Status: Needs review » Needs work

Nice work @tim.plunkett!

  1. +++ b/core/modules/block/lib/Drupal/block/Controller/CategoryAutocompleteController.php
    @@ -0,0 +1,67 @@
    +      if (strpos($category, $typed_category) === 0) {
    

    Should we use stripos instead?

  2. +++ b/core/modules/block/lib/Drupal/block/Controller/CategoryAutocompleteController.php
    @@ -0,0 +1,67 @@
    +        $matches[$category] = $category;
    

    Needs a checkplain for the value.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new21.22 KB
new2.93 KB

Good points for both. Adding test coverage.

jibran’s picture

Status: Needs review » Reviewed & tested by the community

As #37 is addressed. Screenshot is in #38 and we have nice test coverage. Unable to find aything in code review so putting back to RTBC.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Perfect!!

Committed and pushed to 8.x. Still need a follow-up for the "Views:" string. I'd create it myself, but I'm not sure I could adequately describe where that code is and what it's doing.

damiankloip’s picture

Issue tags: -Needs followup

Created that follow up; I should that should be adequate, and very simple. Unless I'm missing something :) #2086447: Remove 'View:' prefix from views block derivative admin labels

tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned

Thanks!

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