CMS Development

TMerkel
Contributor

Link field > Publish status?

SOLVE

Hi everyone,

 

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.

 

Any quick and easy solution for it? 🙂

 

Thanks

0 Upvotes
1 Accepted solution
ModuleMaestro
Solution
Participant

Link field > Publish status?

SOLVE

Hi @TMerkel,

 

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.

 

Hope this helps!

View solution in original post

2 Replies 2
ModuleMaestro
Solution
Participant

Link field > Publish status?

SOLVE

Hi @TMerkel,

 

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.

 

Hope this helps!

TMerkel
Contributor

Link field > Publish status?

SOLVE

Thanks! That helps to hide pages from showing up in an unpublished status on the page itself.

Now i need to check, how to show a info message while editing pages 🙂