Meysam
Meysam

Reputation: 18137

OctoberCMS: How to remove the delete button of update page

I am using the FormController behavior for a controller. There is a delete button (trash icon) in the Update page which I need to hide for logged in users who are not superuser. I can remove the delete button by simply removing its html from the update.htm file:

<button
    type="button"
    class="oc-icon-trash-o btn-icon danger pull-right"
    data-request="onDelete"
    data-load-indicator="<?= e(trans('backend::lang.form.deleting')) ?>"
    data-request-confirm="<?= e(trans('backend::lang.form.confirm_delete')) ?>">
</button>

But this will remove the delete button for all users. I only want to remove this button if the logged in backend user is not admin. How can I do this dynamically?

Upvotes: 1

Views: 1344

Answers (1)

OsDev
OsDev

Reputation: 1252

You can check if the user is superuser because your view has access to the user object

<?php if($this->user->is_superuser): ?>
    <button
     type="button"
     class="oc-icon-trash-o btn-icon danger pull-right"
     data-request="onDelete"
     data-load-indicator="<?= e(trans('backend::lang.form.deleting')) ?>"
     data-request-confirm="<?= e(trans('backend::lang.form.confirm_delete')) ?>">
    </button>
<?php endif; ?>

Upvotes: 2

Related Questions