Comments

Casper09 created an issue. See original summary.

casper09’s picture

StatusFileSize
new1.71 KB
casper09’s picture

Status: Needs work » Needs review
berdir’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
  1. +++ b/sources/content/src/ContentEntitySourcePluginUi.php
    @@ -78,6 +78,15 @@ class ContentEntitySourcePluginUi extends SourcePluginUiBase {
    +
    +      $form['search_wrapper']['search']['publish_status'] = array(
    +          '#type' => 'select',
    

    This isn't just about nodes, its' used for any entity type, so we need to make sure that has a 'published' entity key.

    Also, indendation is wrong here, should be two spaces less.

  2. +++ b/sources/content/src/ContentEntitySourcePluginUi.php
    @@ -78,6 +78,15 @@ class ContentEntitySourcePluginUi extends SourcePluginUiBase {
    +          '#empty_option' => t('- Any -'),
    +          '#default_value' => isset($_GET['publish_status']) ? $_GET['publish_status'] : NULL,
    +          '#options' => [1 => 'Published', 0 => 'Unpublished'],
    

    the options need to use $this->t() so they can be translated.

  3. +++ b/sources/content/src/ContentEntitySourcePluginUi.php
    @@ -390,6 +399,15 @@ class ContentEntitySourcePluginUi extends SourcePluginUiBase {
     
    +      // New sort option for published status of content.
    ...
    +      }
    +
    +      if (isset($_GET['publish_status']) && $_GET['publish_status'] == '0') {
    +          $query->condition('status', 0);
    +      }
    

    maybe do something like

    if (isset(..)) {
    $query->condition('status', $_GET['publish_status']);
    }

    Also here, make sure that indentation is correct, like the lines around.

Also, this will require test.

casper09’s picture

Status: Needs work » Needs review
StatusFileSize
new1.69 KB

1) indentation - fixed
2) added $this->t() for options
3) indentation - fixed, not using your suggestion, because we must get all values without filter publish

javjaff’s picture

Hi guys.
Greate jobs. Your patch is what I needed ;)

Today I tested your patch on an existing site and on fresh Drupal 8 installation (test site), both with TMGMT 8.12.

1. Test site with fresh installation.
I have few nodes on test site and I unpublished some of them.

  • When I filter by published only, all nodes are displayed - failure.
  • When

I filter by unpublished, then unpublished nodes are displayed only - ok.

I have two content types: Page with revisions and Article without revisions - I assumed that maybe revisions were the problems.

2. Working online website.
I have revisions for nodes on that website.

  • When I filter by published only, published nodes are displayed only - ok.
  • When I filt

er by unpublished, some published nodes are displayed - failure.

javjaff’s picture

StatusFileSize
new3.52 KB

Hi. As I wrote, I had some problems with filtering content by publish status from the patch #5.
In my case, the problems were related with revisions unfortunately.

Except that publish filter didn't work properly in my case (described above), by the revisions there were some other issues with range/limit of the entities on the list (only few displayed per page; results page with pager) - I had that problem without publish status filter also.

I made few changes and created a new patch (for module version 8.x-1.12), please make a review.

javjaff’s picture

StatusFileSize
new3.83 KB

Sorry, my mistake. There's something wrong in my patch 7 (failed to apply).
I generated patch once again.

Status: Needs review » Needs work

The last submitted patch, 8: filter-publish-status-3093849-8.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

gebiss’s picture

Yep, the no 5 patch worked exactly as javjaff said. It wouldn't filter correctly.

I tested patch no 8 on TMGMT 8.x-1.14 on Drupal 9.4.5 and it worked for me. The content is filtered correctly on Published and Unpublished filter.

Thanks javjaff

dishabhadra’s picture

I tested patch #8 on Drupal 10.1.8 and it applied successfully.

For node and taxonomy terms there is a status field so it is filtered correctly on the published and unpublished filters.

But for Menu Link content or for other entities that don't have a status field they get the error.

Status error

So I fixed that issue by checking if the field definition has a status field then showing the status filter.

For Menu added the Enabled/Disabled filter.

dishabhadra’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 11: filter-publish-status-3093849-11.patch, failed testing. View results

mkalkbrenner’s picture

The patch should use EntityPublishedInterface nowadays