Since the same think is done for LINK and EMBED, this could be handled with a unique condition:

    if ( $relation->type & ( Relation::LINK | Relation::EMBED ) )