Cockpit-HQ / Cockpit

Cockpit Core - Content Platform
https://getcockpit.com
Other
388 stars 47 forks source link

How to extend components and edit existing components. #217

Closed DGINXREAL closed 2 months ago

DGINXREAL commented 2 months ago

Hello i'm new at Cockpit. I have some question about the Components/Layouts.

What is the correct way to edit existing components for the layouts?

And how can we add new components?

We want to provide all of this in an extra addon, that we can just install in different projects.

KR

DGINXREAL commented 2 months ago

Ah i found it by myself.

$this->on('layout.components.collect', function($components) {
    // Add a custom layout component
    $components['video']['fields'] = array_map(function($field){
        if($field['name'] === "attr"){
            $field['opts']['options'][] = 'itsDginx';
        }
        return $field;
    }, $components['video']['fields']);

    $components['mycustomcomponent'] = [
        'label' => 'My Custom Component',
        'icon'  => 'icon.svg',
        'template' => '<div>{{ content }}</div>' // Custom HTML structure
    ];

    ray($components);
});