Issue #104: Backport Drupal 8 dialog API.

PR for https://github.com/backdrop/backdrop-issues/issues/104

This combines patches from:
https://drupal.org/node/1667742
https://drupal.org/node/1870764

and some of
https://drupal.org/node/1851414