I created a flag based on a simple custom content_type, created a new view with a page.

I added a view field "Flagging : Flag Link"

This error shows when I want to display the page containing this view

( ! ) Fatal error: Call to a member function getLinkTypePlugin() on null in drupal8\modules\flag\src\Plugin\views\field\FlagViewsLinkField.php on line 100

  protected function renderLink(EntityInterface $entity, ResultRow $values) {
    if (empty($entity)) {
      return '';
    }
    $flag = $this->getFlag();
    $link_type_plugin = $flag->getLinkTypePlugin(); <----- line 100
    $link = $link_type_plugin->getLink($flag, $entity);
    return $link;
  }

  public function getFlag() {
    if (isset($this->view->relationship[$this->options['relationship']])) {
      return $this->view->relationship[$this->options['relationship']]->getFlag();
    }
    return NULL;
  }

getFlag() seems to return NULL, a problem with a relationship somewhere ?

CommentFileSizeAuthor
#5 FlagViewsLinkField.patch1.54 KBYoyoS
#4 FlagViewsLinkField.diff1.54 KBYoyoS

Comments

YoyoS created an issue. See original summary.

YoyoS’s picture

Issue summary: View changes
YoyoS’s picture

Issue summary: View changes
YoyoS’s picture

StatusFileSize
new1.54 KB

I made a patch, It may not be the right solution but it works.

If someone wants to correct it and explains me how to make a good patch following the right Drupal patterns, I would love it :)

YoyoS’s picture

StatusFileSize
new1.54 KB
joachim’s picture

Can you explain how you built your view?

YoyoS’s picture

I first created a "Content" Flag => "fr/admin/structure/flags/add" And Selected my Flaggable Type which is a new Content Type created before. I didn't checked or changed anything except I have checked the "Display link as field"

Then I simply created a view with Display: Flagging and selected my new flag.
I checked "Create a page" with a custom alias and a pager.

Does this help ?

joachim’s picture

Title: "Flagging : Flag Link" view field showing page error » Allow "Flagging : Flag Link" view field to work on base table
Category: Bug report » Feature request
Status: Active » Needs work
Issue tags: -flag link view field

Ah yup, the flag link field is only meant to go on a relationship. So your view ought to be of nodes, with a relationship to the flag you want.

We still haven't got round to allowing views with the Flagging table as the base on D7.

YoyoS’s picture

Thanks. I was doing it wrong.

ivnish’s picture

Status: Needs work » Closed (outdated)

8 years without any activity. I think we can close it as outdated. Please reopen if needed.

ivnish’s picture

Assigned: YoyoS » Unassigned