We have a content type with a date range element on our D8 site. I got a request to hide the display of the end date if the content editor decided so.
From testing, the content editor can't delete the end date-- the field fails validation if an end date has already been specified. And anyways, they don't want to delete the end date-- they want to maintain that information-- they only want it not to display to the public audience, in certain circumstances.
I started to approach this by adding a second field to the content type, a boolean checkbox "Hide End Date". I wrote a
hook_preprocess_field in our .theme file in order to change the display of the date range value. But after debugging the variables, I realized that the date range field doesn't have any information about the value of the "hide end date" field, of course.
I'm not sure how best to proceed. Is
hook_preprocess_node the place where I can look at both field values, and alter the value of the date range field? Will that affect display of the field throughout the site, including views?