Enabling aggregation breaks views with "Moderation state" fields

Created on 11 May 2020, almost 5 years ago
Updated 23 December 2022, over 2 years ago

Problem

Steps to reproduce

  1. Enable content_moderation
  2. Assign a workflow to a node bundle
  3. Create a new node view and add a "Moderation state" field
  4. Enable aggregation and execute the view

Result:

Drupal\Core\Entity\Sql\SqlContentEntityStorageException: Column information not available for the 'moderation_state' field. in Drupal\Core\Entity\Sql\DefaultTableMapping->getFieldColumnName() (line 430 of core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php).

Proposed resolution

As a workaround the deprecated moderation state relationship can still be used with a view that has aggregation enabled.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
Content moderationΒ  β†’

Last updated 3 days ago

  • Maintained by
  • πŸ‡¦πŸ‡ΊAustralia @Sam152
Created by

πŸ‡ͺπŸ‡ΈSpain grota

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • last update over 1 year ago
    29,479 pass
  • Status changed to Needs review over 1 year ago
  • last update over 1 year ago
    Custom Commands Failed
  • πŸ‡ΊπŸ‡ΈUnited States jdleonard Austin, TX, USA

    #17 applied to 10.1.3 and allowed my view with aggregation to work with a Moderation State field.

    Setting to Needs Review as there are no steps to reproduce the error described in #18 and this is working for me.

  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Issue summary update and tests will still be needed.

  • last update over 1 year ago
    30,438 pass
  • πŸ‡¨πŸ‡ΏCzech Republic David Urban

    I have just tested with 10.2.2 and the #17 patch seems to be working.

  • πŸ‡ΊπŸ‡ΈUnited States tyler.hastain Utah

    Added patch 17 for Drupal 10.2.4. It only fixes the issue if the aggregation setting for the moderation state is set to aggregate on the Entity ID instead of the Value. (See attached screenshot for more information.)

  • πŸ‡ΊπŸ‡ΈUnited States maskedjellybean Portland, OR

    Thank you for this. #17 worked for me in Drupal 10.2.3.

  • #17 partially worked for me in Drupal 10.3.0 and 10.2.3
    I use an aggregartion on content moderation states field with the count aggrator in combination with the chart module.

    I've solved my issue with tha hook_views_query_alter

    function hook_views_query_alter(ViewExecutable $view,  $query):void
    {
        //Fix bug for views on content moderation
    	if(!empty($query->fields)){
    		foreach($query->fields as $kf=>$field){
    			if(isset($field['function'])){
    				if($field['field']=='moderation_state'){
    					$query->fields[$kf]['table']= 'content_moderation_state';
    				}
    			}
    		}
    	}
    }
    
  • πŸ‡ΊπŸ‡¦Ukraine myLies

    #17 works for me with Drupal 10.2.6 (simple aggregation case by value column)
    Thank you @anchal_gupta

  • πŸ‡ΊπŸ‡¦Ukraine myLies

    UPD: The patch from #17 do not correctly evaluate the sort operation - simply, the ORDER BY wasn't been added
    I have update a bit a patch from #17 to make sort works (see the interdiff)
    This way it works for me with D10.2

Production build 0.71.5 2024