- πΊπΈ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; }
- π©πͺ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 3:36pm 23 May 2023 - π³π±Netherlands Tr4nzNRG
Would be nice if it also takes workflow states in account (draft, archived)?
- last update
over 1 year ago 67 pass, 11 fail - 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 7:25pm 25 August 2023 - πΊπΈ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 8:02pm 25 August 2023 - last update
over 1 year ago 83 pass - 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
-
mark_fullmer β
committed d7ad5b0b on 6.0.x
Issue #3094710 by mark_fullmer, klidifia, Anybody: Distinguish...
-
mark_fullmer β
committed d7ad5b0b on 6.0.x
-
mark_fullmer β
committed bb462007 on 6.1.x
Issue #3094710 by mark_fullmer, klidifia, Anybody: Distinguish...
-
mark_fullmer β
committed bb462007 on 6.1.x
- Status changed to Fixed
about 1 year ago 4:54pm 29 September 2023 Automatically closed - issue fixed for 2 weeks with no activity.