sylvainjule / kirby-embed

Embed field for Kirby 3 and 4.
74 stars 3 forks source link

Check for empty embed field #9

Closed possible-is closed 2 years ago

possible-is commented 2 years ago

Hello Sylvain, i am not sure if this is really a classic issue, but i didn't know how else i could get in touch. When i enter an url in an embed field and save it, and then delete the url again, the field is not completely empty. There remains an emtpy input and media info. With this, i cannot check if the field is "->isNotEmpty()", because for kirby there is always a value in there. Is there a way around this? Greetings and thanks for the wonderful plugin, Matthias

sylvainjule commented 2 years ago

Hello, the ->toEmbed() method acts like ->isNotEmpty() for this field, if the field is either empty or invalid it returns a falsy (null) value.

Like:

if($embed = $page->myfield()->toEmbed()) {
    echo $embed->code()
}
possible-is commented 2 years ago

Thanks a lot!