function ConfirmFormHelper::buildCancelLink

Same name in other branches
  1. 9 core/lib/Drupal/Core/Form/ConfirmFormHelper.php \Drupal\Core\Form\ConfirmFormHelper::buildCancelLink()
  2. 10 core/lib/Drupal/Core/Form/ConfirmFormHelper.php \Drupal\Core\Form\ConfirmFormHelper::buildCancelLink()
  3. 11.x core/lib/Drupal/Core/Form/ConfirmFormHelper.php \Drupal\Core\Form\ConfirmFormHelper::buildCancelLink()

Builds the cancel link for a confirmation form.

Parameters

\Drupal\Core\Form\ConfirmFormInterface $form: The confirmation form.

\Symfony\Component\HttpFoundation\Request $request: The current request.

Return value

array The link render array for the cancel form.

8 calls to ConfirmFormHelper::buildCancelLink()
ConfirmFormBase::buildForm in core/lib/Drupal/Core/Form/ConfirmFormBase.php
Form constructor.
ConfirmFormHelperTest::testCancelLinkDestination in core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php
@covers ::buildCancelLink
ConfirmFormHelperTest::testCancelLinkRoute in core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php
@covers ::buildCancelLink
ConfirmFormHelperTest::testCancelLinkRouteWithParams in core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php
@covers ::buildCancelLink
ConfirmFormHelperTest::testCancelLinkRouteWithUrl in core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php
@covers ::buildCancelLink

... See full list

File

core/lib/Drupal/Core/Form/ConfirmFormHelper.php, line 25

Class

ConfirmFormHelper
Provides common functionality to confirmation forms.

Namespace

Drupal\Core\Form

Code

public static function buildCancelLink(ConfirmFormInterface $form, Request $request) {
    // Prepare cancel link.
    $query = $request->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',
            ],
        ],
        '#url' => $url,
        '#cache' => [
            'contexts' => [
                'url.query_args:destination',
            ],
        ],
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.