Problem/Motivation

As discovered in #2886517: [regression] Flag text fields do not support HTML The Fla.g views link field plugin doesn't use flag.html.twig like it's supposed to. In fact, it uses a far older rendering method.

Proposed resolution

Update the views link field plugin to use ActionLinkTypeBase::getAsFlagLink() or a similar method that will be more maintainable.

Remaining tasks

Create patch.

User interface changes

None.

API changes

Views link field would use the template like it's supposed to.

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

socketwench created an issue. See original summary.

socketwench’s picture

Issue tags: +Release blocker
andileco’s picture

The following was helpful for me:

protected function renderLink(EntityInterface $entity, ResultRow $values) {
    // Output nothing as there is no flag.
    // For an 'empty text' option use the default 'No results behavior'
    // option provided by Views.
    if (empty($entity)) {
      return '';
    }

    $flag = $this->getFlag();
    $link_type_plugin = $flag->getLinkTypePlugin();

    return $link_type_plugin->getAsFlagLink($flag, $entity);

  }
maaty388’s picture

Status: Active » Closed (works as designed)
andileco’s picture

Why was this marked "Works as designed"?

maaty388’s picture

This custom code works

andileco’s picture

Status: Closed (works as designed) » Needs work

Thanks! I changed back to needs work, so that I can create a patch. Then we would move to "Needs Review" or "Ready to be committed" when that's posted.

andileco’s picture

Status: Needs work » Needs review
FileSize
1.17 KB

Patch attached.

Status: Needs review » Needs work

The last submitted patch, 8: 2888268-8-views-link-doesnt-use-twig.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

martin107’s picture

Status: Needs work » Postponed

We have a branch blocker at the moment ....

I am a bit busy at the moment .. I am trying to clear it as part of #2898502: Convert/Modernise FlagContextualLinksTest

sorry time is pressing for me at the moment...perhaps we need to open an isolated branch blocker issue.

jantoine’s picture

With the branch blocker issue now resolved, should the status of this issue be updated?

martin107’s picture

Status: Postponed » Needs review

Thanks for the prompt ... patch still applies - Moving to needs review to trigger testbot ... which fingers crossed should be green.

  • andileco authored 938bece on 8.x-4.x
    Issue #2888268 by andileco, socketwench, matjaz_zavski, martin107,...
socketwench’s picture

Status: Needs review » Fixed

Yep, still passes!

Thanks everyone!

pradeepjha’s picture

After applying above patch. I was able to use follow link in ajaxified way but got following error.

The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to Drupal\flag\Plugin\views\field\FlagViewsLinkField::renderLink() must implement interface Drupal\Core\Entity\EntityInterface, null given, called in /home/**/**/html/modules/contrib/flag/src/Plugin/views/field/FlagViewsLinkField.php on line 76 in Drupal\flag\Plugin\views\field\FlagViewsLinkField->renderLink() (line 114 of modules/contrib/flag/src/Plugin/views/field/FlagViewsLinkField.php).

socketwench’s picture

@pradeepjha I created a follow up issue here: #2917836: Null passed to AJAXified FlagViewsLinkField::renderLink()

Status: Fixed » Closed (fixed)

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