class ConfirmFormHelper in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Form/ConfirmFormHelper.php \Drupal\Core\Form\ConfirmFormHelper
Provides common functionality to confirmation forms.
Hierarchy
- class \Drupal\Core\Form\ConfirmFormHelper
Expanded class hierarchy of ConfirmFormHelper
3 files declare their use of ConfirmFormHelper
- ConfirmFormHelperTest.php in core/
tests/ Drupal/ Tests/ Core/ Form/ ConfirmFormHelperTest.php - Contains \Drupal\Tests\Core\Form\ConfirmFormHelperTest.
- ContentEntityConfirmFormBase.php in core/
lib/ Drupal/ Core/ Entity/ ContentEntityConfirmFormBase.php - Contains \Drupal\Core\Entity\ContentEntityConfirmFormBase.
- EntityConfirmFormBase.php in core/
lib/ Drupal/ Core/ Entity/ EntityConfirmFormBase.php - Contains \Drupal\Core\Entity\EntityConfirmFormBase.
File
- core/
lib/ Drupal/ Core/ Form/ ConfirmFormHelper.php, line 17 - Contains \Drupal\Core\Form\ConfirmFormHelper.
Namespace
Drupal\Core\FormView source
class ConfirmFormHelper {
/**
* Builds the cancel link for a confirmation form.
*
* @param \Drupal\Core\Form\ConfirmFormInterface $form
* The confirmation form.
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request.
*
* @return array
* The link render array for the cancel form.
*/
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',
],
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfirmFormHelper:: |
public static | function | Builds the cancel link for a confirmation form. |