Awesome module. When configuring a block field it would be nice to specify a "Category" of blocks to make available. Right now you need to select each block within a Category to make available.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bobthebuilder created an issue. See original summary.

yobottehg’s picture

For me it seems like a good idea.

just check the following:
- custom block content entities
- views blocks

Perhaps we could look for the provider of the block.

scottsawyer’s picture

I agree, this would be a great feature. This way, if a new block within a "category" is created, it could be immediately available.

dddbbb’s picture

Came here to suggest something similar.

The issue is two fold in my experience:

1. Maintaining which blocks are available is a chore as blocks continue to be created. Having the option whitelist blocks by block provider rather than each individual block would really help in some uses cases.

2. The exported field instance config includes references to block content if you've chosen to whitelist those kinds of blocks. Config referencing/depending on content feels fragile and doesn't suit use cases where config is used to spin up anew site that might not have any content yet. Again, whitelisting by block provider would get around this.

arthur_lorenz’s picture

Added the possibility to filter available blocks by category.

fago’s picture

Status: Active » Needs work

Thanks, patch looks mostly good. Here a few minor remarks:

  1. +++ b/src/BlockFieldManagerInterface.php
    @@ -20,4 +20,12 @@ interface BlockFieldManagerInterface {
    +   *   An array of block categories.
    

    This should describe the keys and values of the array.
    e.g., type-hint string[] and say:
    A numerically indexed array of block categories.

  2. +++ b/src/Plugin/Field/FieldType/BlockFieldItem.php
    @@ -89,6 +91,15 @@ class BlockFieldItem extends FieldItemBase implements BlockFieldItemInterface {
    +    foreach($categories as $category) {
    

    missing space after foreach

arthur_lorenz’s picture

Thx, fixed the issues.

arthur_lorenz’s picture

Status: Needs work » Needs review
arthur_lorenz’s picture

Assigned: Unassigned » arthur_lorenz

The last submitted patch, 5: block-field-2876110-5.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 7: block-field-2876110-7.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

opi’s picture

tim-diels’s picture

This is working very good, would love to see this in the module.
Latest patch applied nicely.

brayfe’s picture

Applied this patch cleanly to Drupal 8.5.6 with Block Field version 8.x-1.0-alpha8. So far, works well with the current use case I have. Will report back if I find any issues with adding new provider blocks.

jnettik’s picture

Tested this patch on Drupal 8.6.10 and Block Field 1.0-alpha8 with no issues. This patch feels like a huge improvement to Block Field. I'd also love to see it committed.

Bhanu951’s picture

Version: 8.x-1.x-dev » 8.x-1.0-alpha8
Status: Needs work » Reviewed & tested by the community
FileSize
7.22 KB

Modified Patch for 8.x-1.0-alpha8 build.

Edit:

It seems test cases are failing.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 16: block-field-2876110-16.patch, failed testing. View results

michaellander’s picture

Issue tags: +beta blocker
michaellander’s picture

I like the direction this is going. I'm going to take it over and move the options into plugins. This would potentially allow for people to extend the module for more advanced filtering, without requiring us to think through all possible use cases at the moment. An example would be mixing and matching hand picked blocks along with categories, while excluding certain providers and so forth.

michaellander’s picture

Here is a first pass at it. Existing settings will not work, so we'll still need to write an update hook. The update hook can cover alpha settings, as well as fixes for anyone using the existing patch. The tests will also need to be updated as I believe some of the selectors have changed. The plugins were heavily influenced by how Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem implements them. This should give a ton of flexibility for others to extend how selection works with minimal API commitments on our end.

michaellander’s picture

Version: 8.x-1.0-alpha8 » 8.x-1.x-dev
michaellander’s picture

Alright, added:

  • Added missing comments.
  • Update hook, including coverage for earlier versions of this patch.
  • Updated config schema
  • Updated tests install config schema

I think we're close, but would appreciate a few more eyes on it!

michaellander’s picture

Status: Needs work » Needs review
michaellander’s picture

michaellander’s picture

The last submitted patch, 20: block-field-settings-selection-plugins-2876110-20.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

switzern’s picture

The patch in #24 applies cleanly for me against the most current version of the dev branch. I've patched and tested locally on a site that is running Block Field in production and everything is working as expected.

I've tested:
- All existing Block Fields work as they did before the patch.
- The selection method for all existing fields is set to Blocks and available blocks are configured correctly.
- The selection method can be changed to categories for existing Block Fields without affecting settings or functionality of the existing fields.
- New Block Fields can be created and available blocks can be set without error using either the Blocks or Categories selection method.

michaellander’s picture

Re-rolled to latest dev. Fixed some code formatting issues.

Status: Needs review » Needs work

The last submitted patch, 28: block-field-settings-selection-plugins-2876110-28.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

michaellander’s picture

michaellander’s picture

Status: Needs work » Needs review
michaellander’s picture

michaellander’s picture

Ugh, missed 3 lines. Sorry last one.

switzern’s picture

The patch in #33 works well. I've applied against the current HEAD of 8.x-1.x-dev in a local instance of a site that is running Block Field in production and tested all of the same use cases I outlined in #27. For clarity, those use cases are:

- All existing Block Fields work as they did before the patch.
- The selection method for all existing fields is set to Blocks and available blocks are configured correctly.
- The selection method can be changed to categories for existing Block Fields without affecting settings or functionality of the existing fields.
- New Block Fields can be created and available blocks can be set without error using either the Blocks or Categories selection method.

Additional use cases tested:
- Selection method on an existing field changed from blocks to categories and updated selection to include a few specific categories.
- Selection method on that same field changed back to blocks and updated to include only a specific few blocks as available selections.
- Changed settings back to original values and everything functions normally.

  • michaellander committed a529f46 on 8.x-1.x
    Issue #2876110 by michaellander, arthur_lorenz, opi, Bhanu951, switzern...
michaellander’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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