Verified Commit 79a07a4e authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2901412 by claudiu.cristea, pfrenssen, grathbone, ravi.shankar,...

Issue #2901412 by claudiu.cristea, pfrenssen, grathbone, ravi.shankar, saidatom, Lendude, quietone: Add current route parameters to the confirmation form route
parent 64e5e002
Loading
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
use Drupal\comment\Plugin\views\field\CommentBulkForm;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Routing\ResettableStackedRouteMatchInterface;
use Drupal\Tests\UnitTestCase;

/**
@@ -60,6 +61,8 @@ public function testConstructor() {

    $messenger = $this->createMock('Drupal\Core\Messenger\MessengerInterface');

    $route_match = $this->createMock(ResettableStackedRouteMatchInterface::class);

    $views_data = $this->getMockBuilder('Drupal\views\ViewsData')
      ->disableOriginalConstructor()
      ->getMock();
@@ -90,7 +93,7 @@ public function testConstructor() {
    $definition['title'] = '';
    $options = [];

    $comment_bulk_form = new CommentBulkForm([], 'comment_bulk_form', $definition, $entity_type_manager, $language_manager, $messenger, $entity_repository);
    $comment_bulk_form = new CommentBulkForm([], 'comment_bulk_form', $definition, $entity_type_manager, $language_manager, $messenger, $entity_repository, $route_match);
    $comment_bulk_form->init($executable, $display, $options);

    $reflected_actions = (new \ReflectionObject($comment_bulk_form))->getProperty('actions');
+4 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Routing\ResettableStackedRouteMatchInterface;
use Drupal\node\Plugin\views\field\NodeBulkForm;
use Drupal\Tests\UnitTestCase;

@@ -60,6 +61,8 @@ public function testConstructor() {

    $messenger = $this->createMock('Drupal\Core\Messenger\MessengerInterface');

    $route_match = $this->createMock(ResettableStackedRouteMatchInterface::class);

    $views_data = $this->getMockBuilder('Drupal\views\ViewsData')
      ->disableOriginalConstructor()
      ->getMock();
@@ -90,7 +93,7 @@ public function testConstructor() {
    $definition['title'] = '';
    $options = [];

    $node_bulk_form = new NodeBulkForm([], 'node_bulk_form', $definition, $entity_type_manager, $language_manager, $messenger, $entity_repository);
    $node_bulk_form = new NodeBulkForm([], 'node_bulk_form', $definition, $entity_type_manager, $language_manager, $messenger, $entity_repository, $route_match);
    $node_bulk_form->init($executable, $display, $options);

    $reflected_actions = (new \ReflectionObject($node_bulk_form))->getProperty('actions');
+4 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Routing\ResettableStackedRouteMatchInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\user\Plugin\views\field\UserBulkForm;

@@ -60,6 +61,8 @@ public function testConstructor() {

    $messenger = $this->createMock('Drupal\Core\Messenger\MessengerInterface');

    $route_match = $this->createMock(ResettableStackedRouteMatchInterface::class);

    $views_data = $this->getMockBuilder('Drupal\views\ViewsData')
      ->disableOriginalConstructor()
      ->getMock();
@@ -90,7 +93,7 @@ public function testConstructor() {
    $definition['title'] = '';
    $options = [];

    $user_bulk_form = new UserBulkForm([], 'user_bulk_form', $definition, $entity_type_manager, $language_manager, $messenger, $entity_repository);
    $user_bulk_form = new UserBulkForm([], 'user_bulk_form', $definition, $entity_type_manager, $language_manager, $messenger, $entity_repository, $route_match);
    $user_bulk_form->init($executable, $display, $options);

    $reflected_actions = (new \ReflectionObject($user_bulk_form))->getProperty('actions');
+21 −3
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Routing\RedirectDestinationTrait;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Routing\ResettableStackedRouteMatchInterface;
use Drupal\Core\TypedData\TranslatableInterface;
use Drupal\views\Entity\Render\EntityTranslationRenderTrait;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
@@ -73,6 +74,13 @@ class BulkForm extends FieldPluginBase implements CacheableDependencyInterface {
   */
  protected $messenger;

  /**
   * The current route match service.
   *
   * @var \Drupal\Core\Routing\ResettableStackedRouteMatchInterface
   */
  protected ResettableStackedRouteMatchInterface $routeMatch;

  /**
   * Constructs a new BulkForm object.
   *
@@ -90,10 +98,13 @@ class BulkForm extends FieldPluginBase implements CacheableDependencyInterface {
   *   The messenger.
   * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
   *   The entity repository.
   * @param \Drupal\Core\Routing\ResettableStackedRouteMatchInterface $route_match
   *   The current route match service.
   *
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, LanguageManagerInterface $language_manager, MessengerInterface $messenger, EntityRepositoryInterface $entity_repository) {
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, LanguageManagerInterface $language_manager, MessengerInterface $messenger, EntityRepositoryInterface $entity_repository, ResettableStackedRouteMatchInterface $route_match = NULL) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);

    $this->entityTypeManager = $entity_type_manager;
@@ -101,6 +112,11 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
    $this->languageManager = $language_manager;
    $this->messenger = $messenger;
    $this->entityRepository = $entity_repository;
    if (!$route_match) {
      @trigger_error('Calling BulkForm::__construct() without the $route_match argument is deprecated in drupal:10.3.0 and the $route_match argument will be required in drupal:11.0.0. See https://www.drupal.org/node/3115868', E_USER_DEPRECATED);
      $route_match = \Drupal::routeMatch();
    }
    $this->routeMatch = $route_match;
  }

  /**
@@ -114,7 +130,8 @@ public static function create(ContainerInterface $container, array $configuratio
      $container->get('entity_type.manager'),
      $container->get('language_manager'),
      $container->get('messenger'),
      $container->get('entity.repository')
      $container->get('entity.repository'),
      $container->get('current_route_match')
    );
  }

@@ -428,7 +445,8 @@ public function viewsFormSubmit(&$form, FormStateInterface $form_state) {
        $options = [
          'query' => $this->getDestinationArray(),
        ];
        $form_state->setRedirect($operation_definition['confirm_form_route_name'], [], $options);
        $route_parameters = $this->routeMatch->getRawParameters()->all();
        $form_state->setRedirect($operation_definition['confirm_form_route_name'], $route_parameters, $options);
      }
      else {
        // Don't display the message unless there are some elements affected and
+10 −0
Original line number Diff line number Diff line
action_bulk_test.action.confirm:
  path: '/node/{node}/confirm'
  defaults:
    _form: Drupal\action_bulk_test\Form\TestActionConfirmForm
  requirements:
    _access: 'TRUE'
  options:
    parameters:
      node:
        type: entity:node
Loading