The column type. yii\db\QueryBuilder::getColumnType() will be called
to convert the give column type to the physical one. For example, string will be converted
as varchar(255) and string(100) becomes varchar(100). not null will automatically be
appended as well.

Returns

string – The column type. yii\db\QueryBuilder::getColumnType() will be called
to convert the give column type to the physical one. For example, string will be converted
as varchar(255) and string(100) becomes varchar(100). not null will automatically be
appended as well.

Signature

An extremely simple implementation would be to directly return some HTML:

return'<textarea name="'.$name.'">'.$value.'</textarea>';

For more complex inputs, you might prefer to create a template, and render it via
craft\web\View::renderTemplate(). For example, the following code would render a template located at
path/to/myplugin/templates/_fieldinput.html, passing the $name and $value variables to it:

If you need to tie any JavaScript code to your input, it’s important to know that any name= and id=
attributes within the returned HTML will probably get namespaced,
however your JavaScript code will be left untouched.
For example, if getInputHtml() returns the following HTML:

As you can see, that JavaScript code will not be able to find the textarea, because the textarea’s id=
attribute was changed from foo to namespace-foo.
Before you start adding namespace- to the beginning of your element ID selectors, keep in mind that the actual
namespace is going to change depending on the context. Often they are randomly generated. So it’s not quite
that simple.

Thankfully, craft\web\View provides a couple handy methods that can help you deal with this:

So here’s what a getInputHtml() method that includes field-targeting JavaScript code might look like:

publicfunctiongetInputHtml($value,$element){// Come up with an ID value based on $name$id= Craft::$app->view->formatInputId($name);// Figure out what that ID is going to be namespaced into$namespacedId= Craft::$app->view->namespaceInputId($id);// Render and return the input templatereturn Craft::$app->view->renderTemplate('myplugin/_fieldinput',['name'=>$name,'id'=>$id,'namespacedId'=>$namespacedId,'value'=>$value]);}

Returns

Signature

An extremely simple implementation would be to directly return some HTML:

return'<textarea name="foo">'.$this->foo.'</textarea>';

For more complex settings, you might prefer to create a template, and render it via
craft\web\View::renderTemplate(). For example, the following code would render a template located at
src/templates/_settings.html, passing the settings to it:

If you need to tie any JavaScript code to your settings, it’s important to know that any name= and id=
attributes within the returned HTML will probably get namespaced,
however your JavaScript code will be left untouched.
For example, if getSettingsHtml() returns the following HTML:

As you can see, that JavaScript code will not be able to find the textarea, because the textarea’s id=
attribute was changed from foo to namespace-foo.
Before you start adding namespace- to the beginning of your element ID selectors, keep in mind that the actual
namespace is going to change depending on the context. Often they are randomly generated. So it’s not quite
that simple.

Thankfully, craft\web\View service provides a couple handy methods that can help you deal
with this:

So here’s what a getSettingsHtml() method that includes field-targeting JavaScript code might look like:

publicfunctiongetSettingsHtml(){// Come up with an ID value for 'foo'$id= Craft::$app->getView()->formatInputId('foo');// Figure out what that ID is going to be namespaced into$namespacedId= Craft::$app->view->namespaceInputId($id);// Render and return the input templatereturn Craft::$app->view->renderTemplate('plugin-handle/_widget-settings',['id'=>$id,'namespacedId'=>$namespacedId,'widget'=>$this]);}

Signature

This method is called when the field’s value is first accessed from the element. For example, the first time
entry.myFieldHandle is called from a template, or right before getInputHtml() is called. Whatever
this method returns is what entry.myFieldHandle will likewise return, and what getInputHtml()’s and
serializeValue()’s $value arguments will be set to.