NotFoundHttpException example


        if (!$attribute = $argument->getAttributesOfType(MapQueryParameter::class)[0] ?? null) {
            return [];
        }

        $name = $attribute->name ?? $argument->getName();
        if (!$request->query->has($name)) {
            if ($argument->isNullable() || $argument->hasDefaultValue()) {
                return [];
            }

            throw new NotFoundHttpException(sprintf('Missing query parameter "%s".', $name));
        }

        $value = $request->query->all()[$name];
        $type = $argument->getType();

        if (null === $attribute->filter && 'array' === $type) {
            if (!$argument->isVariadic()) {
                return [(array) $value];
            }

            $filtered = array_values(array_filter((array) $value, \is_array(...)));

            
/** * Gets the template name for a given panel. * * @throws NotFoundHttpException */
    public function getName(Profile $profile, string $panel): mixed
    {
        $templates = $this->getNames($profile);

        if (!isset($templates[$panel])) {
            throw new NotFoundHttpException(sprintf('Panel "%s" is not registered in profiler or is not present in viewed profile.', $panel));
        }

        return $templates[$panel];
    }

    /** * Gets template names of templates that are present in the viewed profile. * * @throws \UnexpectedValueException */
    public function getNames(Profile $profile): array
    {

  public function listing($mapper_id) {
    $mapper_definition = $this->mapperManager->getDefinition($mapper_id);
    $mapper = $this->mapperManager->createInstance($mapper_id$mapper_definition);
    if (!$mapper) {
      throw new NotFoundHttpException();
    }
    $entity_type = $mapper->getType();
    // If the mapper, for example the mapper for fields, has a custom list     // controller defined, use it. Other mappers, for examples the ones for     // node_type and block, fallback to the generic configuration translation     // list controller.     $build = $this->entityTypeManager()
      ->getHandler($entity_type, 'config_translation_list')
      ->setMapperDefinition($mapper_definition)
      ->render();
    $build['#title'] = $mapper->getTypeLabel();
    

        if (!$attribute = $argument->getAttributesOfType(MapQueryParameter::class)[0] ?? null) {
            return [];
        }

        $name = $attribute->name ?? $argument->getName();
        if (!$request->query->has($name)) {
            if ($argument->isNullable() || $argument->hasDefaultValue()) {
                return [];
            }

            throw new NotFoundHttpException(sprintf('Missing query parameter "%s".', $name));
        }

        $value = $request->query->all()[$name];

        if (null === $attribute->filter && 'array' === $argument->getType()) {
            if (!$argument->isVariadic()) {
                return [(array) $value];
            }

            $filtered = array_values(array_filter((array) $value, \is_array(...)));

            


  /** * {@inheritdoc} */
  public function buildForm(array $form, FormStateInterface $form_state, WorkflowInterface $workflow = NULL, $entity_type_id = NULL) {
    $this->workflow = $workflow;
    try {
      $this->entityType = $this->entityTypeManager->getDefinition($entity_type_id);
    }
    catch (PluginNotFoundException $e) {
      throw new NotFoundHttpException();
    }

    $options = $defaults = [];
    foreach ($this->bundleInfo->getBundleInfo($this->entityType->id()) as $bundle_id => $bundle) {
      // Check if moderation is enabled for this bundle on any workflow.       $moderation_enabled = $this->moderationInformation->shouldModerateEntitiesOfBundle($this->entityType, $bundle_id);
      // Check if moderation is enabled for this bundle on this workflow.       $workflow_moderation_enabled = $this->workflow->getTypePlugin()->appliesToEntityTypeAndBundle($this->entityType->id()$bundle_id);
      // Only show bundles that are not enabled anywhere, or enabled on this       // workflow.       if (!$moderation_enabled || $workflow_moderation_enabled) {
        
->getStorage('contact_form')
        ->load($config->get('default_form'));
      // If there are no forms, do not display the form.       if (empty($contact_form)) {
        if ($this->currentUser()->hasPermission('administer contact forms')) {
          $this->messenger()->addError($this->t('The contact form has not been configured. <a href=":add">Add one or more forms</a> .', [
            ':add' => Url::fromRoute('contact.form_add')->toString(),
          ]));
          return [];
        }
        else {
          throw new NotFoundHttpException();
        }
      }
    }

    $message = $this->entityTypeManager()
      ->getStorage('contact_message')
      ->create([
        'contact_form' => $contact_form->id(),
      ]);

    $form = $this->entityFormBuilder()->getForm($message);
    

  public function buildForm(array $form, FormStateInterface $form_state, WorkflowInterface $workflow = NULL, $workflow_state = NULL) {
    if (!$workflow->getTypePlugin()->hasState($workflow_state)) {
      throw new NotFoundHttpException();
    }
    $this->workflow = $workflow;
    $this->stateId = $workflow_state;

    if ($this->workflow->getTypePlugin()->workflowStateHasData($this->workflow, $this->workflow->getTypePlugin()->getState($this->stateId))) {
      $form['#title'] = $this->getQuestion();
      $form['description'] = ['#markup' => $this->t('This workflow state is in use. You cannot remove this workflow state until you have removed all content using it.')];
      return $form;
    }

    return parent::buildForm($form$form_state);
  }
$response = $this->httpKernel->handle($redirect_request, HttpKernelInterface::SUB_REQUEST);
      if ($response instanceof CacheableResponseInterface) {
        // @todo Once path aliases have cache tags (see         // https://www.drupal.org/node/2480077), add test coverage that         // the cache tag for a commented entity's path alias is added to the         // comment's permalink response, because there can be blocks or         // other content whose renderings depend on the subrequest's URL.         $response->addCacheableDependency($subrequest_url);
      }
      return $response;
    }
    throw new NotFoundHttpException();
  }

  /** * The _title_callback for the page that renders the comment permalink. * * @param \Drupal\comment\CommentInterface $comment * The current comment. * * @return string * The translated comment subject. */
  
$this->expressionLanguageProviders = $expressionLanguageProviders;
    }

    /** * Renders the profiler panel for the given token. * * @throws NotFoundHttpException */
    public function panelAction(string $token): Response
    {
        if (null === $this->profiler) {
            throw new NotFoundHttpException('The profiler must be enabled.');
        }

        $this->profiler->disable();

        if (null === $this->matcher || null === $this->routes) {
            return new Response('The Router is not enabled.', 200, ['Content-Type' => 'text/html']);
        }

        $profile = $this->profiler->loadProfile($token);

        /** @var RequestDataCollector $request */
        

  public function buildForm(array $form, FormStateInterface $form_state, RouteMatchInterface $route_match = NULL, $plugin_id = NULL, $langcode = NULL) {
    /** @var \Drupal\config_translation\ConfigMapperInterface $mapper */
    $mapper = $this->configMapperManager->createInstance($plugin_id);
    $mapper->populateFromRouteMatch($route_match);

    $language = $this->languageManager->getLanguage($langcode);
    if (!$language) {
      throw new NotFoundHttpException();
    }

    $this->mapper = $mapper;
    $this->language = $language;

    // ConfigTranslationFormAccess will not grant access if this raises an     // exception, so we can call this without a try-catch block here.     $langcode = $this->mapper->getLangcode();

    $this->sourceLanguage = $this->languageManager->getLanguage($langcode);

    

  public function filterXss(Request $request, FilterFormatInterface $filter_format) {
    $value = $request->request->get('value');
    if (!isset($value)) {
      throw new NotFoundHttpException();
    }

    // The original_format parameter will only exist when switching text format.     $original_format_id = $request->request->get('original_format_id');
    $original_format = NULL;
    if (isset($original_format_id)) {
      $original_format = $this->entityTypeManager()
        ->getStorage('filter_format')
        ->load($original_format_id);
    }

    
if (!\is_int($value) && !\is_string($value)) {
            throw new \LogicException(sprintf('Could not resolve the "%s $%s" controller argument: expecting an int or string, got "%s".', $argument->getType()$argument->getName()get_debug_type($value)));
        }

        /** @var class-string<\BackedEnum> $enumType */
        $enumType = $argument->getType();

        try {
            return [$enumType::from($value)];
        } catch (\ValueError $e) {
            throw new NotFoundHttpException(sprintf('Could not resolve the "%s $%s" controller argument: ', $argument->getType()$argument->getName()).$e->getMessage()$e);
        }
    }
}

  public function viewHelpTopic($id) {
    $build = [];

    if (!$this->helpTopicPluginManager->hasDefinition($id)) {
      throw new NotFoundHttpException();
    }
    /** @var \Drupal\help_topics\HelpTopicPluginInterface $help_topic */
    $help_topic = $this->helpTopicPluginManager->createInstance($id);

    $build['#body'] = $help_topic->getBody();

    $this->renderer->addCacheableDependency($build$help_topic);

    // Build the related topics section, starting with the list this topic     // says are related.     $links = [];

    
$request_context = new RequestContext();
    $request_context->fromRequest($request);
    $this->accessUnawareRouter->expects($this->any())
      ->method('getContext')
      ->willReturn($request_context);

    $this->kernel->expects($this->once())->method('handle')->willReturnCallback(function DRequest $request) {
      return new HtmlResponse($request->getMethod());
    });

    $event = new ExceptionEvent($this->kernel, $request, HttpKernelInterface::MAIN_REQUEST, new NotFoundHttpException('foo'));

    $this->customPageSubscriber->onException($event);

    $response = $event->getResponse();
    $result = $response->getContent() . " " . UrlHelper::buildQuery($request->request->all());
    $this->assertEquals('POST name=druplicon&pass=12345', $result);
    $this->assertEquals(AccessResult::allowed()->addCacheTags(['foo', 'bar'])$request->attributes->get(AccessAwareRouterInterface::ACCESS_RESULT));
  }

  /** * Tests onHandleException with a GET request. */
if ($argument->isVariadic()
            || !\is_string($value = $request->attributes->get($argument->getName()))
            || null === ($uidClass = $argument->getType())
            || !is_subclass_of($uidClass, AbstractUid::class, true)
        ) {
            return [];
        }

        try {
            return [$uidClass::fromString($value)];
        } catch (\InvalidArgumentException $e) {
            throw new NotFoundHttpException(sprintf('The uid for the "%s" parameter is invalid.', $argument->getName())$e);
        }
    }
}
Home | Imprint | This part of the site doesn't use cookies.