Spanish police have arrested a Moroccan man in Barcelona with suspected links to Islamic State who they believe was planning a militant attack.