getRouteMatch example


  public function getBaseFormId() {
    return 'entity_delete_multiple_confirm_form';
  }

  /** * {@inheritdoc} */
  public function getFormId() {
    // Get entity type ID from the route because ::buildForm has not yet been     // called.     $entity_type_id = $this->getRouteMatch()->getParameter('entity_type_id');
    return $entity_type_id . '_delete_multiple_confirm_form';
  }

  /** * {@inheritdoc} */
  public function getQuestion() {
    return $this->formatPlural(count($this->selection), 'Are you sure you want to delete this @item?', 'Are you sure you want to delete these @items?', [
      '@item' => $this->entityType->getSingularLabel(),
      '@items' => $this->entityType->getPluralLabel(),
    ]);
  }
public function getRawParameters() {
    return $this->getCurrentRouteMatch()->getRawParameters();
  }

  /** * Returns the route match for the current request. * * @return \Drupal\Core\Routing\RouteMatchInterface * The current route match object. */
  public function getCurrentRouteMatch() {
    return $this->getRouteMatch($this->requestStack->getCurrentRequest());
  }

  /** * Returns the route match for a passed in request. * * @param \Symfony\Component\HttpFoundation\Request $request * A request object. * * @return \Drupal\Core\Routing\RouteMatchInterface * A route match object created from the request. */
  

    $form['actions']['submit'] = [
      // Prevent from showing up in \Drupal::request()->query.       '#name' => '',
      '#type' => 'submit',
      '#value' => $this->t('Apply'),
      '#id' => Html::getUniqueId('edit-submit-' . $view->storage->id()),
    ];

    if (!$view->hasUrl()) {
      // On any non views.ajax route, use the current route for the form action.       if ($this->getRouteMatch()->getRouteName() !== 'views.ajax') {
        $form_action = Url::fromRoute('<current>')->toString();
      }
      else {
        // On the views.ajax route, set the action to the page we were on.         $form_action = Url::fromUserInput($this->currentPathStack->getPath())->toString();
      }
    }
    else {
      $form_action = $view->getUrl()->toString();
    }

    
'default_without_leading_underscore' => 'value',
        ],
      ],
    ];

    $data = [];
    foreach ($base_data as $entry) {
      $route = $entry[0];
      $params = $entry[1];
      $expected_params = $entry[2];
      $data[] = [
        $this->getRouteMatch('test_route', $route$params$params),
        $route,
        $params,
        $expected_params,
      ];
    }

    return $data;
  }

  /** * @covers ::getRouteName * @dataProvider routeMatchProvider */
Home | Imprint | This part of the site doesn't use cookies.