I have a form where a user can either choose a gallery field to populate or a video field to populate but they have to choose one of the other -- there can't be a video and gallery on a page.
The logical way to do this is make three seperate content types, an article, a video and a gallery. However, since they all function about the same and an article could be about a video or a slideshow. Nevertheless, there isn't a case where a slideshow and video should be together. If they user wants video and images they can embed images through wysiwyg.
Using the #state mechanism, I have a select radios field that has the option of none, video, or image / gallery. This is set to hidden in the content display interface. If they choose image then the file field widget shows and if they choose video then the youtube field shows (once again I could use Media but that is huge and overkill for this application.)
The interface is quite sweet.
.
However, there is a problem because here a slideshow gallery has been created before the user decided to use a youtube video embedded.
What is the best practice for hiding the image gallery if the Youtube setting has been choosen? Do I make the media setting visible and then hide it and the image gallery? This doesn't make good sense because it is processed and therefore ineffient doing extra work. I don't want to force the form field to be deleted because then the work is lost. It just shouldn't be processed rather than have work deleted in the case the user would like to revert from one to the other. Any ideas?
EDIT:
I tried this code which works but I don't know if it's the best practice.
function helper_preprocess_node (&$variables) {
switch ($variables['type']){
case 'article':
if (isset($variables['field_article_media'][0]['value'])){
if ($variables['field_article_media'][0]['value'] == 'gallery'){
unset($variables['content']['field_youtube']);
}
if ($variables['field_article_media'][0]['value'] == 'video'){
unset($variables['content']['field_image']);
}
unset($variables['content']['field_article_media']);
}
break;
default:
break;
}
}