1

Do the "isEditable" property of Entry still exists? Whats the best way to achieve the same functionallity in Craft 4?

{% if entry.isEditable() %}

After I upgraded from Craft 3 to 4, all my "edit links" are gone from the website. Looking at the Craft's documentation, it's missing this property in v4 docs (but exist in v3).

https://docs.craftcms.com/api/v4/craft-elements-entry.html#public-properties https://docs.craftcms.com/api/v3/craft-elements-entry.html#public-properties

1 Answer 1

3

The getIsEditable() method was removed in Craft 4.0, in favour of some new element methods like canView() and canSave(). These were brought in with the new "unified element editor" and AFAIK these methods are only mentioned in the plugin upgrade guide, not the main Craft 4 upgrade guide. They are still totally fine to use in front end templates, though.

To replace getIsEditable(), the closest equivalent is probably the canSave() method:

{% if currentUser and entry.canSave(currentUser) %}
    ...
{% endif %}

Also, in Craft 4.3 the new global Twig functions canView() and canSave() were added, which wraps the methods mentioned above. I personally prefer to use the global functions, as they typically make a conditional like the above a lot terser:

{% if canSave(entry) %}
    ...
{% endif %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.