- πΊπΈUnited States loopy1492
We finally got to the bottom of this and it was a weird situation.
We are filling a select2 field on the fly with
$nodeStorage = $this->entityTypeManager->getStorage('node'); $nodeQuery = $nodeStorage->getQuery();
Then it's supposed to filter based on node type...
$custom_node_type_ids = $nodeQuery ->condition('type', 'custom_node_type') ->condition('status', 1) ->sort('created', 'DESC') ->accessCheck() ->execute();
But for some reason, when I debug the output from this function, it returns not only the custom_node_type nodes, but also the node of the current page. The current page is of the "page" content type, but that doesn't seem to matter to the nodeQuery.
I had to add the following:
$my_nodes_ids = $nodeQuery ->condition('type', 'my_nodes') ->condition('status', 1) ->sort('created', 'DESC') ->condition('nid', '4856', '!=') ->accessCheck() ->execute();
After that, my function that was filling the select2 field no longer had null values for the fields it was trying to reference.
I suspect this has always been a problem and Drupal just passed over the null value before, but now it's less forgiving of sloppy code.
At any rate, this is not a priblem with select2 at all.
- Status changed to Closed: works as designed
over 1 year ago 12:31pm 8 August 2023