Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task: All content entity types should have some views integration. This issue is also a base for using views for that particular admin listing
Issue priority Normal, because the impact is not that high.
Disruption No disruption, because there is no API change.

Problem/Motivation

We need to add a revisions ui for block_content. This would best be done with views. Hence we need views support.

Proposed resolution

Implement BlockContentViewsData class

Remaining tasks

Write patch
Tests
Reviews

User interface changes

None

API changes

None

#1984588: Add a UI for viewing/reverting custom block revisions
#2375589: Convert custom block library page to views

Files: 
CommentFileSizeAuthor
#62 custom-block-views-test.png90.33 KBkattekrab
#61 interdiff.txt1.7 KBjibran
#61 1984582-62.patch46.79 KBjibran
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 85,645 pass(es). View

Comments

dawehner’s picture

FileSize
4.92 KB
PASSED: [[SimpleTest]]: [MySQL] 55,531 pass(es). View

Oh damn, I haven't seen that assigned fast enough.

I hope you can at least get inspired by this small bit.

larowlan’s picture

Assigned: larowlan » Unassigned
Status: Active » Needs review

Looks good to me, lets ask the bot.

larowlan’s picture

So after taking this for a spin we'll need to add view and delete revision link field handlers.

+++ b/core/modules/block/custom_block/custom_block.views.incundefined
@@ -0,0 +1,200 @@
+    'help' => t('The ID of the custom block revision.'),

The ID of the custom block this revision is from

+++ b/core/modules/block/custom_block/custom_block.views.incundefined
@@ -0,0 +1,200 @@
+    'title' => t('Current Revision ID'),

Just revision ID

+++ b/core/modules/block/custom_block/custom_block.views.incundefined
@@ -0,0 +1,200 @@
+    'help' => t('The current Revision ID of the custom block.'),

The ID of the revision

dawehner’s picture

FileSize
10.74 KB
PASSED: [[SimpleTest]]: [MySQL] 55,533 pass(es). View

Well, we certainly still need some routing/menu entries to actually manage revisions, so we need this first in order to continue here.

xtfer’s picture

I'm looking at this in preparation for #1984588: Add a UI for viewing/reverting custom block revisions.

The "Link to edit a custom block" handler is currently broken.

Debug:
'Missing handler: custom_block edit_link field'
in views_get_handler() (line 940 of core/modules/views/views.module).

xtfer’s picture

Status: Needs review » Needs work
dawehner’s picture

Status: Needs work » Needs review
Issue tags: +Needs tests
FileSize
2.47 KB
11.04 KB
PASSED: [[SimpleTest]]: [MySQL] 55,692 pass(es). View

Okay let's be a little bit more honest.

dawehner’s picture

Issue tags: -Needs tests

Okay let's be a little bit more honest.

xtfer’s picture

