Spin-off from #1871696-109: Convert block instances to configuration entities to resolve architectural issues :

- We have the 'block' plugin type, plugins of this type are referred to as "block" plugins, they implement BlockInterface and possibly extend BlockBase. So far so good.
- #1871696: Convert block instances to configuration entities to resolve architectural issues introduces Block as a config entity class. So a Block $entity has an associated plugin object, but itself does not implement BlockInterface nor extends BlockBase. --> misleading naming WTF :-)

As a possible clarification:
Go with : 'blocks' are the entities; plugins are not blocks, but block handlers ?
Thus,
BlockManager -> BlockHandlerManager,
BlockBase -> BlockHandlerBase,
BlockInterface -> BlockHandlerInterface
...

Comments

tim.plunkett’s picture

Issue tags: +Blocks-Layouts, +Block plugins

Tagging. Thanks for opening this.

effulgentsia’s picture

Maybe this is only partially related, but I'd like us to consider having Block plugins not depend on Block entities at all, but rather, for the entity to pass in and read back a $configuration values array only. However, even if we did that, we'd still have Block entities depending on Block plugins, so this issue might still be relevant for the sanity of that code.

tim.plunkett’s picture

The main use case for a plugin needing the entity:

BlockInterface::blockBuild() is responsible for returning the contents of a block.

A view can be configured to override the title.
Therefore, Drupal\views\Plugin\block\block\ViewsBlock::blockBuild() needs to be able to update the title dynamically, regardless of whats in the YAML file.

tim.plunkett’s picture

I'd also like to note that Views display plugins get a reference to their view, and filters and formats will do the same thing. I image that image effects and image styles will also follow suit.

effulgentsia’s picture

I image that image effects and image styles will also follow suit.

We'll see, but I hope not. One of the nice things about plugins is their ability to be contained within larger config structures of different kinds. For example, field formatter settings can be contained in an EntityDisplay or in a View, and at different parts of those structures. Similarly, I'd like contrib modules to be able to use image effect plugins within their own config structures, not just within image styles.

Views plugins getting a reference to the View probably has enough justification for sacrificing this level of reuse, but I'd like to be careful about spreading that pattern too broadly.

Therefore, Drupal\views\Plugin\block\block\ViewsBlock::blockBuild() needs to be able to update the title dynamically, regardless of whats in the YAML file.

And have that change automatically saved back in the block entity? I wonder if there's some other way to accomplish that.

eclipsegc’s picture

Views plugins getting a reference to the View probably has enough justification for sacrificing this level of reuse, but I'd like to be careful about spreading that pattern too broadly.

Yes this! A million times this!

Therefore, Drupal\views\Plugin\block\block\ViewsBlock::blockBuild() needs to be able to update the title dynamically, regardless of whats in the YAML file.

And have that change automatically saved back in the block entity? I wonder if there's some other way to accomplish that.

The design here was that the BlockPluginBase::configuration variable would hold all of this stuff. it's public and actually has getters and setters because we intended on configurable plugins becoming a subset of plugins that had discrete reusable parts. The render controller can most definitely parse that any way it likes and extract any key and set the label however it pleases. This is true of anything that's in the configuration. It's available at all times, and should (or at least was intended to) contain all the values from the configuration (entity or not). The entity is not necessary for the block.

Eclipse

yched’s picture

Another +[a lot] on what effulgentsia said.
Ideally, image effects should not assume they're used as part of something called "image styles", nor have to know anything about those - and similar patterns where applicable : filters wrt text formats, field formatters wrt entity displays or views...
Separation of concern ++.

Slight distinction though between "in which context I'm used" and "on which objects I'm working on" : it's perfectly fine IMO for a $formatter plugin to know which $field_instance it works on. A formatter does stuff on a specific field, that's part of the contract of being a formatter.

Not familiar enough with the "block plugins & entities" code to decide where this specific case stands.

fago’s picture

Ideally, image effects should not assume they're used as part of something called "image styles", nor have to know anything about those - and similar patterns where applicable : filters wrt text formats, field formatters wrt entity displays or views...
Separation of concern ++.

Totally. The way I solved this in Rules 7.x for actions and conditions is introducing an array of parameter information, describing each needed parameter/variable/whatever you call it. Then the rule element gets configured with a plain array of $settings containing all the necessary configuration.
That way, stuff using the action/condition/configurable/.. knows what the required input is and can configure it as necessary for the required context, while the action/condition/configurable/.. does not need to know anything about that - it just relies on getting values for the described parameter/variable/whatever.

