Allow defining inlineAttributeInputHtml and attributeHtml from BaseNativeField
#18039
-
|
We make heavy use of custom native field layout elements in a custom plugin i.e. extending BaseNativeField. It would be great if you could define within that class the You can already define the card preview html via Currently we have a custom implementation to achieve this but would be nice if Craft did this by default - unless we've missed something? Within the element classes we have this to set the table preview HTML which calls the same protected function attributeHtml(string $attribute): string
{
$fieldLayout = $this->getFieldLayout();
if ($fieldLayout && $fieldLayout->isFieldIncluded($attribute)) {
$field = $fieldLayout->getField($attribute);
if ($field->previewable()) {
return $field->previewHtml($this);
}
}
return parent::attributeHtml($attribute);
}For the inline inputs we have this in the element class: protected function inlineAttributeInputHtml(string $attribute): string
{
$fieldLayout = $this->getFieldLayout();
if ($fieldLayout && $fieldLayout->isFieldIncluded($attribute)) {
$field = $fieldLayout->getField($attribute);
if (method_exists($field, 'getInlineInputHtml')) {
return $field->getInlineInputHtml($this);
}
}
return parent::inlineAttributeInputHtml($attribute);
}Followed by this in the field layout elements to expose the public function getInlineInputHtml(?ElementInterface $element = null): ?string
{
return $this->inputHtml($element);
}This is a little different to how its handled in CustomFields where Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
You can customize an attribute’s HTML via use craft\base\Element;
use craft\base\Event;
use craft\events\DefineAttributeHtmlEvent;
Event::on(Element::class, Element::EVENT_DEFINE_ATTRIBUTE_HTML, function (DefineAttributeHtmlEvent $event) {
if ($event->attribute === 'myAttribute') {
$event->html = '...';
}
});And you can override its inline HTML using |
Beta Was this translation helpful? Give feedback.
You can customize an attribute’s HTML via
Element::EVENT_DEFINE_ATTRIBUTE_HTML:And you can override its inline HTML using
Element::EVENT_DEFINE_INLINE_ATTRIBUTE_INPUT_HTML.