- Issue created by @cedricl
- š¦šŗAustralia almunnings Melbourne, š¦šŗ
š
Could be tricky. Could be easy. Iām keen. Will have a look this weekend.
- š¦šŗAustralia almunnings Melbourne, š¦šŗ
Users without access to view unpublished data wouldn't see the unpublished items, but your request is specifically asking for unpublished items to always be hidden from entity reference fields.
My gut feel is this should stay as permissions, and Drupal already has a way for you to achieve this.
But perhaps a hook could do what you need?
use Drupal\Core\Cache\RefinableCacheableDependencyInterface; use Drupal\Core\Entity\EntityPublishedInterface; use Drupal\Core\Field\FieldItemListInterface; /** * Implements hook_graphql_compose_field_results_alter(). */ function MYMODULE_graphql_compose_field_results_alter(array &$results, array $context, RefinableCacheableDependencyInterface $metadata) { $field_list = $context['value'] ?? NULL; if (!$field_list instanceof FieldItemListInterface) { return; } if ($field_list->getFieldDefinition()->getType() === 'entity_reference') { $results = array_filter( $results, fn ($entity) => ($entity instanceof EntityPublishedInterface) ? $entity->isPublished() : TRUE ); } }
- š¦šŗAustralia darvanen Sydney, Australia
Could this perhaps be repurposed as a feature request for filters on edge queries?
- š¦šŗAustralia almunnings Melbourne, š¦šŗ
Demand for this feature has recently skyrocketed 200%
I'll look into it more.
- Status changed to Needs review
about 1 year ago 11:11am 21 September 2023 - š¦šŗAustralia almunnings Melbourne, š¦šŗ
Ok, deployed to develop
https://git.drupalcode.org/project/graphql_compose/-/commit/bfec317fefee...
Its in there somewhere. Lots to unpack.
I've applied it to entity references and edges.Let me know how you go with your testing!
- š¦šŗAustralia darvanen Sydney, Australia
Tried to test, I:
- Pulled latest 2.0.x
- Cleared cache (on my contrib rig, no other modules installed except dependencies)
- Searched for new options in /admin/config/graphql_compose
- Checked the explorer
I can't see where/how to set a filter on the query, what am I missing?
- š¦šŗAustralia almunnings Melbourne, š¦šŗ
It should be under Advanced settings at admin/config/graphql_compose/settings
Exclude unpublished entities which will be on by default for new installs
- Status changed to RTBC
about 1 year ago 1:39am 25 September 2023 - š¦šŗAustralia darvanen Sydney, Australia
Ahah! The one place I didn't look.
Yes, this passes manual testing of a simple unpublished article. Very nice. I believe this meets the criteria of the IS as it stands.
- š§šŖBelgium cedricl
Does exactly what I wanted. Thanks for the help @almunnings
- Status changed to Fixed
about 1 year ago 9:56pm 6 November 2023