In d8, we already have typed data definitions which fit perfectly for describing each needed parameter/variable/whatever. We still have to build the missing parts though - what I roughly described over at #1846172: Replace the actions API. Not sure whether action/condition parameter configuration is perfect match for other "configurables" though - it's perhaps a bit more sophisticated than needed usually.

Regarding decoupling block plugin and block entity, I think we should have the block plugins, the plugin configuration and associated block configuration entities, which optionally can take care of persisting the plugin configuration via a config entity (if you need to). Thus, block plugins should not assume to work with CMI config object or config entities, they should provide us with a $configuration data structure we can manage as we want, e.g. don't persist it at all, serialize it as part of a bigger data structure (rule config, views config, ..), or persist it with an associated config entity.

eclipsegc’s picture

Thus, block plugins should not assume to work with CMI config object or config entities, they should provide us with a $configuration data structure we can manage as we want, e.g. don't persist it at all, serialize it as part of a bigger data structure (rule config, views config, ..), or persist it with an associated config entity.

+1000000000 to this as well.

Eclipse

tim.plunkett’s picture

As long as you solve this without removing ViewsBlock ability to set the entity label on the fly, without the insane hacks that I removed, more power to you.

xjm’s picture

effulgentsia’s picture

Most of the comments so far on this issue are more relevant for #1927608: Remove the tight coupling between Block Plugins and Block Entities, but the original issue summary here is still relevant: even if the two are decoupled, the same name for two different concepts is not ideal.

eclipsegc’s picture

I completely agree. I think we should seriously consider moving block plugins out of the block module entirely and renaming them and just having a block entity.

Eclipse

tim.plunkett’s picture

Just to crosspost an idea I had in #1927608: Remove the tight coupling between Block Plugins and Block Entities, I suggested renaming the entity type to 'block_wrapper'. Since that's all it does, it wraps a block.

tim.plunkett’s picture

Assigned: Unassigned » tim.plunkett
Status: Active » Postponed

Okay, we might have some consensus on block_wrapper, but it will be a direct follow-up to #1927608: Remove the tight coupling between Block Plugins and Block Entities

tim.plunkett’s picture

StatusFileSize
new4.8 KB

I tried to rename the access hooks similar to #1927608-124: Remove the tight coupling between Block Plugins and Block Entities, but they're tied to the entity type names. Posting it here to save the work.

effulgentsia’s picture

Title: Block $entity, Block $plugin » It's confusing that "Block" sometimes refers to the entity and sometimes to the plugin

Retitling. An example of the confusion, even after #1927608: Remove the tight coupling between Block Plugins and Block Entities, is that hook_block_view_alter() acts on the plugin and hook_block_access() acts on the entity, but you wouldn't know that by those hook names.

eclipsegc’s picture

wrong issue, sorry...

yched’s picture

Title: It's confusing that "Block" sometimes refers to the entity and sometimes to the plugin » It's confusing that "Block/$block" sometimes refers to the entity and sometimes to the plugin

It's confusing that "Block" sometimes refers to the entity and sometimes to the plugin

Well, the only "Block" class is the entity. The WTF is that Block "not implements BlockInterface, not extends BlockBase", since those are for the plugins.
Then there is "$block, the plugin" and "$block, the entity" :-)

tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned
Status: Postponed » Needs work

Okay.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new35.68 KB

This stemmed from some discussion in Prague.

Status: Needs review » Needs work

The last submitted patch, block-1890534-21.patch, failed testing.

eclipsegc’s picture

That patch sort of obfuscates further what is going on. Kinda meh about it. :-(

What if we changed the block entity class to BlockConfig and just tried to make a sane pass through the code accordingly? Then we can say something like "You have a bunch of Block Configuration objects and they can return the fully configured block plugin for you." etc.

Thoughts?

Eclipse

yched’s picture

FWIW, Field & FieldInstance config entities are being renamed FieldConfig & FieldInstanceConfig

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

tim.plunkett’s picture

Issue summary: View changes
Issue tags: -Blocks-Layouts

Not actively part of the Blocks-Layouts work.

effulgentsia’s picture

Version: 8.2.x-dev » 8.3.x-dev
tim.plunkett’s picture

This is still very confusing, by the way. Just not part of the current work being done.

Version: 8.3.x-dev » 8.4.x-dev

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

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

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

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.

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.

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.

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.

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.

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.

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

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. 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 work » Postponed (maintainer needs more info)
Issue tags: +stale-issue-cleanup

Thank you for creating this issue to improve Drupal.

We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.

Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

Thanks!

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.