Distinguish autocomplete results with "Unpublished" state

Created on 15 November 2019, about 5 years ago
Updated 29 September 2023, about 1 year ago

In the Drupal 7 version of Linkit, if selecting the option to show unpublished entities, it was possible to easily denote which was unpublished when searching based on the`.result.unpublished-node` class and the highlighted style attributed to it.

Linkit should support a method to distinguish nodes with "Published" and "Unpublished" status.

✨ Feature request
Status

Fixed

Version

6.1

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom williamsowen

Live updates comments and jobs are added and updated live.
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.

  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    A more customizable alternative, and one that is more accessible since it doesn't indicate state purely by color, would be to use Linkit's configurable metadata information to indicate the node status ("Published/Not published") in the results.

    The one roadblock to this is that Drupal core does not (yet) provide a token for node status. See ✨ Add a token for publication status Fixed .

    Once that lands, this can be done easily in Linkit.

    In the meantime, folks can implement the publication status token in custom code:

    /**
     * Implements hook_token_info().
     */
    function mymodule_token_info() {
      $type = [
        'name' => t('Nodes'),
        'description' => t('Tokens related to individual content items, or "nodes".'),
        'needs-data' => 'node',
      ];
      $node['mymodule_publication_state'] = [
        'name' => t("Publication state"),
        'type' => 'node',
      ];
      return [
        'types' => ['node' => $type],
        'tokens' => ['node' => $node],
      ];
    }
    
    /**
     * Implements hook_tokens().
     */
    function mymodule_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
      $replacements = [];
      if ($type == 'node' && !empty($data['node'])) {
        /** @var \Drupal\node\NodeInterface $node */
        $node = $data['node'];
        foreach ($tokens as $name => $original) {
          switch ($name) {
            case 'mymodule_publication_state':
              $replacements[$original] = $node->isPublished() ? 'Published' : 'Not published';
              break;
          }
        }
      }
      return $replacements;
    }
    
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    I really like the result in #2 and I think the correct approach would be to add a class for the published state on each result. By default an unpublished state should then have a light red background as in #2 from the module's CSS.

  • Assigned to mark_fullmer
  • Status changed to Needs review over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    Assigning myself for review...

  • πŸ‡³πŸ‡±Netherlands Tr4nzNRG

    Would be nice if it also takes workflow states in account (draft, archived)?

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.0.7 + Environment: PHP 8.1 & MariaDB 10.3.22
    last update over 1 year ago
    67 pass, 11 fail
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update over 1 year ago
    67 pass, 11 fail
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    The patch from #3 added logic for the field widget display, but not for the CKEditor plugin. The attached patch adds logic for the latter, and slightly changes the implementation:

    Before:

    +     var $wrapper = $('<div>').addClass('linkit-result-line-wrapper ' + item.status);
    

    After:

    +     var $wrapper = $('<div>').addClass('linkit-result-line-wrapper');
    +    $wrapper.addClass(item.status);
    

    Before:

    +     return $entity->status->getString() ? 'published' : 'unpublished';
    

    After:

    +         return $entity->isPublished() ? 'published' : 'unpublished';
    
  • The last submitted patch, 10: 3094710-entity-status-10.6.0.x.patch, failed testing. View results β†’
    - codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

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

    Looks like the test failures are valid, since they're looking for a specific CSS string:

    Drupal\Tests\linkit\FunctionalJavascript\LinkFieldTest::testLinkFieldWidgetAndFormatter
    Behat\Mink\Exception\ElementNotFoundException: Element matching css "ul.linkit-ui-autocomplete li.linkit-result-line span.linkit-result-line--title" not found

  • Status changed to Needs review over 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.0.7 + Environment: PHP 8.1 & MariaDB 10.3.22
    last update over 1 year ago
    83 pass
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update over 1 year ago
    83 pass
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    Okay, not all entity types have a "status" value, so we need to add a conditional!

        if ($entity->getEntityType()->hasKey('status')) {
          $entity = \Drupal::entityTypeManager()->getStorage($entity_type)->load($entity->id());
          return $entity->isPublished() ? 'published' : 'unpublished';
        }
    
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    Would be nice if it also takes workflow states in account (draft, archived)?

    I think this would need to be handled by way of configuring matcher metadata, similar to what is described in https://www.drupal.org/project/linkit/issues/3094710#comment-14984839 ✨ Distinguish autocomplete results with "Unpublished" state Fixed

  • Status changed to Fixed about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024