Phasing out values from Content Navigator Choicelists

With Corona on the verge of closing schools and daycare in the coming week, i figured it was a good time to do some client-work, so i logged in. Immediately i found a colleague online as well (on a Sunday?!) . Anyway, he was working on a little script that needed some finetuning.

The script was to allow content-navigator render values that were no-longer valid according to EDS / Filenet (think of migrated content). The OOTB implementation would just “hide” them.

Eventually we tinkered the following:

require([
        "dojo/_base/declare",
        "dojo/_base/lang",
        "dojo/aspect",
        "ecm/widget/LayoutPropertiesPane"
    ],
    function(declare,
        lang,
        aspect,
        LayoutPropertiesPane) {

        aspect.around(LayoutPropertiesPane.prototype, "renderAttributes", function(originalrenderAttributes) {
            return function(attributeDefinitions, item, reason, isReadOnly, params) {

                attributeDefinitions.forEach(function(def) {

                    function addChoiceIfNotExists(value) {
                        var choiceExists = def.choiceList.choices.some(function(choice) {
                            return choice.value === value
                        });
                        if (!choiceExists) {
                            def.choiceList.choices.push({
                                valid: true,
                                displayName: value + " - deprecated",
                                value: value
                            });
                        }
                    }

                    if (def.choiceList) {
                        if (def.cardinality === "LIST") {
                            item.getValues(def.id).forEach(addChoiceIfNotExists);
                        } else if (def.cardinality === "SINGLE") {
                            addChoiceIfNotExists(item.getValue(def.id));
                        } else {
                            throw "Unexpected choicelist cardinality";
                        }
                    }
                });

                originalrenderAttributes.apply(this, arguments);
            }
        });
    });

Credits of course to my colleague with the long name 😉 Bruno Raphael Marques de Santana.

Leave a Reply

Your email address will not be published. Required fields are marked *