-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LinkResolver class usage #18
Comments
Hey, I think you'll find all of the answers to your questions and more by looking at how things are done in our plain PHP starter project (we also have one for PHP Symfony if you prefer). Writing your own class sounds like the cleanest way to do it in an advanced way, that's the way we've done it ourselves, except we've also used a (By the way, have you noticed that your code's last line is missing a closing parenthesis?) Does this bring clarity to your issue? If not, no problem, I'll look further with you. |
Missing parenthesis is a typo in the issue, not present in my code. The code you link to seems to be doing things the same way as what I have above, in that it extends the Above I'm calling https://github.com/prismicio/php-kit/blob/master/src/Prismic/Fragment/StructuredText.php#L175 An object instance is not callable. You can't do I tried calling Now, if I try to run |
My 2c on the subject. Just add a test case with the json and the code ;) Thomas Rabaix
|
Hm, there definitely seems to be something wrong... If you feel like fixing the bug, feel free, we'd love to look at it and merge it quickly. Otherwise, how to design and use the |
The LinkResolver is now an object (with its own class) thus it should not be used as a function. Should fix prismicio-community#18
Sounds like we missed this case. I added a fix and a test. @rudyrigot merge the PR if it's ok for you :-) |
Okay, thanks, @dohzya, that's an improvement. But two issues remain: First, I still can't get the resolver to run on a document object. Here's my code. class Resolver extends \Prismic\LinkResolver {
public function resolve($documentLink) {
echo "\nresolve function running\n";
return '/' . $documentLink->getType() . '/' . $documentLink->getSlug();
}
}
Route::get('hello', function() {
$results = Prismic::get('[[:d = any(document.type, ["content-page"])]]');
$resolver = new Resolver;
header("Content-Type: text/plain");
echo "\n\npost HTML:\n";
echo $results[0]->get('content-page.post')->asHtml($resolver);
echo "\n\ndocument HTML:\n";
echo $results[0]->asHtml($resolver);
exit;
});
Here's the output I get:
As you can see, the resolver runs (not sure why twice) for the I will post the other issue separately -- it is in #20. |
LinkResolver was only provided to DocumentLink, so links nested in a StructuredText (for instance) didn't receive it.
The |
Well, this looks very good to me. @tremby Do you want to have a look at it before we merge this? Your feedback has been amazingly valuable to us! |
Everything works as expected with @dohzya's changes, both with the LinkResolver instance and with closures (I will note this in the other ticket too). Please merge his changesets. Thanks very much. |
Thanks a lot for your feedback and your time! |
How is the
LinkResolver
abstract class supposed to be used? I have tried passing a closure as$linkResolver
toasHtml
on some structured text and this works, but for more nicely structured code I would have thought it'd make sense to write my own resolver class. I've tried this:and I'm getting an error on StructuredText.php line 175 saying "Function name must be a string", where it tries to do
$url = $linkResolver ? $linkResolver($span->getLink()) : '';
The text was updated successfully, but these errors were encountered: