getkirby / kirby

Kirby's core application folder
https://getkirby.com
Other
1.31k stars 168 forks source link

kirbytext:before and kirbytext:after Hooks Only Get Called Once Per Page Load #1345

Closed neildaniels closed 5 years ago

neildaniels commented 5 years ago

Describe the bug In response to Issue #1337, this commit added kirbytext:before and kirbytext:after.

Unfortunately, neither of those hooks seems to work as I would expect.

Both of these fields only executes once ever on a page. Subsequent calls on a different field, or even the same field, completely skip the hook again.

This is easily reproduced on the StarterKit, by adding the following plugin:

<?php

Kirby::plugin('plugin-debug/kirbytext-hooks', [
    'hooks' => [
        'kirbytext:after' => function (string $text) {
            return 'NOPE';
        },
    ],
]);

and then modifying the album.php template by duplicating the description output:

      <?= $page->description()->kt() ?>
      <?= $page->description()->kt() ?>

To Reproduce Steps to reproduce the behavior:

  1. Configure Starterkit as mentioned above
  2. Load the the http://localhost/photography/animals page

Expected behavior I would expect:

NOPE

NOPE

Instead, you see:

NOPE

What does the fox say?

Kirby Version 3.0.0-RC-5.0

bastianallgeier commented 5 years ago

I should have thought of this. We have a endless-loop protection setup for regular hooks because they could run recursively (something like page.update could trigger another page.update within etc.) But this also prevented those hooks from running more than once, which is of course not correct. I just fixed this and added tests for it.