return $this->entityManager()->getStorage($this->getFlaggableType())->load($this->getFlaggableId());

This is hard to read because of the nesting. I can't tell what the load() method is on without going cross-eyed.

Comments

joachim created an issue. See original summary.

joshi.rohit100’s picture

Status: Active » Needs review
StatusFileSize
new620 bytes

Like this or need commenting ?

martin107’s picture

StatusFileSize
new616 bytes
new0 bytes

The patch from #2 looks good to me.....

I would like to make a small change to one of the method's variable names.

$flaggable_type seems a better fit when reading :-

  $flggable_type = $this->getFlaggableType();
joachim’s picture

Looks good for the approach, though there's a typo or two in the variable names -- flaggble?

martin107’s picture

Ah I just notice this Flagging::getFlaggableId() is for public access.

We could greatly simplify but just returning

$this->get('entity_id')->entity;

Full disclosure I shamelessly copied this from

\Drupal\comment\Entity\Comment::getCommentedEntity()

  /**
   * {@inheritdoc}
   */
  public function getCommentedEntity() {
    return $this->get('entity_id')->entity;
  }

I wonder if we have been missing this simplification from other FlagService methods
I will have time to think about this ... only later in the week.

PS we would have to change the BaseDefinitionField definition of entity_id from string to an entity reference.

and in a similar fashion Flagging::getFlag() in turn becomes

public function getFlag() {
+return $this->entityManager()->getStorage('flag')->load($this->getFlagId());
- return $this->get('flag_id')->entity;
}

joshi.rohit100’s picture

StatusFileSize
new618 bytes
new541 bytes

corrected typo.

martin107’s picture

StatusFileSize
new650 bytes

I have just remembered lines like

    return $this->entityManager()->getStorage($flaggable_type)->load($flaggable_id);

are a valued optimisation, especially useful when operating at scale .....

I think it would be a major change to convert string to entity_refernces...

My instinct is that this design decision maybe a good optimization for D7, but for D8 and its rewrite of the entity system
that assumption needs to be at least challenge and thoroughly profiled in a issue I want to file that issue this weekend. :)

As usual my thoughts come out too slowly ... sorry for the distraction.

the typo fix looks good.

Status: Needs review » Needs work

The last submitted patch, 7: 2557749-6.patch, failed testing.

joshi.rohit100’s picture

Status: Needs work » Needs review
StatusFileSize
new618 bytes

Re-rolled

joachim’s picture

Status: Needs review » Fixed

Thanks everyone!

  • joachim committed 639e73b on 8.x-4.x authored by joshi.rohit100
    Issue #2557749 by martin107, joshi.rohit100: Changed nested chaining in...

Status: Fixed » Closed (fixed)

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