Skip to content

possibility to inject custom attributes of element types to field layout #10334

Answered by brandonkelly
vnali asked this question in Q&A
Discussion options

You must be logged in to vote

You can do this by registering your attributes’ fields as “standard fields” on the field layout, as mandatory layout elements. (They will be called “native fields” in Craft 4, but otherwise works the same.)

You can do that with the EVENT_DEFINE_STANDARD_FIELDS event from your plugin’s init() method:

use craft\events\DefineFieldLayoutFieldsEvent;
use craft\fieldlayoutelements\StandardTextField;
use craft\models\FieldLayout;
use yii\base\Event;

Event::on(
    FieldLayout::class,
    FieldLayout::EVENT_DEFINE_STANDARD_FIELDS,
    function(DefineFieldLayoutFieldsEvent $event) {
        /** @var FieldLayout $fieldLayout */
        $fieldLayout = $event->sender;

        if ($fieldLayout->type

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by brandonkelly
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants