- First commit to issue fork.
- Merge request !29Issue #3110385: Allow hook content_lock_entity_lockable to disable locking → (Merged) created by smustgrave
- Status changed to RTBC
9 months ago 12:38am 26 March 2024 - 🇺🇸United States smustgrave
I believe this is correct but there is no api.php so not 100% sure if this was the intent of the hook. Going off of ✨ Missing content_lock.api.php Needs review
- Status changed to Needs work
9 months ago 2:56pm 26 March 2024 - 🇬🇧United Kingdom alexpott 🇪🇺🌍
I'm not sure the hook even makes sense in it's current form. I thought maybe you could alter the $config but I'm pretty sure the $config array will be passed by value as it is just an array so any changes a module maybe would not count for anything.
In Drupal 7 this was like this
return !in_array(FALSE, module_invoke_all('content_lock_entity_lockable', $entity, $entity_id, $entity_type, $bundle));
so it works like what is being proposed here.I think we should:
- Add automated tests (if we had these we would not have broken this)
- Add documentation i.e. a .api.php with information about how this hook works.
- Use a better implementation - we can do an early return the moment we get a false if we use invokeAllWith()
Here's a sample implementation of a similar hook in another module.
// Check if encryption is prevented due to implementations of // hook_field_encrypt_allow_encryption(). $allowed = TRUE; $this->moduleHandler->invokeAllWith('field_encrypt_allow_encryption', function (callable $hook) use (&$allowed, $entity) { if ($allowed && $hook($entity) === FALSE) { $allowed = FALSE; } });
I think we should expect hook implementations to return TRUE or FALSE and any other type of return should be an error.
Changing to a bug because atm the hook is pointless.
- Assigned to smustgrave
- 🇺🇸United States smustgrave
Added some test coverage.
For the api documentation I just went with $entity, $config, and $form_op for now
Per slack can edit more if needed but assumed most info can be drawn from $entity.Updated contentLock and appears to be working.
- Status changed to RTBC
9 months ago 8:29am 28 March 2024 -
alexpott →
committed 7ad5ec66 on 8.x-2.x authored by
smustgrave →
Issue #3110385 by smustgrave, mattsqd, alexpott: Allow hook...
-
alexpott →
committed 7ad5ec66 on 8.x-2.x authored by
smustgrave →
- Status changed to Fixed
9 months ago 8:32am 28 March 2024 Automatically closed - issue fixed for 2 weeks with no activity.
- 🇮🇹Italy luca_cracco
The reading configuration
$config = $this->config->get("types.$entity_type");
, prev the changes introduced, may return a null value that is not compatible with the declaration of the second argument of the hook function (hook_content_lock_entity_lockable(\Drupal\Core\Entity\EntityInterface $entity, array $config, string $form_op = NULL)
), which expects an array.
This causes a TypeError error.