while using the link field in a custom module, I've just realized that it is possible for Editors to choose from all existing pages/blog posts without checking the publication status.
That results in 404 errors because people can choose unpublished pages, and pages that will be unpublished in the future won't be removed automatically.
As you've surfaced it seems the page module field allows selection of pages that aren't published. In terms of solutions for this I'm not seeing any options for us to pass validation in the field selection. I did however manage to retrieve a page's publish status through the use of the content_by_id module function here.
The HubL I used was as follows:
{% set page_id = module.page_field %}
{% set page_content = content_by_id(page_id) %}
{{ page_content.isPublished }} ->> will return false or true depending on whether it's published
And returned a value of false when the page wasn't published. I'm thinking you could use this as a way to surface up a warning in the editor screen (not the module editor sidebar) that the page is not published when someone selects an unpublished page. Past this, I think it would be a good feature request to allow some further validations to this particular field to avoid user error when selecting pages.
As you've surfaced it seems the page module field allows selection of pages that aren't published. In terms of solutions for this I'm not seeing any options for us to pass validation in the field selection. I did however manage to retrieve a page's publish status through the use of the content_by_id module function here.
The HubL I used was as follows:
{% set page_id = module.page_field %}
{% set page_content = content_by_id(page_id) %}
{{ page_content.isPublished }} ->> will return false or true depending on whether it's published
And returned a value of false when the page wasn't published. I'm thinking you could use this as a way to surface up a warning in the editor screen (not the module editor sidebar) that the page is not published when someone selects an unpublished page. Past this, I think it would be a good feature request to allow some further validations to this particular field to avoid user error when selecting pages.