+++ b/core/modules/block/custom_block/custom_block.views.incundefined
@@ -0,0 +1,216 @@
+  $data['custom_block']['type'] = array();
+
+  if (module_exists('language')) {
+    $data['custom_block']['langcode'] = array(

Simple one...

if (\Drupal::moduleHandler()->moduleExists('language')) {

+++ b/core/modules/block/custom_block/custom_block.views.incundefined
@@ -0,0 +1,216 @@
+  $data['custom_block']['view_link'] = array(
+    'title' => t('Link to custom block'),
+    'help' => t('Provide a simple link to the custom block.'),
+    'field' => array(
+      'id' => 'entity_link',
+    ),
+  );
+
+  $data['custom_block']['edit_link'] = array(
+    'title' => t('Link to edit the custom block'),
+    'help' => t('Provide a simple link to edit the custom block.'),
+    'field' => array(
+      'id' => 'custom_block_edit_link',
+    ),

These are still failing for me. Do they need to be similar to views_handler_field_entity?

xtfer’s picture

Status: Needs review » Needs work
xtfer’s picture

+++ b/core/modules/block/custom_block/custom_block.views.incundefined
@@ -0,0 +1,216 @@
+    'relationship' => array(
+      'label' => t('Custom block revision'),
+      'base' => 'custom_block_revision',
+      'base field' => 'revision_id',

I also had to add

'id' => 'standard',

to get this relationship to work

xtfer’s picture

Assigned: Unassigned » xtfer
tim.plunkett’s picture

Component: block.module » custom_block.module
xtfer’s picture

Assigned: xtfer » Unassigned
Gábor Hojtsy’s picture

Title: Add views support for {custom_block_revision} » Add views support for custom blocks

This issue adds custom blocks views support wholesale, so better have a more accurate title.

damiankloip’s picture

  1. +++ b/core/modules/block/custom_block/custom_block.views.inc
    @@ -0,0 +1,216 @@
    +    'relationship' => array(
    +      'label' => t('Custom block revision'),
    +      'base' => 'custom_block_revision',
    +      'base field' => 'revision_id',
    

    As xtfer mentions, we need an id in here.

  2. +++ b/core/modules/block/custom_block/custom_block.views.inc
    @@ -0,0 +1,216 @@
    +  if (module_exists('language')) {
    

    Drupal::moduleHandler()->...

  3. +++ b/core/modules/views/lib/Drupal/views/Plugin/views/field/EntityLink.php
    @@ -0,0 +1,90 @@
    +class EntityLink extends FieldPluginBase {
    

    See #2030453: Aggregate field data is not available as tokens for output rewriting, we should override usesGroupBy() here as it doesn't make sense to allow aggregation on these field handlers.

  4. +++ b/core/modules/views/lib/Drupal/views/Plugin/views/field/EntityLink.php
    @@ -0,0 +1,90 @@
    +    $entity = $this->get_entity($values);
    +    if ($entity->access($this->operation)) {
    

    Should this be if (($entity = $this->get_entity) && $entity->access()) ?

Also, seems like we might need some integration tests for this?

dawehner’s picture

Status: Needs work » Needs review
Issue tags: +Needs tests
FileSize
1.95 KB
11.18 KB
FAILED: [[SimpleTest]]: [MySQL] 58,091 pass(es), 1 fail(s), and 0 exception(s). View

Just fixing the problems but yeah I guess we need some tests.

The last submitted patch, vdc-1984582-17.patch, failed testing.

Anonymous’s picture

Issue summary: View changes

Updated issue summary.

jibran’s picture

Assigned: Unassigned » jibran
Issue summary: View changes

I'll take a look.

jibran’s picture

Assigned: jibran » Unassigned
Status: Needs work » Needs review
FileSize
28.05 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 82,832 pass(es). View

Let's start fresh.

jibran’s picture

Some questions for @dawehner.

  1. Do you think we should add BulkForm field plugin to this patch?
  2. Do you think we need Id argument plugin?
  3. Do you think we need Id argument validator?
  4. Do we need to add a tag? $data['block_content']['table']['base']['access query tag'] = 'block_content_access';
  1. +++ b/core/modules/block_content/src/BlockContentViewsData.php
    @@ -0,0 +1,209 @@
    +    $data['block_content']['table']['wizard_id'] = 'block_content';
    ...
    +    $data['block_content_revision']['table']['wizard_id'] = 'block_content_revision';
    ...
    +    $data['block_content_field_revision']['table']['wizard_id'] = 'block_content_field_revision';
    

    @dawehner do we need these?

  2. +++ b/core/modules/block_content/src/BlockContentViewsData.php
    @@ -0,0 +1,209 @@
    +    // @todo Figure out do we need this or not.
    ...
    +    // @todo Figure out do we need this or not.
    ...
    +    // @todo Figure out do we need this or not.
    

    @dawehner do we need new field plugin link node_language?

  3. +++ b/core/modules/block_content/src/BlockContentViewsData.php
    @@ -0,0 +1,209 @@
    +    $data['block_content']['path'] = array(
    

    @dawehner @larowlan we have view link field. Do we need path field as well?

  4. +++ b/core/modules/block_content/src/BlockContentViewsData.php
    @@ -0,0 +1,209 @@
    +    $data['block_content_field_data']['changed_fulldate'] = array(
    ...
    +    $data['block_content_field_data']['changed_year_month'] = array(
    ...
    +    $data['block_content_field_data']['changed_year'] = array(
    ...
    +    $data['block_content_field_data']['changed_month'] = array(
    ...
    +    $data['block_content_field_data']['changed_day'] = array(
    ...
    +    $data['block_content_field_data']['changed_week'] = array(
    

    @dawehner do we need these for blocks?

  5. +++ b/core/modules/block_content/src/BlockContentViewsData.php
    @@ -0,0 +1,209 @@
    +    // @todo Fix this when we support block content revision links.
    ...
    +    // @todo Fix this when we support block content revision links.
    ...
    +    // @todo Fix this when we support block content revision links.
    

    @larowlan why we don't have revision uri?

  6. +++ b/core/modules/block_content/src/Plugin/views/field/BlockContent.php
    @@ -0,0 +1,107 @@
    +        $block_content = entity_load('block_content', $id);
    ...
    +          $languages = language_list();
    

    @jibran injection.

  7. +++ b/core/modules/block_content/src/Plugin/views/field/Link.php
    @@ -0,0 +1,91 @@
    +    if ($block_content->access('view')) {
    
    +++ b/core/modules/block_content/src/Plugin/views/field/LinkDelete.php
    @@ -0,0 +1,38 @@
    +    if (!$block_content->access('delete')) {
    
    +++ b/core/modules/block_content/src/Plugin/views/field/LinkEdit.php
    @@ -0,0 +1,46 @@
    +    if (!$block_content->access('update')) {
    

    @larowlan I don't think we can check these permissions? Unless I am missing something.

  8. +++ b/core/modules/block_content/src/Plugin/views/field/Path.php
    @@ -0,0 +1,74 @@
    +    return \Drupal::url('entity.block_content.canonical', ['block_content' => $id], ['absolute' => $this->options['absolute']]);
    

    @jibran injection

  9. +++ b/core/modules/block_content/src/Plugin/views/field/Type.php
    @@ -0,0 +1,65 @@
    +      $type = entity_load('block_content_type', $data);
    

    @jibran injection.

  10. +++ b/core/modules/block_content/src/Plugin/views/wizard/BlockContent.php
    @@ -0,0 +1,67 @@
    + * @todo: replace numbers with constants.
    
    +++ b/core/modules/block_content/src/Plugin/views/wizard/BlockContentRevision.php
    @@ -0,0 +1,88 @@
    + * @todo: replace numbers with constants.
    

    Was ist das?

  11. +++ b/core/modules/block_content/src/Plugin/views/wizard/BlockContent.php
    @@ -0,0 +1,67 @@
    +class BlockContent extends WizardPluginBase {
    

    @dawehner Is this class enough or do we want more options on wizard form?

  12. +++ b/core/modules/block_content/src/Plugin/views/wizard/BlockContent.php
    @@ -0,0 +1,67 @@
    +  protected $createdColumn = 'block_content_field_data-changed';
    
    +++ b/core/modules/block_content/src/Plugin/views/wizard/BlockContentRevision.php
    @@ -0,0 +1,88 @@
    +  protected $createdColumn = 'block_content_field_revision-changed';
    

    @dawehner there is no create column. Should we support this?

  13. +++ b/core/modules/block_content/src/Plugin/views/wizard/BlockContentRevision.php
    @@ -0,0 +1,88 @@
    +    // @todo Fix this when we support block content revision links.
    +    // $display_options['fields']['info']['link_to_block_content'] = 0;
    +    // $display_options['fields']['info']['link_to_block_content_revision'] = 1;
    +    $display_options['fields']['info']['plugin_id'] = 'standard';
    

    We have to create a new field plugin to support the revison links.

I'll add some tests next.

larowlan’s picture

Jibran++
We don't have uri because #1984588: Add a UI for viewing/reverting custom block revisions and this are kind of inter-related

larowlan’s picture

->access should work, from memory it just uses administer blocks permission.
I don't think we need view link, or path link, there is no viewing at moment, it falls back to editing.

jibran’s picture

Assigned: Unassigned » jibran

Working on this.

jibran’s picture

Assigned: jibran » Unassigned
Issue tags: -Needs tests
FileSize
53 KB
71.27 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 83,401 pass(es), 15 fail(s), and 0 exception(s). View

Added some passing and failing tests. I'll try to look into fails next year.

jibran’s picture

+++ b/core/modules/block_content/src/BlockContentViewsData.php
@@ -162,6 +162,11 @@ public function getViewsData() {
+    $data['block_content_field_revision']['table']['group'] = t('Custom Block revision');
...
+    $data['block_content_field_revision']['table']['join']['block_content_revision']['left_field'] = 'revision_id';
+    $data['block_content_field_revision']['table']['join']['block_content_revision']['field'] = 'revision_id';
+    $data['block_content_field_revision']['table']['join']['block_content_revision']['type'] = 'INNER';

@dawehner Why these are not added by parent? We are not adding these in NodeData. I have to add these explicitly.

Status: Needs review » Needs work

The last submitted patch, 25: 1984582-25.patch, failed testing.

dawehner’s picture

@dawehner Why these are not added by parent? We are not adding these in NodeData. I have to add these explicitly.

Good question, don't know at the moment. It seems to be that you added it in #1984582-20: Add views support for custom blocks ... didn't you :P

Added some passing and failing tests. I'll try to look into fails next year.

Happy next year ...

jibran’s picture

Status: Needs work » Needs review
FileSize
14.84 KB
74.21 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 83,403 pass(es), 1 fail(s), and 0 exception(s). View

Green Happy New Year!!!
It is ready for review. Please @dawehner can you please ans #21. Thanks.

jibran’s picture

FileSize
1.16 KB
74.2 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 83,415 pass(es), 1 fail(s), and 0 exception(s). View

Minor doc fix.

jibran’s picture

The last submitted patch, 29: 1984582-29.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 30: 1984582-30.patch, failed testing.

jibran’s picture

Status: Needs work » Needs review
FileSize
2.42 KB
73.76 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 83,412 pass(es). View

Now the real green :P

larowlan’s picture

Wow - awesome patch - great test coverage too!
Code review:

  1. +++ b/core/modules/block_content/src/BlockContentViewsData.php
    @@ -0,0 +1,222 @@
    +    // @todo Figure out do we need this or not.
    +    // $data['block_content_field_data']['langcode']['help'] = t('The language of the block content or translation.');
    +    // $data['block_content_field_data']['langcode']['field']['id'] = 'block_content_language';
    

    I guess no - if it's commented out?

  2. +++ b/core/modules/block_content/src/BlockContentViewsData.php
    @@ -0,0 +1,222 @@
    +    // $data['block_content_field_data']['langcode']['help'] = t('The language of the block content or translation.');
    ...
    +        'title' => t('Translation link'),
    +        'help' => t('Provide a link to the translations overview for custom blocks.'),
    ...
    +        'title' => t('Link to block content'),
    +        'help' => t('Provide a simple link to the block content.'),
    ...
    +        'title' => t('Link to edit block content'),
    +        'help' => t('Provide a simple link to edit the block content.'),
    ...
    +        'title' => t('Link to delete block content'),
    +        'help' => t('Provide a simple link to delete the block content.'),
    ...
    +        'title' => t('Path'),
    +        'help' => t('The aliased path to this block content.'),
    ...
    +    //   'title' => t('Block Content operations bulk form'),
    +    //   'help' => t('Add a form element that lets you run operations on multiple block contents.'),
    ...
    +      'title' => t('Updated date'),
    +      'help' => t('Date in the form of CCYYMMDD.'),
    ...
    +      'title' => t('Updated year + month'),
    +      'help' => t('Date in the form of YYYYMM.'),
    ...
    +      'title' => t('Updated year'),
    +      'help' => t('Date in the form of YYYY.'),
    ...
    +      'title' => t('Updated month'),
    +      'help' => t('Date in the form of MM (01 - 12).'),
    ...
    +      'title' => t('Updated day'),
    +      'help' => t('Date in the form of DD (01 - 31).'),
    ...
    +      'title' => t('Updated week'),
    +      'help' => t('Date in the form of WW (01 - 53).'),
    ...
    +    $data['block_content_revision']['table']['base']['help'] = t('Block Content revision is a history of changes to block content.');
    ...
    +    $data['block_content_revision']['id']['relationship']['title'] = t('Block Content');
    +    $data['block_content_revision']['id']['relationship']['label'] = t('Get the actual block content from a block content revision.');
    +
    ...
    +    $data['block_content_revision']['revision_id']['relationship']['title'] = t('Block Content');
    +    $data['block_content_revision']['revision_id']['relationship']['label'] = t('Get the actual block content from a block content revision.');
    ...
    +    $data['block_content_field_revision']['table']['group'] = t('Custom Block revision');
    ...
    +    //     'title' => t('Link to revision'),
    +    //     'help' => t('Provide a simple link to the revision.'),
    ...
    +    //     'title' => t('Link to revert revision'),
    +    //     'help' => t('Provide a simple link to revert to the revision.'),
    ...
    +    //     'title' => t('Link to delete revision'),
    +    //     'help' => t('Provide a simple link to delete the content revision.'),
    

    $this->t is available

  3. +++ b/core/modules/block_content/src/BlockContentViewsData.php
    @@ -0,0 +1,222 @@
    +    if (\Drupal::moduleHandler()->moduleExists('content_translation')) {
    

    $this->moduleHandler is available

  4. +++ b/core/modules/block_content/src/BlockContentViewsData.php
    @@ -0,0 +1,222 @@
    +    // @todo Fix this when we support block content revision links.
    ...
    +    // @todo Fix this when we support block content revision links.
    ...
    +    // @todo Fix this when we support block content revision links.
    ...
    +    // @todo Fix this when we support block content revision links.
    

    Can we add the link to the d.o issue for adding revision UI?

  5. +++ b/core/modules/block_content/src/Plugin/views/field/Link.php
    @@ -0,0 +1,94 @@
    +    if (!$block_content->access('view')) {
    

    This should be 'update' there is no 'viewing' block content - see 'entity.block_content.canonical' route

  6. +++ b/core/modules/block_content/src/Plugin/views/field/Link.php
    @@ -0,0 +1,94 @@
    +    $text = !empty($this->options['text']) ? $this->options['text'] : $this->t('View');
    

    And then I suppose this should default to 'Edit' - although I see we have an 'edit' one - so maybe this one can just be dropped?

  7. +++ b/core/modules/block_content/src/Plugin/views/field/Path.php
    @@ -0,0 +1,113 @@
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function query() {
    +    $this->ensureMyTable();
    +    $this->addAdditionalFields();
    +  }
    

    Is this needed? If so can you add a comment indicating what it does differently to parent?

  8. +++ b/core/modules/block_content/src/Plugin/views/wizard/BlockContent.php
    @@ -0,0 +1,67 @@
    + * @todo: replace numbers with constants.
    
    +++ b/core/modules/block_content/src/Plugin/views/wizard/BlockContentRevision.php
    @@ -0,0 +1,70 @@
    + * @todo: replace numbers with constants.
    

    Do we have an issue for that?

  9. +++ b/core/modules/block_content/src/Plugin/views/wizard/BlockContentRevision.php
    @@ -0,0 +1,70 @@
    +    // @todo Fix this when we support block content revision links.
    

    To be honest, I think we could do this UI with views :)

Manual review coming

larowlan’s picture

Manual testing:

Add a new view (wizard)

Add some fields - delete link shows as broken/missing:

Attempt to view the saved view (table with title (linked), edit and delete links).

jibran’s picture

Status: Needs work » Needs review
FileSize
26.75 KB
83.33 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 83,435 pass(es). View

First of all excellent review. Thanks @larowlan.
#35

  1. Can we please wait for @dawehner to confirm?
  2. O come on! you don't have to point out it 37 times :P. Nice catch. Fixed :D
  3. Very nice catch. Fixed.
  4. Done.
  5. Removed LinkEdit field plugin and updated Link field plugin.
  6. Same as above.
  7. I have no idea what is this. I asked @damiankloip at Drupalcon Amsterdam why we have to do this he explained it to me then and I don't know the reason now :$. @dawehner please suggest the comment. I'll I add it. So not fixed yet.
  8. No idea perhaps @dawehner knows.
  9. Not until we can fix point 4 of the review.

Thanks for the manual testing in #36. Seriously jibran-- for this kind of mess. I have fixed it now and added a small test for it as well.

PS: Still waiting for @dawehner's re-entry in the issue :D

jibran’s picture

Issue summary: View changes

Updated the old issue summary.

jibran’s picture

FileSize
34.01 KB
51.94 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 83,377 pass(es). View

I talked to @dawehner in IRC here is the conoversation just for the record.

[02:28]	dawehner	jibran: ... we have generic entity integrations for a lot of things
[02:28]	jibran	dawehner: yeah
[02:29]	jibran	dawehner: I copied almost all of BlockViewData from NodeViewData
[02:29]	dawehner	jibran: ... well node is all special
[02:30]	jibran	dawehner: yeah that is why I asked your opinion
[02:30]	jibran	dawehner: we can certainly drop some stuff
[02:30]	jibran	dawehner: I have commented out some code as well
[02:39]	dawehner	jibran: well yeah copying from node is a bad idea, its hyper-special
[02:40]	jibran	dawehner: ok we can drop stuff no worries
[02:46]	dawehner	jibran: so yeah ideally you would not have to write any views integration at all
[02:48]	dawehner	jibran: you also need no wizard for example
[02:48]	jibran	dawehner: ok
[02:51]	dawehner	jibran: you also probably don't need any links, given that the entity operations field will be available as well
[02:52]	jibran	dawehner: ok

Removed wizards and links from the patch.

dawehner’s picture

  1. +++ b/core/modules/block_content/config/schema/block_content.views.schema.yml
    @@ -0,0 +1,51 @@
    +views.field.block_content:
    +  type: views_field
    +  label: 'Block Content'
    +  mapping:
    +    link_to_block_content:
    +      type: boolean
    +      label: 'Link this field to the original piece of block content'
    +
    

    Can we add a todo here which points to https://www.drupal.org/node/2322949 ?

  2. +++ b/core/modules/block_content/src/BlockContentViewsData.php
    @@ -0,0 +1,183 @@
    +
    +    $data['block_content']['id']['field']['id'] = 'block_content';
    +
    +    $data['block_content_field_data']['info']['field']['id'] = 'block_content';
    +    $data['block_content_field_data']['info']['field']['link_to_block_content default'] = TRUE;
    +
    +    $data['block_content_field_data']['type']['field']['id'] = 'block_content_type';
    +
    

    In case we write new handlers can we please write them in ways that updates after #2322949: Implement generic entity link view field handlers are less? So for example this would be name it 'link_to_entity' or something along this lines

  3. +++ b/core/modules/block_content/src/BlockContentViewsData.php
    @@ -0,0 +1,183 @@
    +    if ($this->moduleHandler->moduleExists('content_translation')) {
    +      $data['block_content']['translation_link'] = array(
    +        'title' => $this->t('Translation link'),
    +        'help' => $this->t('Provide a link to the translations overview for custom blocks.'),
    +        'field' => array(
    +          'id' => 'content_translation_link',
    +        ),
    +      );
    +    }
    

    Can we add a todo to make that kind of integration automatic, introduced in content_translation method itself?

  4. +++ b/core/modules/block_content/src/BlockContentViewsData.php
    @@ -0,0 +1,183 @@
    +
    +    // @todo Fix this when we support block content bulk form.
    +    // @see https://www.drupal.org/node/2375589
    +    // $data['block_content']['block_content_bulk_form'] = array(
    +    //   'title' => $this->t('Block Content operations bulk form'),
    +    //   'help' => $this->t('Add a form element that lets you run operations on multiple block contents.'),
    +    //   'field' => array(
    +    //     'id' => 'block_content_bulk_form',
    +    //   ),
    +    // );
    +
    

    I highly doubt that you will EVER need that

  5. +++ b/core/modules/block_content/src/BlockContentViewsData.php
    @@ -0,0 +1,183 @@
    +    // Bogus fields for aliasing purposes.
    +
    +    // @todo Add similar support to any date field
    +    // @see https://drupal.org/node/2337507
    +    $data['block_content_field_data']['changed_fulldate'] = array(
    +      'title' => $this->t('Updated date'),
    +      'help' => $this->t('Date in the form of CCYYMMDD.'),
    +      'argument' => array(
    +        'field' => 'changed',
    +        'id' => 'date_fulldate',
    +      ),
    +    );
    +
    +    $data['block_content_field_data']['changed_year_month'] = array(
    +      'title' => $this->t('Updated year + month'),
    +      'help' => $this->t('Date in the form of YYYYMM.'),
    +      'argument' => array(
    +        'field' => 'changed',
    +        'id' => 'date_year_month',
    +      ),
    +    );
    +
    +    $data['block_content_field_data']['changed_year'] = array(
    +      'title' => $this->t('Updated year'),
    +      'help' => $this->t('Date in the form of YYYY.'),
    +      'argument' => array(
    +        'field' => 'changed',
    +        'id' => 'date_year',
    +      ),
    +    );
    +
    +    $data['block_content_field_data']['changed_month'] = array(
    +      'title' => $this->t('Updated month'),
    +      'help' => $this->t('Date in the form of MM (01 - 12).'),
    +      'argument' => array(
    +        'field' => 'changed',
    +        'id' => 'date_month',
    +      ),
    +    );
    +
    +    $data['block_content_field_data']['changed_day'] = array(
    +      'title' => $this->t('Updated day'),
    +      'help' => $this->t('Date in the form of DD (01 - 31).'),
    +      'argument' => array(
    +        'field' => 'changed',
    +        'id' => 'date_day',
    +      ),
    +    );
    +
    +    $data['block_content_field_data']['changed_week'] = array(
    +      'title' => $this->t('Updated week'),
    +      'help' => $this->t('Date in the form of WW (01 - 53).'),
    +      'argument' => array(
    +        'field' => 'changed',
    +        'id' => 'date_week',
    +      ),
    +    );
    +
    

    can we drop that please? This is a really edge case feature for views.

  6. +++ b/core/modules/block_content/src/BlockContentViewsData.php
    @@ -0,0 +1,183 @@
    +    // Advertise this table as a possible base table.
    +    $data['block_content_revision']['table']['base']['help'] = $this->t('Block Content revision is a history of changes to block content.');
    +    $data['block_content_revision']['table']['base']['defaults']['title'] = 'info';
    +
    +    // @todo the ID field needs different behaviour on revision/non-revision
    +    //   tables. It would be neat if this could be encoded in the base field
    +    //   definition.
    +    $data['block_content_revision']['id']['relationship']['id'] = 'standard';
    +    $data['block_content_revision']['id']['relationship']['base'] = 'block_content';
    +    $data['block_content_revision']['id']['relationship']['base field'] = 'id';
    +    $data['block_content_revision']['id']['relationship']['title'] = $this->t('Block Content');
    +    $data['block_content_revision']['id']['relationship']['label'] = $this->t('Get the actual block content from a block content revision.');
    +
    +    $data['block_content_revision']['revision_id']['relationship']['id'] = 'standard';
    +    $data['block_content_revision']['revision_id']['relationship']['base'] = 'block_content';
    +    $data['block_content_revision']['revision_id']['relationship']['base field'] = 'revision_id';
    +    $data['block_content_revision']['revision_id']['relationship']['title'] = $this->t('Block Content');
    +    $data['block_content_revision']['revision_id']['relationship']['label'] = $this->t('Get the actual block content from a block content revision.');
    +
    +    $data['block_content_revision']['revision_log']['field']['id'] = 'xss';
    +
    +    $data['block_content_field_revision']['table']['group'] = $this->t('Custom Block revision');
    +
    +    $data['block_content_field_revision']['table']['join']['block_content_revision']['left_field'] = 'revision_id';
    +    $data['block_content_field_revision']['table']['join']['block_content_revision']['field'] = 'revision_id';
    +    $data['block_content_field_revision']['table']['join']['block_content_revision']['type'] = 'INNER';
    +
    +    $data['block_content_field_revision']['table']['join']['block_content']['left_field'] = 'revision_id';
    +    $data['block_content_field_revision']['table']['join']['block_content']['field'] = 'revision_id';
    +
    +    // @todo Fix this when we support block content revision links.
    +    // @see https://www.drupal.org/node/1984588
    +    // $data['block_content_field_revision']['info']['field']['id'] = 'block_content_revision';
    +
    +    // @todo Figure out do we need this or not.
    +    // $data['block_content_field_revision']['langcode']['field']['id'] = 'block_content_language';
    +
    +    // @todo Fix this when we support block content revision links.
    +    // @see https://www.drupal.org/node/1984588
    +    // $data['block_content_revision']['link_to_revision'] = array(
    +    //   'field' => array(
    +    //     'title' => $this->t('Link to revision'),
    +    //     'help' => $this->t('Provide a simple link to the revision.'),
    +    //     'id' => 'block_content_revision_link',
    +    //     'click sortable' => FALSE,
    +    //   ),
    +    // );
    +
    +    // @todo Fix this when we support block content revision links.
    +    // @see https://www.drupal.org/node/1984588
    +    // $data['block_content_revision']['revert_revision'] = array(
    +    //   'field' => array(
    +    //     'title' => $this->t('Link to revert revision'),
    +    //     'help' => $this->t('Provide a simple link to revert to the revision.'),
    +    //     'id' => 'block_content_revision_link_revert',
    +    //     'click sortable' => FALSE,
    +    //   ),
    +    // );
    +
    +    // @todo Fix this when we support block content revision links.
    +    // @see https://www.drupal.org/node/1984588
    +    // $data['block_content_revision']['delete_revision'] = array(
    +    //   'field' => array(
    +    //     'title' => $this->t('Link to delete revision'),
    +    //     'help' => $this->t('Provide a simple link to delete the content revision.'),
    +    //     'id' => 'block_content_revision_link_delete',
    +    //     'click sortable' => FALSE,
    +    //   ),
    +    // );
    +
    

    Maybe dump question .... but are you sure that the standard integration is not enough?

    Maybe next time not just c&p everything :p

  7. +++ b/core/modules/block_content/src/Plugin/views/field/Type.php
    @@ -0,0 +1,65 @@
    +/**
    + * Field handler to translate a block content type into its readable form.
    + *
    + * @ingroup views_field_handlers
    + *
    + * @ViewsField("block_content_type")
    + */
    +class Type extends BlockContent {
    +
    +  /**
    

    Can we add a todo pointing to #2363811: Add a generic entity bundle field or actually better not even start trying to support it?

  1. +++ b/core/modules/block_content/src/Tests/Views/BlockContentTestBase.php
    @@ -0,0 +1,111 @@
    +  protected function createBlockContent(array $settings = array()) {
    +    $status = 0;
    +    $settings += array(
    +      'info' => $this->randomMachineName(),
    +      'type' => 'basic',
    +      'langcode' => 'en',
    +    );
    +    if ($block_content = entity_create('block_content', $settings)) {
    +      $status = $block_content->save();
    +    }
    +    $this->assertEqual($status, SAVED_NEW, String::format('Created block content %info.', array('%info' => $block_content->label())));
    +    return $block_content;
    +  }
    ...
    +  /**
    +   * Creates a custom block type (bundle).
    +   *
    +   * @param array $values
    +   *   An array of settings to change from the defaults.
    +   *
    +   * @return \Drupal\block_content\Entity\BlockContentType
    +   *   Created custom block type.
    +   */
    +  protected function createBlockContentType(array $values = array()) {
    +    // Find a non-existent random type name.
    +    if (!isset($values['id'])) {
    +      do {
    +        $id = strtolower($this->randomMachineName(8));
    +      } while (BlockContentType::load($id));
    +    }
    +    else {
    +      $id = $values['id'];
    +    }
    +    $values += array(
    +      'id' => $id,
    +      'label' => $id,
    +      'revision' => FALSE
    +    );
    +    $bundle = entity_create('block_content_type', $values);
    +    $status = $bundle->save();
    +    block_content_add_body_field($bundle->id());
    +
    +    $this->assertEqual($status, SAVED_NEW, String::format('Created block content type %bundle.', array('%bundle' => $bundle->id())));
    +    return $bundle;
    +  }
    

    May be we could introduce a trait?

  2. +++ b/core/modules/block_content/src/Tests/Views/RevisionRelationshipsTest.php
    @@ -0,0 +1,96 @@
    + * @group block_content
    + */
    +class RevisionRelationshipsTest extends ViewTestBase {
    +
    

    <3 all this test coverage

webchick’s picture

Component: custom_block.module » block_content.module
dawehner’s picture

Status: Needs review » Needs work

SO yeah this needs work ...

jibran’s picture

Status: Needs work » Needs review
FileSize
12.03 KB
45.03 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 84,075 pass(es), 5 fail(s), and 12 exception(s). View

For #40

  1. Fixed.
  2. Done.
  3. Done.
  4. Removed.
  5. Dropped.
  6. Removed. C&P makes you better core developer :P
  7. Done

Status: Needs review » Needs work

The last submitted patch, 43: 1984582-43.patch, failed testing.

jibran’s picture

Status: Needs work » Needs review
FileSize
2.26 KB
45 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 84,149 pass(es), 2 fail(s), and 10 exception(s). View

Some fixes.

Status: Needs review » Needs work

The last submitted patch, 45: 1984582-45.patch, failed testing.

Berdir’s picture

I was helping someone to debug this at our local sprint yesterday. Looks like EntityViewsData does not generate the complete views data for revisionable entities, joins/relationships are missing. NodeViewsData is adding a bunch of stuff.

Maybe it would be easier to open a separate issue and move more logic from NodeViewsData into EntityViewsData and make that work before we complete this here.

dawehner’s picture

@jibran
Nevertheless please create the necessary follow ups.

jibran’s picture

Assigned: Unassigned » jibran

Working on this one.

jibran’s picture

Assigned: jibran » Unassigned
Status: Needs work » Needs review
Issue tags: +Need issue summary update
Related issues: +#2410275: EntityViewsData should add relationships to revision tables, +#2410261: content_translation should add views translation link field, +#2322949: Implement generic entity link view field handlers, +#2363811: Add a generic entity bundle field
FileSize
2.33 KB
46.5 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 85,309 pass(es). View

Fixed the test fails. Created all the follow ups. One day we will remove BlockContentViewsData. @dawehner please add BE in IS.

dawehner’s picture

Issue summary: View changes

Added the BE

jibran’s picture

Issue tags: -Need issue summary update

Perfect now RTBC?

kattekrab’s picture

Ok - I had a bit of a play around with simplytest.me

Followed @larowlan's lead from #36 .

I didn't hit the errors he did, so that's good!

I was able to select custom block, and custom block revisions from the pull down list, which I can't do in the d8 install I've been playing with.

With patch.

Without patch.

I also made a couple of custom blocks, and managed to create a block display view of them.

I noticed a couple of other things - but not sure they are related to this particular issue, so will reach out on irc about them first.

larowlan’s picture

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

yup RTBC++

dasjo’s picture

Also tested this during #SprintWeekend and worked great so far!

When building the view i find it confusing that the block labels are named "description", buts that's totally decoupled from this ticket...

kattekrab’s picture

Yeah - I found that weird too. Why ARE the block labels called description instead of title?

tim.plunkett’s picture

Because it's been called "description" since box.module and block.module were merged in 2002, before Drupal 4.0.0: http://cgit.drupalcode.org/drupal/commit/?id=a4b5005640228b8f5cec843e46c...

kattekrab’s picture

Huh.

Thanks Tim.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/block_content/src/Plugin/views/field/Type.php
    @@ -0,0 +1,67 @@
    +  /**
    +   * Renders block content type as human readable name, unless using machine_name option.
    +   */
    +  function renderName($data, $values) {
    

    missing scope, argument documentation, and comment is longer than 80 chars.

  2. +++ b/core/modules/block_content/src/Tests/Views/BlockContentFieldFilterTest.php
    @@ -0,0 +1,109 @@
    +
    +  function setUp() {
    

    Let's get an {@inheritdoc} here.

jibran’s picture

Status: Needs work » Needs review
FileSize
46.79 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 85,645 pass(es). View
1.7 KB

@alexpott thanks for the review fixed everything.

kattekrab’s picture

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

I did another manual test with simplytest.me

Created 3 custom blocks, made a block view of them, made a couple of revisions, made a page view of the revisions.
All works well.

Found some oddities when creating the Revisions view though - but I think that legitimately should be followed up in the postponed ticket about block revisions #1984588: Add a UI for viewing/reverting custom block revisions

This issue, about adding views support for blocks, seems nailed.

Thanks all. RTBC.

Wim Leers’s picture

#58: WOW, awesome detective work!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

I debated about whether we should push this to 8.1 but consider it is ready and the impact extremely self contained happy to commit. Plus all entities having views integration is an extremely good thing for d8's flexibility. Committed 663c371 and pushed to 8.0.x. Thanks!

Thank you for adding the beta evaluation to the issue summary.

  • alexpott committed 663c371 on 8.0.x
    Issue #1984582 by jibran, kattekrab, dawehner, larowlan: Add views...
jibran’s picture

Yay!! custom blocks has views support now.
Thank you @alexpott for the commit.
Thank you @kattekrab and @larowlan for the reivew.
Thank you @dawehner for all the help and support.
See you all in #2375589: Convert custom block library page to views.

Status: Fixed » Closed (fixed)

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