Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cleggypdc/421ebaac7f04baffaad57ed58f2289bd to your computer and use it in GitHub Desktop.
Save cleggypdc/421ebaac7f04baffaad57ed58f2289bd to your computer and use it in GitHub Desktop.
Pimcore Custom Field example
<?php
//place me in /plugins/MyPlugin/lib/HiLifeAdminTheme/Plugin.php
namespace MyPlugin;
use Pimcore\API\Plugin as PluginLib;
class Plugin extends PluginLib\AbstractPlugin implements PluginLib\PluginInterface
{
public static function install()
{
// implement your own logic here
return true;
}
public static function uninstall()
{
// implement your own logic here
return true;
}
public static function isInstalled()
{
// implement your own logic here
return true;
}
}
<?php
//place me in /plugins/MyPlugin/lib/Pimcore/Model/Object/ClassDefinition/Data/Inputnolabel.php
namespace Pimcore\Model\Object\ClassDefinition\Data;
use Pimcore\Model;
class Inputnolabel extends Model\Object\ClassDefinition\Data\Input {
/**
* Static type of this element
*
* @var string
*/
public $fieldtype = "inputnolabel";
}
<?xml version="1.0"?>
<zend-config xmlns:zf="http://framework.zend.com/xml/zend-config-xml/1.0/">
<plugin>
<!-- place me in /plugins/MyPlugin/plugin.xml -->
<!-- the plugin name [A-Za-z_] -->
<pluginName>MyPlugin</pluginName>
<!-- a short description -->
<pluginDescription><![CDATA[Provides custom input with no label]]></pluginDescription>
<!-- meta data -->
<pluginVersion>1.0</pluginVersion>
<pluginRevision>1</pluginRevision>
<pluginBuildTimestamp>0</pluginBuildTimestamp>
<!-- className of the plugin which extends Pimcore_API_Plugin_Abstract-->
<pluginClassName>\MyPlugin\Plugin</pluginClassName>
<!-- include paths relative to plugin-directory -->
<pluginIncludePaths>
<path>/MyPlugin/lib</path>
</pluginIncludePaths>
<!-- namespaces to register with autoloader-->
<pluginNamespaces>
<namespace>MyPlugin</namespace>
</pluginNamespaces>
<!-- js files with path relative to plugin-directory -->
<pluginJsPaths>
<path>/plugins/MyPlugin/static/js/object/classes/data/inputnolabel.js</path>
<path>/plugins/MyPlugin/static/js/object/tags/inputnolabel.js</path>
</pluginJsPaths>
</plugin>
</zend-config>
//place me in /plugins/MyPlugin/static/js/object/classes/data/inputnolabel.js
pimcore.registerNS("pimcore.object.classes.data.inputnolabel");
pimcore.object.classes.data.inputnolabel = Class.create(pimcore.object.classes.data.input, {
type: "inputnolabel",
initialize: function (treeNode, initData) {
this.type = "inputnolabel";
this.initData(initData);
this.treeNode = treeNode;
},
getTypeName: function () {
return t("inputnolabel");
}
});
//place me in /plugins/MyPlugin/static/js/object/tags/inputnolabel.js
pimcore.registerNS("pimcore.object.tags.inputnolabel");
pimcore.object.tags.inputnolabel = Class.create(pimcore.object.tags.input, {
type: "inputnolabel",
initialize: function (data, fieldConfig) {
this.data = "";
if (data) {
this.data = data;
}
this.fieldConfig = fieldConfig;
},
getLayoutEdit: function () {
var input = {
emptyText: this.fieldConfig.titleOriginal,
name: this.fieldConfig.name,
componentCls: "object_field",
hideLabel: true
};
if (this.data) {
input.value = this.data;
}
if (this.fieldConfig.width) {
input.width = this.fieldConfig.width;
} else {
input.width = 250;
}
if(this.fieldConfig.columnLength) {
input.autoCreate = {tag: 'input', type: 'text', maxlength: this.fieldConfig.columnLength};
}
if(this.fieldConfig["regex"]) {
input.regex = new RegExp(this.fieldConfig.regex);
}
this.component = new Ext.form.TextField(input);
return this.component;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment