I've done this a couple ways.
First, you can you hook_ds_pre_render_alter (I can't find a better link to ds.api.php!) like hook_preprocess_node and just hide your title field if the image field is set. If you're using this option be sure to dig into the layout render array to the correct spot. For example if you have the ds node_title field within the ds_content region, hide it like
$layout_render_array['ds_content']['node_title']['#access'] = FALSE;
of if you have the same field within a title_wrapper field group, hide it like
$layout_render_array['ds_content']['group_title_wrapper']['node_title']['#access'] = FALSE;
Or you can create a custom ds field (yes, you have access to the whole entity). I usually enable the hidden
region at /admin/structure/ds/settings
, then I add both my title field and image field to the hidden region on my view mode and then just render whichever one I need in my ds field's build()
method via the field's view method, in this case it would be like
$this->entity()->field_MY_IMAGE_FIELD->view('teaser');
or
$this->entity()->title->view('teaser');
Instead of passing a view mode's name, you can pass a display configuration array straight to the field's view method.