getRawParameter example


  public function addBundleTitle(RouteMatchInterface $route_match$entity_type_id$bundle_parameter) {
    $bundles = $this->entityTypeBundleInfo->getBundleInfo($entity_type_id);
    // If the entity has bundle entities, the parameter might have been upcasted     // so fetch the raw parameter.     $bundle = $route_match->getRawParameter($bundle_parameter);
    if ((count($bundles) > 1) && isset($bundles[$bundle])) {
      return $this->t('Add @bundle', ['@bundle' => $bundles[$bundle]['label']]);
    }
    // If the entity supports bundles generally, but only has a single bundle,     // the bundle is probably something like 'Default' so that it preferable to     // use the entity type label.     else {
      return $this->addTitle($entity_type_id);
    }
  }

  

  protected $entity;

  /** * {@inheritdoc} */
  public function getEntityFromRouteMatch(RouteMatchInterface $route_match$entity_type_id) {
    // The URL of this entity form contains only the ID of the field_config     // but we are actually editing a field_storage_config entity.     $field_config = FieldConfig::load($route_match->getRawParameter('field_config'));
    if (!$field_config) {
      throw new NotFoundHttpException();
    }

    return $field_config->getFieldStorageDefinition();
  }

  /** * {@inheritdoc} * * @param array $form * A nested array form elements comprising the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. * @param string $field_config * The ID of the field config whose field storage config is being edited. */

  public function setEntity(EntityInterface $entity) {
    $this->entity = $entity;
    return $this;
  }

  /** * {@inheritdoc} */
  public function getEntityFromRouteMatch(RouteMatchInterface $route_match$entity_type_id) {
    if ($route_match->getRawParameter($entity_type_id) !== NULL) {
      $entity = $route_match->getParameter($entity_type_id);
    }
    else {
      $values = [];
      // If the entity has bundles, fetch it from the route match.       $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
      if ($bundle_key = $entity_type->getKey('bundle')) {
        if (($bundle_entity_type_id = $entity_type->getBundleEntityType()) && $route_match->getRawParameter($bundle_entity_type_id)) {
          $values[$bundle_key] = $route_match->getParameter($bundle_entity_type_id)->id();
        }
        elseif ($route_match->getRawParameter($bundle_key)) {
          
public function access(Route $route, RouteMatchInterface $route_match$bundle = NULL): AccessResultInterface {
    $permission = $route->getRequirement('_permission');
    if ($permission && !$this->currentUser()->hasPermission($permission)) {
      return AccessResult::neutral()->cachePerPermissions();
    }
    // Set $this->bundle for use by ::permissionsByProvider().     if ($bundle instanceof EntityInterface) {
      $this->bundle = $bundle;
    }
    else {
      $bundle_entity_type = $route->getDefault('bundle_entity_type');
      $bundle_name = is_string($bundle) ? $bundle : $route_match->getRawParameter($bundle_entity_type);
      $this->bundle = $this->entityTypeManager
        ->getStorage($bundle_entity_type)
        ->load($bundle_name);
    }

    if (empty($this->bundle)) {
      // A typo in the request path can lead to this case.       return AccessResult::forbidden();
    }

    return AccessResult::allowedIf((bool) $this->permissionsByProvider());
  }

  public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account, string $bundle = NULL): AccessResultInterface {
    $access = AccessResult::neutral();
    if ($entity_type_id = $route->getDefault('entity_type_id')) {
      if (empty($bundle)) {
        $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
        $bundle = $route_match->getRawParameter($entity_type->getBundleEntityType());
      }

      $field_types = $this->fieldTypePluginManager->getDefinitions();
      // Allows access if there are any existing fields and the user       // correct permissions.       foreach ($this->entityFieldManager->getFieldStorageDefinitions($entity_type_id) as $field_storage) {
        // Do not include fields with         // - non-configurable field storages,         // - locked field storages,         // - field storages that should not be added via user interface,         // - field storages that already have a field in the bundle.

  public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account$form_mode_name = 'default', $bundle = NULL) {
    $access = AccessResult::neutral();
    if ($entity_type_id = $route->getDefault('entity_type_id')) {
      if (empty($bundle)) {
        $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
        $bundle = $route_match->getRawParameter($entity_type->getBundleEntityType());
      }

      $visibility = FALSE;
      if ($form_mode_name == 'default') {
        $visibility = TRUE;
      }
      elseif ($entity_display = $this->entityTypeManager->getStorage('entity_form_display')->load($entity_type_id . '.' . $bundle . '.' . $form_mode_name)) {
        $visibility = $entity_display->status();
      }

      if ($form_mode_name != 'default' && $entity_display) {
        
$route = $route_match->getRouteObject();
    $map = $route->hasOption('_view_argument_map') ? $route->getOption('_view_argument_map') : [];

    foreach ($map as $attribute => $parameter_name) {
      // Allow parameters be pulled from the request.       // The map stores the actual name of the parameter in the request. Views       // which override existing controller, use for example 'node' instead of       // arg_nid as name.       if (isset($map[$attribute])) {
        $attribute = $map[$attribute];
      }
      if ($arg = $route_match->getRawParameter($attribute)) {
      }
      else {
        $arg = $route_match->getParameter($attribute);
      }

      if (isset($arg)) {
        $args[] = $arg;
      }
    }

    $class = $route->getOption('_view_display_plugin_class');
    

  public function testRouteMatchFromRequest() {
    $request = new Request();

    // A request that hasn't been routed yet.     $route_match = RouteMatch::createFromRequest($request);
    $this->assertNull($route_match->getRouteName());
    $this->assertNull($route_match->getRouteObject());
    $this->assertSame([]$route_match->getParameters()->all());
    $this->assertNull($route_match->getParameter('foo'));
    $this->assertSame([]$route_match->getRawParameters()->all());
    $this->assertNull($route_match->getRawParameter('foo'));

    // A routed request without parameter upcasting.     $route = new Route('/test-route/{foo}');
    $request->attributes->set(RouteObjectInterface::ROUTE_NAME, 'test_route');
    $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, $route);
    $request->attributes->set('foo', '1');
    $route_match = RouteMatch::createFromRequest($request);
    $this->assertSame('test_route', $route_match->getRouteName());
    $this->assertSame($route$route_match->getRouteObject());
    $this->assertSame(['foo' => '1']$route_match->getParameters()->all());
    $this->assertSame([]$route_match->getRawParameters()->all());

    
public function testGetParameters(RouteMatchInterface $route_match, Route $route$parameters$expected_filtered_parameters) {
    $this->assertSame($expected_filtered_parameters$route_match->getParameters()->all());
  }

  /** * @covers ::getRawParameter * @covers \Drupal\Core\Routing\RouteMatch::getParameterNames * @dataProvider routeMatchProvider */
  public function testGetRawParameter(RouteMatchInterface $route_match, Route $route$parameters$expected_filtered_parameters) {
    foreach ($expected_filtered_parameters as $name => $expected_value) {
      $this->assertSame($expected_value$route_match->getRawParameter($name));
    }
    foreach (array_diff_key($parameters$expected_filtered_parameters) as $name) {
      $this->assertNull($route_match->getRawParameter($name));
    }
  }

  /** * @covers ::getRawParameters * @covers \Drupal\Core\Routing\RouteMatch::getParameterNames * @dataProvider routeMatchProvider */
  

  public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account$view_mode_name = 'default', $bundle = NULL) {
    $access = AccessResult::neutral();
    if ($entity_type_id = $route->getDefault('entity_type_id')) {
      if (empty($bundle)) {
        $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
        $bundle = $route_match->getRawParameter($entity_type->getBundleEntityType());
      }

      $visibility = FALSE;
      if ($view_mode_name == 'default') {
        $visibility = TRUE;
      }
      elseif ($entity_display = $this->entityTypeManager->getStorage('entity_view_display')->load($entity_type_id . '.' . $bundle . '.' . $view_mode_name)) {
        $visibility = $entity_display->status();
      }

      if ($view_mode_name != 'default' && $entity_display) {
        
/** * {@inheritdoc} */
  public function getParameters() {
    return $this->getCurrentRouteMatch()->getParameters();
  }

  /** * {@inheritdoc} */
  public function getRawParameter($parameter_name) {
    return $this->getCurrentRouteMatch()->getRawParameter($parameter_name);
  }

  /** * {@inheritdoc} */
  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. */
Home | Imprint | This part of the site doesn't use cookies.