Skip to main content
added 616 characters in body
Source Link
Kevin
  • 28k
  • 12
  • 95
  • 196

View with a path of api/VERSION/foo/bar/%node - do I need%node is not being upcast to a custom ParameterConverter for this?Node object

I am trying to create a handful of Views with a REST Export display. They have paths set behind 'api/.../.../.../%node' where %node will be an ID sent to the request to be upcasted. The basic View has a contextual filter of Content ID (excluded), and then "has any term" from this node.

However, in the contextual filter for "Taxonomy Term ID from URL" with "Load terms from the node page":

      if (($node = $this->routeMatch->getParameter('node')) && $node instanceof NodeInterface) {
        $entity = $node;
      }

This check fails, and thus the nodes terms are not checked.

Do I need a custom parameter for this purpose to tell the system what to look for? I figured as long as the ID is a node, the upcast will still occur but it is not.

Here is what xdebug sees in ViewPageController for route params and arguments:

enter image description here

7611 is the node ID, what part of the process should or usually would upcast this to a Node object?

If I do this in the Views TID argument, of course, then I have a Node:

    // Load default argument from node.
    if (!empty($this->options['node'])) {
      // Just check, if a node could be detected.
      if (($node = $this->routeMatch->getParameter('node')) && $node instanceof NodeInterface) {
        $entity = $node;
      }

      if (($node = $this->routeMatch->getParameter('node')) && !empty($node) && !($node instanceof NodeInterface)) {
        $entity = \Drupal::entityTypeManager()->getStorage('node')->load($node);
      }
    }

Edit: possibly related: https://www.drupal.org/project/drupal/issues/2528166

View with a path of api/VERSION/foo/bar/%node - do I need a custom ParameterConverter for this?

I am trying to create a handful of Views with a REST Export display. They have paths set behind 'api/.../.../.../%node' where %node will be an ID sent to the request to be upcasted. The basic View has a contextual filter of Content ID (excluded), and then "has any term" from this node.

However, in the contextual filter for "Taxonomy Term ID from URL" with "Load terms from the node page":

      if (($node = $this->routeMatch->getParameter('node')) && $node instanceof NodeInterface) {
        $entity = $node;
      }

This check fails, and thus the nodes terms are not checked.

Do I need a custom parameter for this purpose to tell the system what to look for? I figured as long as the ID is a node, the upcast will still occur but it is not.

Here is what xdebug sees in ViewPageController for route params and arguments:

enter image description here

7611 is the node ID, what part of the process should or usually would upcast this to a Node object?

View with a path of api/VERSION/foo/bar/%node - %node is not being upcast to a Node object

I am trying to create a handful of Views with a REST Export display. They have paths set behind 'api/.../.../.../%node' where %node will be an ID sent to the request to be upcasted. The basic View has a contextual filter of Content ID (excluded), and then "has any term" from this node.

However, in the contextual filter for "Taxonomy Term ID from URL" with "Load terms from the node page":

      if (($node = $this->routeMatch->getParameter('node')) && $node instanceof NodeInterface) {
        $entity = $node;
      }

This check fails, and thus the nodes terms are not checked.

Do I need a custom parameter for this purpose to tell the system what to look for? I figured as long as the ID is a node, the upcast will still occur but it is not.

Here is what xdebug sees in ViewPageController for route params and arguments:

enter image description here

7611 is the node ID, what part of the process should or usually would upcast this to a Node object?

If I do this in the Views TID argument, of course, then I have a Node:

    // Load default argument from node.
    if (!empty($this->options['node'])) {
      // Just check, if a node could be detected.
      if (($node = $this->routeMatch->getParameter('node')) && $node instanceof NodeInterface) {
        $entity = $node;
      }

      if (($node = $this->routeMatch->getParameter('node')) && !empty($node) && !($node instanceof NodeInterface)) {
        $entity = \Drupal::entityTypeManager()->getStorage('node')->load($node);
      }
    }

Edit: possibly related: https://www.drupal.org/project/drupal/issues/2528166

added 381 characters in body
Source Link
Kevin
  • 28k
  • 12
  • 95
  • 196

I am trying to create a handful of Views with a REST Export display. They have paths set behind 'api/.../.../.../%node' where %node will be an ID sent to the request to be upcasted. The basic View has a contextual filter of Content ID (excluded), and then "has any term" from this node.

However, in the contextual filter for "Taxonomy Term ID from URL" with "Load terms from the node page":

      if (($node = $this->routeMatch->getParameter('node')) && $node instanceof NodeInterface) {
        $entity = $node;
      }

This check fails, and thus the nodes terms are not checked.

Do I need a custom parameter for this purpose to tell the system what to look for? I figured as long as the ID is a node, the upcast will still occur but it is not.

Here is what xdebug sees in ViewPageController for route params and arguments:

enter image description here

7611 is the node ID, what part of the process should or usually would upcast this to a Node object?

I am trying to create a handful of Views with a REST Export display. They have paths set behind 'api/.../.../.../%node' where %node will be an ID sent to the request to be upcasted.

However, in the contextual filter for "Taxonomy Term ID from URL" with "Load terms from the node page":

      if (($node = $this->routeMatch->getParameter('node')) && $node instanceof NodeInterface) {
        $entity = $node;
      }

This check fails, and thus the nodes terms are not checked.

Do I need a custom parameter for this purpose to tell the system what to look for? I figured as long as the ID is a node, the upcast will still occur but it is not.

I am trying to create a handful of Views with a REST Export display. They have paths set behind 'api/.../.../.../%node' where %node will be an ID sent to the request to be upcasted. The basic View has a contextual filter of Content ID (excluded), and then "has any term" from this node.

However, in the contextual filter for "Taxonomy Term ID from URL" with "Load terms from the node page":

      if (($node = $this->routeMatch->getParameter('node')) && $node instanceof NodeInterface) {
        $entity = $node;
      }

This check fails, and thus the nodes terms are not checked.

Do I need a custom parameter for this purpose to tell the system what to look for? I figured as long as the ID is a node, the upcast will still occur but it is not.

Here is what xdebug sees in ViewPageController for route params and arguments:

enter image description here

7611 is the node ID, what part of the process should or usually would upcast this to a Node object?

Source Link
Kevin
  • 28k
  • 12
  • 95
  • 196

View with a path of api/VERSION/foo/bar/%node - do I need a custom ParameterConverter for this?

I am trying to create a handful of Views with a REST Export display. They have paths set behind 'api/.../.../.../%node' where %node will be an ID sent to the request to be upcasted.

However, in the contextual filter for "Taxonomy Term ID from URL" with "Load terms from the node page":

      if (($node = $this->routeMatch->getParameter('node')) && $node instanceof NodeInterface) {
        $entity = $node;
      }

This check fails, and thus the nodes terms are not checked.

Do I need a custom parameter for this purpose to tell the system what to look for? I figured as long as the ID is a node, the upcast will still occur but it is not.