Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Content Moderation's form element assumes bundles are used for the entity page it's on. Make a custom entity with Drupal Console that doesn't support bundles, and try to create one.
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
/** @var ContentEntityInterface $entity */
$entity = $items->getEntity();
/* @var \Drupal\Core\Config\Entity\ConfigEntityInterface $bundle_entity */
$bundle_entity = $this->entityTypeManager->getStorage($entity->getEntityType()->getBundleEntityType())->load($entity->bundle()); //<--this line crashes everything
if (!$this->moderationInformation->isModeratedEntity($entity)) {
// @todo https://www.drupal.org/node/2779933 write a test for this.
return $element + ['#access' => FALSE];
}
Comment | File | Size | Author |
---|---|---|---|
#28 | 2868429-28.patch | 5.55 KB | timmillwood |
Comments
Comment #2
timmillwoodGood spot!
It's only recently we've started supporting non-bundle entity types, so we really need to increase the testing on this. One of the main outstanding things if you can't enable moderation on a non-bundle entity type, because the current UI is within the bundle settings. So interested to know how you're hitting this. However, this will change once #2843083: Select entity type / bundle in workflow settings gets in, which will allow you to enable moderation on non-bundle entity types.
Comment #3
timmillwoodHere's a patch for this.
Comment #5
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedSuper nit, missing newline between namespace and use, hopefully can be fixed on commit.
Otherwise +1 to more comprehensive testing for non-config bundles. Diff makes perfect sense, no need to get an instance of the bundle for an exception only.
Comment #6
Ada Hernandez CreditAttribution: Ada Hernandez at MTech, LLC commentedadding newline ---> #5
Comment #7
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedComment #8
RaisinBranCrunch CreditAttribution: RaisinBranCrunch commentedThanks, so glad I was able to be of use. Honestly, I'm not entirely sure how this came up. I didn't look as closely at it at first, but now it seems like this doesn't happen just for any entity. Our site has a custom entity with a field that references a content type that is Workflow'd by content moderation... could that be calling this?
The stack trace that led up to the error was from WidgetBase:
Comment #10
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedReroll and back to RTBC.
Comment #11
catchDo we want to keep the more specific error message when there's a bundle? Or at least add the entity type to the message?
Comment #12
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedThere is no situation when this exception will be triggered.
In the true part of the ternary, the workflow entity already throws an exception if the state doesn't exist, in the false part now that we have the required_states feature on the ContentModeration workflow type, there will always be something set.
So, this is actually totally safe to remove.
Comment #13
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedI also need this backported to 8.3. Attached.
Comment #14
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedComment #16
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedComment #17
timmillwoodGood solution to #11.
Queued an 8.3.x test for #13.
Comment #21
catchI like that much better. Committed/pushed to 8.4.x and cherry-picked to 8.3.x, thanks!
Neither the 8.4.x nor 8.3.x patches applied to me, but did a local re-roll prior to commit.
Comment #22
tacituseu CreditAttribution: tacituseu commentedSomething wen't wrong here with 8.3.x, see:
https://www.drupal.org/pift-ci-job/668343
https://www.drupal.org/pift-ci-job/668344
https://www.drupal.org/pift-ci-job/668345
https://www.drupal.org/pift-ci-job/668346
Comment #23
timmillwoodThat's strange because
entity_test_mulrevpub
exists in 8.3.x: http://cgit.drupalcode.org/drupal/tree/core/modules/system/tests/modules...Comment #24
tacituseu CreditAttribution: tacituseu commentedIt is intermittent, 30% failure rate judging byhttps://www.drupal.org/node/3060/qa.Edit: scratch that, all those "tested on commit" failed.
Comment #26
alexpottI've reverted this on 8.3.x
Comment #27
catchThis might be related to #2864008: Convert web tests to browser tests for content_moderation module, at least let's run it past DrupalCI now I've cherry-picked that commit.
Comment #28
timmillwoodHere's an 8.3.x backport.
Comment #29
alexpottLooks great. All the changes are the same as the patch for 8.4.x which I confirmed by applying and committing the changes locally and then checking out the 8.4.x version of the test.
Comment #31
catchCommitted/pushed to 8.3.x, thanks!