prismicio-community / php-kit

Community maintained development kit for Prismic and the PHP language
https://prismic.io
Other
109 stars 83 forks source link

LinkResolver -- don't add <a> tag when resolve returns null? #21

Closed tremby closed 10 years ago

tremby commented 10 years ago

It might be useful for the HTML renderer not to print the <a> tag at all (only its contents) if the LinkResolver's resolve method (or the closure) returns null (or false or something), rather than having an <a href=""> tag when a link can't be made for whatever reason.

It'd be more useful again to be able to change the tag which is used (a <span class="broken-link"> or something, perhaps) in certain cases, rather than being limited to only changing the href.

Just an idea, since if a link is broken at the moment I can raise a warning but am otherwise stuck with an <a href="">click here to whatever</a> element. Something for the "someday" list, perhaps.

rudyrigot commented 10 years ago

Some of the other kits actually already work like that (including the Ruby kit), and I think it is a good idea, and we should probably synchronize all the kits around that behavior.

Do you need it quickly? This is basic PHP, so, with proper code review from @dohzya, I should be able to make that happen. (or if you'd rather give it a go, knock yourself out, we'd happily merge it!)

tremby commented 10 years ago

I actually started to implement the changes but making it work the same way as the Ruby meant turning the LinkInterface into an abstract Link class, and I realized I then wasn't going to have time to finish, or to write tests.

There's no big rush but it'd definitely be nice to see.

One question: isBroken is decided by Prismic before we get our hands on the data, right? But should a link be treated as if it's broken in the same way (i.e. a span element) if the link resolver returns null/false? There may be cases where the application may want to decide if a link is valid or not based on context, even if it's valid as far as Prismic is concerned.

tremby commented 10 years ago

See the pull request. I did not refactor to make it more like the Ruby kit -- this is a pretty simple change.