Comments

bmcclure created an issue. See original summary.

rv0’s picture

Status: Active » Needs review
StatusFileSize
new1.19 KB

Coincidently, I wrote something for this yesterday:

replicaobscura’s picture

Nice! I like it, going to get this tested and committed ASAP. Thanks!

chriswinger’s picture

The patch works, mostly, but on the first and last articles in the pager I get:

Notice: Trying to get property of non-object in Drupal\entity_pager\EntityPager->getLink() (line 179 of modules/contrib/entity_pager/src/EntityPager.php).
Drupal\entity_pager\EntityPager->getLink('link_next', 1) (Line: 55)
Drupal\entity_pager\EntityPager->getLinks() (Line: 36)
template_preprocess_entity_pager(Array, 'entity_pager', Array) (Line: 287)
rv0’s picture

Status: Needs review » Needs work

I'll have a look at it later today

rv0’s picture

Status: Needs work » Needs review
StatusFileSize
new1.28 KB

That should do it. Rerolled against latest dev

chriswinger’s picture

Patch in #6 worked for me. Thanks!

chriswinger’s picture

Status: Needs review » Reviewed & tested by the community
chriswinger’s picture

Actually, I noticed a problem with the patch (both of them actually). If you have the 'Display Count' option checked you will get the error: Fatal error: Call to undefined method Drupal\entity_pager\EntityPager::t() in /modules/contrib/entity_pager/src/EntityPager.php on line 203

chriswinger’s picture

Status: Reviewed & tested by the community » Needs work
chriswinger’s picture

This should fix the translation error.

I also also changed this so that it will always attempt to detokenize the link. If we don't do this, links on first and last pages would show the token markup.

chriswinger’s picture

Status: Needs work » Needs review
Station.ch’s picture

Status: Needs review » Needs work

Changing to my user.

s_leu’s picture

Not sure about changing this


+++ b/src/EntityPager.php
@@ -194,7 +195,7 @@ class EntityPager implements EntityPagerInterface {
+        '#markup' => t('@cnt of <span class="total">@count</span>', [

Not sure about this change. Actually it's a good idea to use an injected string translation service for this. But this would require to convert the class into a service first, which would make sense in order to allow re-using the code with dependency injection I suppose.

Besides there's some other things missing/wrong in the code of the module. For example, there's a template but no corresponding implementation of hook_theme().

The last patch fixes the fatal error but is not a clean solution IMO. Some test coverage for the token resolving and the general working of the module would be great too.

s_leu’s picture

Adding a new patch that keeps using $this->t() instead of t.

Looking at the class, probably also the token service should not be used by calling \Drupal::token() but use an injected service instead, which would require to create a factory for the EntityPager objects. It's out of scope here a followup for this would sure make sense, along with the other issues i mentioned in the last post.

Besides this, there's quite some coding style issues that should be fixed as well.

s_leu’s picture

Status: Needs work » Needs review
replicaobscura’s picture

Thanks for the effort, and the patch!

I will give the latest patch a test and get it committed ASAP if it looks good. Also, I noted your other comments about the other mentioned issues, as well as code style issues, and will handle those separately (unless there are already issues for them).

Thanks again!

  • bmcclure committed ce71b60 on 8.x-1.x authored by s_leu
    Issue #2870793 by rv0, s_leu, chriswinger, bmcclure: Support tokens in...
replicaobscura’s picture

Assigned: Unassigned » replicaobscura
Status: Needs review » Fixed

Thanks everyone! I committed a change similar to s_leu's last patch, credit given to s_leu along with mentions of everyone else that's contributed to this issue.

Status: Fixed » Closed (fixed)

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

ericshell’s picture

Currently having trouble with this feature:

1) With just the alpha 2 release I get this error on initial config of a view:
Notice: Undefined index: next_prev in template_preprocess_entity_pager() (line 34 of .../contrib/entity_pager/entity_pager.module)

2) With the alpha 2 release and patch from #15 I get this error:
Notice: Trying to get property of non-object in Drupal\entity_pager\EntityPager->getLink() (line 182 of .../entity_pager/src/EntityPager.php)

3) With the latest dev release (+5) that appears to have a similar addition for the use of tokens I get this error:
Notice: Undefined index: next_prev in template_preprocess_entity_pager() (line 34 of .../contrib/entity_pager/entity_pager.module)

Currently on 8.3.5. It looks like I get the errors 1 and 3 until I turn off the All Link, remove the link and title from textfield, and turn off the Count settings. Turning them back on seems to work fine afterwards (at least for the preview). Will continue to look into this and post any additional info I can find.

Mytko Enko’s picture

After enabling dev-mode module (with patches included?) seems to work fine on node page, but completely crashes home page:
Fatal error: Call to a member function getEntityTypeId() on a non-object in /home/r2jmq/www/modules/entity_pager/src/EntityPager.php on line 238

replicaobscura’s picture

ericshell and Mytko Enko, are both of these issues only related to using tokens in the link titles, or are these general issues you're running into regardless whether you use tokens? Trying to determine if this issue needs to be re-opened, or if a separate one should be used.

firfin’s picture

I think ericshell's issue is probably related to this issue, as he is having difficulties with alpha2 version also? Also my problem is not directly related maybe, but I am not getting the desired result using tokens with entity_pager (dev-1.x a73eadd)

No errors but tokens don't seem to get replaced? I am trying {{title}} and [title]. Neither work, what are tokens that can be used?
Also still having this problem when trying a non-token string. As in #2920753: Changing labels has no effect

plusproduit’s picture

Hi,
I just updated to latest dev because of https://www.drupal.org/project/entity_pager/issues/2900996
Now the tokens don't work in next/prev links.
The patches in this issue don't seem to apply to latest dev (dec 8 2017). Any help would be appreciated!

EDIT:
Sorry I just realized that the tokens are not views replacement tokens, so now I use [node:title] instead of {{ node:title }} and it works like a charm