- Status changed to Fixed
about 1 year ago 7:10am 29 September 2023 Automatically closed - issue fixed for 2 weeks with no activity.
There is a notice displayed:
Notice: Undefined index: #attached in Drupal\content_moderation_info_block\Form\ContentModerationInfoBlockModerationForm->buildForm() (line 82 of /web/modules/contrib/content_moderation_info_block/src/Form/ContentModerationInfoBlockModerationForm.php)
This is caused by this line of code:
$key = array_search('content_moderation/content_moderation', $form['#attached']['library'], TRUE);
when the #attached
key is not available in the form array.
I have managed to track down the reason for that thing. The ContentModerationInfoBlockModerationForm
::buildForm calls the parent:buildForm which builds the EntityModerationForm
. The EntityModerationForm
checks the workflow for the entity and determines the available transitions for the entity. If it finds none it does an early exit:
EntityModerationForm line 98:
if (!count($target_states)) {
return $form;
}
and it does it BEFORE setting the #attached
libraries (it does it in line 131.
So the notice happens when there are no valid states for the current entity.
1. Enable the module
2. Enable the block
3. Visit the entity page with enabled moderation
4. Set the moderation state to some state that does not have any allowed transitions
Either check if there is a new_state
element defined in the form (its added by the parent form after the early exit) or simply do
if (!isset($form['#attached']['library'])) {
return $form;
}
$key = array_search('content_moderation/content_moderation', $form['#attached']['library'], TRUE);
Create a patch
Fixed
1.0
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
Automatically closed - issue fixed for 2 weeks with no activity.