Problem/Motivation

The following steps worked for me:

  • Enable hal, rest and serializer
  • Allow the anonymous user to create page content and Create and edit URL aliases
  • Post the following code to http://d8.dev/entity/node:
    {
    "type": [
    {
    "target_id": "article"
    }
    ],
    "title": [
    {
    "value": "Hello world example"
    }
    ],
    "_links": {
    "type": {
    "href": "http://d8.dev/rest/type/node/page"
    }
    },
    "path":[
    {
    "alias": "/example"
    }
    ]
    }
    
  • A new entry was created on 'http:/d8.dev/example'

It is quite hard to get the NID from that

Proposed resolution

Don't use path aliases for the generated URL

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner created an issue. See original summary.

dawehner’s picture

Status: Active » Needs review
Issue tags: +Needs tests
FileSize
921 bytes

Here is a patch for this, of course though, we need some tests.

tim.plunkett’s picture

+++ b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php
@@ -108,7 +108,7 @@ public function post(EntityInterface $entity = NULL) {
+      $url = $entity->urlInfo('canonical', ['absolute' => TRUE, 'alias' => FALSE])->toString(TRUE);

Makes sense to me. Might as well switch to toUrl() while you're fixing this.

dawehner’s picture

dawehner’s picture

There we go.

The last submitted patch, 4: 2610694-3.patch, failed testing.

The last submitted patch, 4: 2610694-fail.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 5: 2610694-3.patch, failed testing.

dawehner’s picture

Just some additional work, but it seems to be that things aren't that easy.

Wim Leers’s picture

Status: Needs work » Needs review

It is quite hard to get the NID from that

:P

Oh, the smell of beautiful sarcasm!

Status: Needs review » Needs work

The last submitted patch, 9: 2610694-9.patch, failed testing.

Berdir’s picture

Hm. Doing this as a way to get the NID seems like the wrong solution. We have separate issues to return the created data and we have yet another issue to return the ID.

The thing is that with redirect.module (global redirect functionality) or #2641118: Route normalizer: Global Redirect in core, actually trying to access that page will force a redirect to the alias anyway.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

Status: Needs work » Fixed

Hm. Doing this as a way to get the NID seems like the wrong solution. We have separate issues to return the created data and we have yet another issue to return the ID.

Fair point, I think we can close the issue then.

Wim Leers’s picture

Status: Fixed » Closed (works as designed)