From b51aa0951ee27f0cfb68594157fbf74838a7d2a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Thu, 4 Aug 2022 00:06:22 +0200 Subject: [PATCH] Fixed error, when creation of new elements is disabled in collectionTypes. This for example happens if the user does not have the permission to create new elements. --- .../elements/collection_type_controller.js | 7 +++++++ .../components/collection_type.macro.html.twig | 14 ++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/assets/controllers/elements/collection_type_controller.js b/assets/controllers/elements/collection_type_controller.js index 29d00cb2..4c804534 100644 --- a/assets/controllers/elements/collection_type_controller.js +++ b/assets/controllers/elements/collection_type_controller.js @@ -38,6 +38,13 @@ export default class extends Controller { const targetTable = this.targetTarget; const prototype = this.prototypeValue + if(!prototype) { + console.warn("Prototype is not set, we cannot create a new element. This is most likely due to missing permissions."); + bootbox.alert("You do not have the permsissions to create a new element. (No protoype element is set)"); + return; + } + + //Apply the index to prototype to create our element to insert const newElementStr = this.htmlDecode(prototype.replace(/__name__/g, this.generateUID())); diff --git a/templates/components/collection_type.macro.html.twig b/templates/components/collection_type.macro.html.twig index c895987d..c97a8c56 100644 --- a/templates/components/collection_type.macro.html.twig +++ b/templates/components/collection_type.macro.html.twig @@ -1,8 +1,14 @@ {% macro controller(form, deleteMessage) %} - {{ stimulus_controller('elements/collection_type', { - 'deleteMessage': deleteMessage|trans, - 'prototype': form_widget(form.vars.prototype)|e('html_attr') - }) }} + {% if form.vars.prototype is defined %} + {{ stimulus_controller('elements/collection_type', { + 'deleteMessage': deleteMessage|trans, + 'prototype': form_widget(form.vars.prototype)|e('html_attr') + }) }} + {% else %} {# If add_element is disabled/forbidden, prototype is not available #} + {{ stimulus_controller('elements/collection_type', { + 'deleteMessage': deleteMessage|trans, + }) }} + {% endif %} {% endmacro %} {% macro target() %}