Comments

berdir’s picture

Status: Active » Needs review
StatusFileSize
new314.67 KB

And here we go.

dawehner’s picture

You should not simply even try to review that via dreditor.

+++ b/core/modules/book/book.moduleundefined
@@ -307,7 +307,7 @@ function book_form_node_form_alter(&$form, &$form_state, $form_id) {
+    if (user_access('add content to books') && ((!empty($node->book['mlid']) && !$node->isNew()) || book_type_is_allowed($node->type))) {

Both isset($node->nid) and !empty($node->nid) should be converted to the same statement. It feels like just $node->id() is the proper thing to do

+++ b/core/modules/node/lib/Drupal/node/Plugin/views/row/Rss.phpundefined
@@ -167,7 +167,7 @@ function render($row) {
-    $item->nid = $node->nid;
+    $item->id = $node->nid;

This change is potentially wrong. Shouldn't that be $item->nid = $node->id()?

+++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessFieldTest.phpundefined
@@ -90,12 +90,12 @@ function testNodeAccessAdministerField() {
+    $this->drupalGet("node/" . $node->id());

Let's use single quotes as well.

+++ b/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.phpundefined
@@ -434,7 +440,7 @@ function assertContentByXPath($xpath, array $arguments = array(), $value = NULL,
-  function assertLanguageSwitchLinks($node, $translation, $find = TRUE, $types = NULL) {
+  function assertLanguageSwitchLinks(NodeInterface $node, $translation, $find = TRUE, $types = NULL) {

@@ -462,7 +468,7 @@ function assertLanguageSwitchLinks($node, $translation, $find = TRUE, $types = N
-      if (!empty($translation->nid)) {
+      if ($translation->nid) {

+++ b/core/modules/translation/translation.moduleundefined
@@ -205,13 +205,13 @@ function translation_form_node_form_alter(&$form, &$form_state) {
-        if ($translation->nid != $node->nid) {
+        if ($translation->nid != $node->id()) {

So translation is also of type NodeInterface according to the clones above. Let's fix the documentation of assertLanguageSwitchLinks as well.

berdir’s picture

Thanks for the review!

$translation is a mess, sometimes it's just a stdclass. That was one of the uglier things to track down here.

xano’s picture

Both isset($node->nid) and !empty($node->nid) should be converted to the same statement. It feels like just $node->id() is the proper thing to do

I propose sticking to isNew(). Checking id() might be faster, but it was never made for this purpose, so we may set a wrong example by using it instead of isNew().

berdir’s picture

Agree with @Xano in this case, isNew() feels more self-documenting in this case, we're not interesting if the node has an id or not, we want to know if we're creating a new node or editing an existing one. That's not generally true, tough, there are cases where it makes more sense to check if we have an id. So I'd rather fix cases where we check for id() that don't make sense.

Fixed Rss.php and NodeAccessFieldTest.php.

dawehner’s picture

+++ b/core/modules/book/book.moduleundefined
@@ -447,11 +447,11 @@ function _book_add_form_elements(&$form, &$form_state, EntityInterface $node) {
+  $nid = $node->id() ? $node->id() : 'new';

At least this instance would make sense, most of the other ones actually care more about the id()

berdir’s picture

StatusFileSize
new693 bytes
new314.68 KB

Change that one then :)

berdir’s picture

StatusFileSize
new14.54 KB
new324.94 KB

Found a few more ->nid's while looking at the remaining NG test fails.

Status: Needs review » Needs work

The last submitted patch, node-methods-2041287-8.patch, failed testing.

oriol_e9g’s picture

out of scope:

-  $this->assertBreadcrumb(NULL, $trail, $parent->title, $tree);
+  $this->assertBreadcrumb(NULL, $trail, $parent->label(), $tree);

We can add a separate issue for the remaining title -> label conversions.

berdir’s picture

All of them are already converted in the master patch in #1939994: Complete conversion of nodes to the new Entity Field API, that one just got in accidentally as it's close to id() changes and i missed that when moving changes to the right commit.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new4.06 KB
new326.79 KB

Fixed the wrong id() in the breadcrumb test and even more nid -> id() conversions.

berdir’s picture

#12: node-methods-2041287-12.patch queued for re-testing.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Nice!

berdir’s picture

#12: node-methods-2041287-12.patch queued for re-testing.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/translation/translation.moduleundefined
@@ -566,7 +566,9 @@ function translation_language_switch_links_alter(array &$links, $type, $path) {
-        $links[$langcode]['href'] = 'node/' . $translations[$langcode]->nid . $matches[2];
+        // @todo: Unify translation objects.
+        $nid = $translations[$langcode] instanceof NodeInterface ? $translations[$langcode]->id() : $translations[$langcode]->nid;
+        $links[$langcode]['href'] = 'node/' . $nid  . $matches[2];

Asked berdir about this on IRC... he said "Looking at the code, I don't see how it could possibly ever be a NodeInterface"

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new822 bytes
new326.68 KB
new822 bytes
new326.75 KB

Removed that part.

berdir’s picture

Ignore the first patch/interdiff, that is bogus, accidently had a label() in there again.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Good catch in #16! This interdiff looked fine.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed ad13753 and pushed to 8.x. Thanks!

berdir’s picture

Issue tags: -sprint

Status: Fixed » Closed (fixed)
Issue tags: +sprint

Automatically closed -- issue fixed for 2 weeks with no activity.

berdir’s picture

Issue tags: -sprint

Removing sprint tag.

berdir’s picture

Removing sprint tag.

berdir’s picture

Issue summary: View changes

Updated issue summary.