Problem/Motivation
It seems currently, the default form is offered.
Drupal 8 has this wonderful concept for form modes.
Proposed resolution
Allow selection of a form mode in the block settings.
Thus, field widgets and visibility can be properly configured, specifically for the block.
Remaining tasks
User interface changes
API changes
| Comment | File | Size | Author |
|---|---|---|---|
| #54 | fixed_EntityContextDefinition.patch | 15.89 KB | mlo |
| #53 | 2424739-53.patch | 15.87 KB | manojbisht_drupal |
| #52 | 2424739-51.patch | 15.58 KB | manojbisht_drupal |
| #50 | 2424739-47.patch | 15.32 KB | manojbisht_drupal |
| #47 | 2424739-46.patch | 11.2 KB | manojbisht_drupal |
Issue fork entityform_block-2424739
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #1
berdirNote that all other form modules usually imply to edit an existing entity, so this is not useful unless we also add context support to use an existing entity.
Which possibly requires to use the same approach as entity_view, with a deriver for each entity type + context for that entity type.
Comment #2
almaudoh commentedBumping this. It would be nice to have form modes. I'll see if I can make out some time to work on this.
Comment #3
arosboro commentedThis is probably going to break tests. I implemented a deriver for each entity type to display the entity from context as an update form. I am using this with panels and page manger, but have not tested the admin/structure/block side of things.
Comment #5
arosboro commentedI've sorted my additions out to play nicely with the original block plugin. The attached patch has a migration path that updates the plugin id entityform_block to entityform_block_add for any configuration. A dependency for ctools is introduced with the new Edit and Delete plugins, because they implement Drupal\ctools\Plugin\Deriver\EntityDeriverBase.
I've introduced two new classes and renamed EntityEditFormBlock.php to EntityFormBlockAdd.php.
* EntityEditFormBlock -> EntiyFormBlockAdd
* EntityFormBlockEdit
* EntityFormBlockDelete
Warning: This patch makes database updates to rename any block ids containing entityform_block to entityform_block_add. This is applied to settings of configuration entities with entity type id 'page_variant' or 'block'.
I've made an effort so that the tests may pass, so I'm placing this back in "Needs Review" status.
Comment #7
arosboro commentedAdd test_dependencies key to info.yml.
Comment #8
arosboro commentedComment #10
arosboro commentedThis patch removes the hard dependency for ctools and adds the new features as individual modules, entityform_block_edit and entityform_block_delete. I will try to write unit tests for the new modules, but the existing module's unit tests should pass now.
Comment #11
arosboro commentedComment #12
arosboro commented:-/ It looks like the test configuration needs to be updated to discover EntityFormBlockAddTest.php. They do pass locally.
Comment #13
berdirThanks for working on this.
I don't understand why this needs to be so complicated.
We can't we just add a select to the existing block that allows to select that? I guess the context? In theory, it should be possible to specify that it accepts any entity with type "entity", but not sure if that actually works, possibly not.
But even then, we could limit it to a single block/deriver that accepts the entity context and it doesn't need to be delete/edit specific.
And I think we should avoid renaming the existing stuff, that wil llikely cause a lot of pain (there could be other things that use blocks, e.g. block_field), we could just add a new one with a different name? Maybe the naming of that won't be perfect, but I can live with that.
And the only thing that EntityDeriverBase provides is a constructor and create method, I'd rather copy that than add a dependency which can cause troubles for users that are updating.
Also not sure why you add a composer.json file that doesn't have anything special?
Comment #14
arosboro commentedI re-rolled this with a deriver and context aware block that extends the original addform_block. I removed the dependency for ctools.
composer.json was me attempting to get the tests to pass, thinking it would help with dependencies.
Comment #16
arosboro commentedHere's an updated patch that should pass tests.
Comment #17
jibranI have created the patch form from the scratch.
Updated EFEB to use new EntityFormDeriver.
Comment #18
jibranComment #21
jibranComment #23
jibranThis patch works for both add and edit pages.
Comment #25
jibranNow it works with custom view modes.
Comment #27
jibranMinor doc fixes.
Comment #29
jibranLet's review it first before fixing the tests.
Comment #30
jibranWIth proper form display.
Comment #32
sam152 commentedReview as follows.
This block needs an associated schema definition.
Should this be form_mode?
Should be form_mode.
Should be able to use entity.form_builder::getForm
All this effort and no unit test? :)
This is the second time comment has been excluded. Should be it's own function somewhere which can exclude entity types in the one place.
Why is this needed? If you load a bundle config entity type, should the associated content entity already be added to the list of derivatives?
Comment #33
jibranThanks, for the review.
/node/{node}/editpage we have the node in context but on/node/add/{node_type}we don't have node context we have node type context. This works around that it provides a node type context and use node as derivative ID.Comment #34
sam152 commentedBut wont
/node/{node}/editnot satisfy the context requirements anymore, because$this->derivatives[$bundle_of]is overriden thenodederivative to requirenode_type?Perhaps needs a good comment.
Comment #35
jibranIndeed you are correct. Updated the patch for that.
Comment #37
jibranComment #38
jibranFixed the block access.
Comment #40
jibranFound another issue
Comment #42
piggito commentedRerolled last patch
Comment #44
piggito commentedAdding config schema for block deriver
Comment #45
acbramley commentedAs per this CR
Comment #47
manojbisht_drupal commentedUploading patch to take into user from current url context
Comment #48
manojbisht_drupal commentedComment #50
manojbisht_drupal commentedRerolling Patch
Comment #52
manojbisht_drupal commentedRerolling the patch
Comment #53
manojbisht_drupal commentedRerolling patch for access, if usr has access to form
Comment #54
mlo commentedHi, I have a problem with de last version of the patch.
PHP message: AssertionError: assert(strpos($data_type, 'entity:') !== 0 || $this instanceof EntityContextDefinition) in /var/www/html/web/core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php on line 115 #0 /var/www/html/web/core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php(115):I changed ContextDefinition by EntityContextDefinition to try and solve the error.
Comment #57
unstatu commentedHello all,
I have approached the problem in a completely different way. Sorry for adding a divergence here. If you want, I can create a separate issue for this even if the objective is the same.
I agree with the latest comment of Berdir when he stated that this issue is getting too complicated. Maybe I am missing something but I think that the approach followed in this MR https://git.drupalcode.org/project/entityform_block/-/merge_requests/3 is much easier.
This is a PoC that needs more work:
- Only allow the users to select the form modes that belong to the selected entity type (probably the Form mode field should be loaded via AJAX)
- To test it
Also, there is something that I don't understand about the block context and the edit/delete permissions. I don't know why we have to care about this in this issue if we are not caring about it (AFAIK) when displaying the default form mode. Is not Drupal core checking the permissions when showing the form? Even if it's not the default one?
Please let me know if it worths to continue with this path or if I am missing something. Thanks!