Problem/Motivation

An entity type might have more than one form operation for different fields of the entity. If the conflict module is active then it should be able to auto merge an entity concurrently edited with two different form operations in case they do not share the same fields.

Proposed resolution

Add a setting according to which an entity type should be locked only for the current form operation. Additionally provide white and black lists for operations. The operations could be retrieved through array_keys($entity_type->getHandlerClasses()['form']);.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

hchonov created an issue. See original summary.

hchonov’s picture

Status: Needs work » Needs review
StatusFileSize
new22.94 KB

Status: Needs review » Needs work

The last submitted patch, 2: 2916747-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

kfritsche’s picture

StatusFileSize
new24.93 KB
new3.04 KB

Fixed the current tests and found a small issue, which I needed to fix if form op is not used.

New tests would be nice, but not sure if I get to it soon :/

kfritsche’s picture

Status: Needs work » Needs review
kfritsche’s picture

StatusFileSize
new3.08 KB
new25.06 KB

Fixing notice on the settings form which will be introduced when applying #2911446: Add an option to the configuration form for selecting all bundles

hchonov’s picture

Thank you, @kfritsche!

One not really important nit:

+++ b/config/schema/content_lock.schema.yml
@@ -13,3 +13,24 @@ content_lock.settings:
\ No newline at end of file

We need to add a new line at the end of the file.

After thinking about this feature over again, I think that on the settings form we should disable the opposite list when checking form operations on one of the lists. I mean if a user selects a checkbox on the black list, then the options on the white list should be disabled and on form submit the white list should be saved empty. What do you think about this?

kfritsche’s picture

StatusFileSize
new17.69 KB

I agree to you proposal and would suggest to re-do it with 3 radio buttons (off / white list / black list) and only one time with the form ops checkboxes.

As a Drupal user is kind of familiar with this behavior from the block pages config - Configure Block Pages view

kfritsche’s picture

StatusFileSize
new24.79 KB
new10.01 KB

Refactored config for this patch. I think the config is now better and more readable.

The new structure is now:

form_op_lock:
  node:
    mode: 0 or 1 or 2 (disabled, whitelisted, blacklisted)
    values: 
      - edit
      - xxx

This changed is also reflected in the admin UI having per entity a radio with 3 options and the form ops checkboxes if whitelist or blacklist is selected.

Status: Needs review » Needs work

The last submitted patch, 9: 2916747-9.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

hchonov’s picture

I agree to you proposal and would suggest to re-do it with 3 radio buttons (off / white list / black list) and only one time with the form ops checkboxes.

@kfritsche++ I like your idea better than mine :)


+++ b/config/schema/content_lock.schema.yml
@@ -13,3 +13,15 @@ content_lock.settings:
+    form_op_lock:
+    type: mapping
+    mapping:
+      mode:
...
+      values:

Unfortunately the schema is not entirely correct. We need one parent level for the entity type :).

hchonov’s picture

We also have to consider #2911532-26: Lock on entity translation level instead on entity level - we have to add an update hook and create the column for the langcode, which we've missed in the other issue, and also add the column for the form operation.

kfritsche’s picture

Status: Needs work » Needs review
StatusFileSize
new26.86 KB
new2.97 KB

Re-roll and fixed the issue mentioned above. This should then also fix the tests, as the test failed on the schema validation.

hchonov’s picture

Status: Needs review » Reviewed & tested by the community

Look great now. Thank you!

chr.fritsch’s picture

TBH, i have no idea how to test this. Do you have some guidance for me?

hchonov’s picture

Lets assume your custom module's name is "custom_module".

1. Navigate to http://d8/admin/structure/display-modes/form and create a new form mode named "settings", which makes sense if it has different fields defined than the default or the edit form display mode - for this save the new form mode with different fields under http://d8/admin/structure/types/manage/article/form-display.

2. Then in custom_module.module you have to define the new form operation on the entity type:

function custom_module_entity_type_alter(&$entity_types) {
  $entity_types['node']
    ->setLinkTemplate('settings, '/node/{node}/settings')
    ->setFormClass('settings', 'Drupal\node\NodeForm');
}

3. In custom_module.links.task.yml create the link:

entity.node.settings:
  route_name: entity.node.settings
  base_route: entity.node.canonical
  title: 'Settings'

4. In custom_module.routing.yml add the route:

entity.node.settings:
  path: '/node/{node}/settings'
  defaults:
    _entity_form: 'node.settings'
    _title: 'Settings'
  options:
    _node_operation_route: TRUE

5. drush cr :)

What we've achieved now is that we have a new form display using its own form operation and it has edit access to different fields than the edit/default form mode. Now if we have two completely different form displays with no common fields the conflict module will be able to automatically merge the fields if two users concurrently saved both forms - the edit one and the settings one and therefore removes the need for locking the whole entity.

P.S. I hope that I've provided all the steps needed to create a new form operation and form using it, please don't blame me if I am missing something :).

chr.fritsch’s picture

Thank you for the guide. It seems that something is missing ;) I get a 403 when i enter node/6/settings.

hchonov’s picture

I think you have to add a requirement to the route definition e.g.

requirements:
    _entity_access: 'node.update'

So that the route definition looks like this :

entity.node.settings:
  path: '/node/{node}/settings'
  defaults:
    _entity_form: 'node.settings'
    _title: 'Settings'
  options:
    _node_operation_route: TRUE
  requirements:
    _entity_access: 'node.update'
chr.fritsch’s picture

Status: Reviewed & tested by the community » Needs work

Thank you. Now i was able to test it and i really love it.

I have just one remark about the settings page. It's getting a bit confusing now, because the entity type label and "Lock only on entity form operation level." are in the same font style.

kfritsche’s picture

Status: Needs work » Needs review
StatusFileSize
new12.4 KB
new34.99 KB
new224.02 KB

You are right, settings form got a mess.

So I tested around a little bit and checked out other forms in core, what they do. I thought its best comparable with content language form (admin/config/regional/content-language), so I styled it a bit like that.

New Layout of content lock settings

With this layout its also easy to add per bundle configs if needed. I'm unsure if useful, but if needed I would review that patch :P

Also when selecting an entity type above the settings, it auto selects all at the beginning.

I think this is now way better than before.

  • chr.fritsch committed a9402ee on 8.x-1.x authored by kfritsche
    Issue #2916747 by kfritsche, hchonov, chr.fritsch: Consider the form...
chr.fritsch’s picture

Status: Needs review » Fixed

Thank you, the settings form looks much nicer now.

Status: Fixed » Closed (fixed)

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