buildCancelLink example


  public function testCancelLinkTitle() {
    $cancel_text = 'Cancel text';
    $form = $this->createMock('Drupal\Core\Form\ConfirmFormInterface');
    $form->expects($this->any())
      ->method('getCancelText')
      ->willReturn($cancel_text);

    $link = ConfirmFormHelper::buildCancelLink($formnew Request());
    $this->assertSame($cancel_text$link['#title']);
    $this->assertSame(['contexts' => ['url.query_args:destination']]$link['#cache']);
  }

  /** * @covers ::buildCancelLink * * Tests a cancel link route. */
  public function testCancelLinkRoute() {
    $route_name = 'foo_bar';
    

  protected function actions(array $form, FormStateInterface $form_state) {
    return [
      'submit' => [
        '#type' => 'submit',
        '#value' => $this->getConfirmText(),
        '#submit' => [
          [$this, 'submitForm'],
        ],
      ],
      'cancel' => ConfirmFormHelper::buildCancelLink($this$this->getRequest()),
    ];
  }

  /** * {@inheritdoc} * * The save() method is not used in EntityConfirmFormBase. This overrides the * default implementation that saves the entity. * * Confirmation forms should override submitForm() instead for their logic. */
  
$form['#attributes']['class'][] = 'confirmation';
    $form['description'] = ['#markup' => $this->getDescription()];
    $form[$this->getFormName()] = ['#type' => 'hidden', '#value' => 1];

    $form['actions'] = ['#type' => 'actions'];
    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this->getConfirmText(),
      '#button_type' => 'primary',
    ];

    $form['actions']['cancel'] = ConfirmFormHelper::buildCancelLink($this$this->getRequest());

    // By default, render the form using theme_confirm_form().     if (!isset($form['#theme'])) {
      $form['#theme'] = 'confirm_form';
    }
    return $form;
  }

}

  protected function actions(array $form, FormStateInterface $form_state) {
    return [
      'submit' => [
        '#type' => 'submit',
        '#value' => $this->getConfirmText(),
        '#submit' => [
          [$this, 'submitForm'],
        ],
      ],
      'cancel' => ConfirmFormHelper::buildCancelLink($this$this->getRequest()),
    ];
  }

  /** * {@inheritdoc} * * The save() method is not used in ContentEntityConfirmFormBase. This * overrides the default implementation that saves the entity. * * Confirmation forms should override submitForm() instead for their logic. */
  
Home | Imprint | This part of the site doesn't use cookies.