How to overwrite a Plugin UI Backend JS file


#1

Hey guys,

I want to overwrite pimcore.document.versions ( web/pimcore/static6/js/pimcore/document/versions.js ) and pimcore.document.document. How can I do that without changing the core file ?

Best,
Alex


#2

Hi,

simply create a new one with the same namespace and inherit it from the original one, just like:

pimcore.document.versions = Class.create(pimcore.document.versions {
    getLayout: function ($super) {
        var layout = $super();
        
        return layout;
    }
});

#4

Hi @dpfaffenbauer,

what if I wanna add a checkbox to the fieldConfig of … let’s say fieldcollections.

I tried your way with adding:
pimcore.object.classes.data.fieldcollections = Class.create(pimcore.object.classes.data.fieldcollections, {

    initialize: function (treeNode, initData) {
        this.type = "fieldcollections";

        initData.gridList = false;
        this.initData(initData);

        if (typeof this.datax.lazyLoading == "undefined") {
            this.datax.lazyLoading = true;
        }

        // overwrite default settings
        this.availableSettingsFields = ["name","title","noteditable","invisible","style"];

        this.treeNode = treeNode;
    },

    getLayout: function ($super) {

        var layout = $super();
        this.specificPanel.add([
            {
                xtype: "checkbox",
                fieldLabel: t("gridList"),
                name: "gridList",
                checked: this.datax.gridList,
                disabled: this.isInCustomLayoutEditor()
            },
            {
                xtype: "displayfield",
                hideLabel: false,
                value: t('lazy_loading_warning_joooooo'),
                cls: "pimcore_extra_label_bottom",
                style: "color:red; font-weight: bold;"
            }
        ]);
        return layout;
    },

    applySpecialData: function(source) {
        if (source.datax) {
            if (!this.datax) {
                this.datax =  {};
            }
            Ext.apply(this.datax,
                {
                    allowedTypes: source.datax.allowedTypes,
                    lazyLoading: source.datax.lazyLoading,
                    maxItems: source.datax.maxItems,
                    disallowAddRemove: source.datax.disallowAddRemove,
                    disallowReorder: source.datax.disallowReorder,
                    gridList: source.datax.gridList
                });
        }
    }
});

And with creating a class like:
namespace TestBundle\Component\Extension;

use Pimcore\Model\DataObject\ClassDefinition\Data\Fieldcollections;

/**
 * Class TestFieldcollections
 *
 * @package TestBundle\Component\Extension
 */
class TestFieldcollections extends Fieldcollections
{

    /**
     * @var bool
     */
    public $gridList;

    /**
     * @return bool
     */
    public function isGridList(): bool
    {
        return $this->gridList;
    }

    /**
     * @param bool $gridList
     *
     * @return $this
     */
    public function setGridList(bool $gridList = true): self
    {
        $this->gridList = $gridList;

        return $this;
    }


}

And in the config:

pimcore:
    objects:
        class_definitions:
            data:
                map:
                    fieldcollections: TestBundle\Component\Extension\TestFieldcollections

But when i save the definition of the class (where I use a fieldcollection), I can see that the field is not inside of $data.

Am I missing something here?

I am glad for any help :slight_smile:

Kind Regards,

Martin


#5

sorry, but I am not sure it is possible what you are trying to do. Why do you wan’t to override the fieldcollection field?!


#6

I just want to add a checkbox to the “specificpanel” of fieldcollection.

So I can check in the tag/fieldcollection override, whether the field is checked or not.

If it is checked … do some code :slight_smile:

Maybe I am overthinking this …