query; $url = NULL; // If a destination is specified, that serves as the cancel link. if ($query->has('destination')) { $options = UrlHelper::parse($query->get('destination')); // @todo Revisit this in https://www.drupal.org/node/2418219. try { $url = Url::fromUserInput('/' . ltrim($options['path'], '/'), $options); } catch (\InvalidArgumentException $e) { // Suppress the exception and fall back to the form's cancel URL. } } // Check for a route-based cancel link. if (!$url) { $url = $form->getCancelUrl(); } return [ '#type' => 'link', '#title' => $form->getCancelText(), '#attributes' => ['class' => ['button', 'dialog-cancel']], '#url' => $url, '#cache' => [ 'contexts' => [ 'url.query_args:destination', ], ], ]; } }