PHP code example of numencode / wn-fundamentals-plugin

1. Go to this page and download the library: Download numencode/wn-fundamentals-plugin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

numencode / wn-fundamentals-plugin example snippets


use NumenCode\Fundamentals\Bootstrap\ConfigOverride;

// Extend fields.yaml for a specific model
ConfigOverride::extendFields(ExampleModel::class, function ($fields) {
    $fields['new_field'] = [
        'label'   => 'New Field',
        'type'    => 'text',
        'default' => 'Default Value',
    ];

    return $fields;
});

// Extend columns.yaml for a list view
ConfigOverride::extendColumns(ExampleModel::class, function ($columns) {
    $columns['new_column'] = [
        'label' => 'New Column',
        'type'  => 'text',
    ];

    return $columns;
});

// Global Overrides: Apply global configuration changes across the system.
ConfigOverride::extendAll(function ($filePath, $config) {
    if ($filePath === 'backend/models/user/fields.yaml') {
        $config['tabs']['fields']['new_field'] = [
            'label' => 'Global New Field',
            'type'  => 'text',
        ];
    }

    return $config;
});

// Integration with Winter Pages Plugin: Automatically align form tabs for Pages
Event::listen('backend.form.extendFieldsBefore', function ($form) {
    if (get_class($form->model) === Winter\Pages\Classes\Page::class) {
        // Adjust fields in the secondary tab
        foreach ((array) $form->secondaryTabs['fields'] as $key => $value) {
            $value['cssClass'] = trim(str_replace('secondary-tab', '', $value['cssClass']));
            unset($form->secondaryTabs['fields'][$key]);
            $form->tabs['fields'][$key] = $value;
        }
    }
}, 1000);

class Category extends Model
{
    public $implement = [
        '@NumenCode.Fundamentals.Behaviors.RelationableModel',
    ];

    public $hasMany = [
        'items' => [Item::class, 'key' => 'category_id'],
    ];

    public $relationable = [
        'items_list' => 'items',
    ];
}

use NumenCode\Fundamentals\Classes\CmsPermissions;

class Plugin extends PluginBase
{
    public function boot()
    {
        CmsPermissions::revokeDelete('owners', AcmeController::class);
        CmsPermissions::revokeUpdate(['owners', 'publishers'], CustomController::class);
    }
}

 if (\NumenCode\Fundamentals\Classes\CmsPermissions::canDelete($controller)): 

class MyComponent extends ComponentBase
{
    use \NumenCode\Fundamentals\Traits\ComponentRenderer;
}

// Resolves alias based on the class name
$component = new MyComponent();
$component->init();
echo $component->alias; // Outputs 'mycomponent'

class Plugin extends PluginBase
{
    public function boot()
    {
        MyComponent::$overrideLayout = true;
    }
}

// Progress Bar for CLI
foreach ($haystack as $needle) {
    $this->progressBar(isset($bar) ? ++$bar : $bar=1, count($haystack));
    // All logic comes after this line...
}

// Progress Bar for CMS
foreach ($haystack as $needle) {
    $this->autoProgressBar($haystack, 'progress');
    // All logic comes after this line...
}

class Post extends Model
{
    use \NumenCode\Fundamentals\Traits\Publishable;

    protected $fillable = ['title', 'content', 'is_published'];
}

// To fetch only published records:
$posts = Post::all();

// To 

class MyWrapper
{
    use \NumenCode\Fundamentals\Traits\Wrapper;

    protected function init($parent)
    {
        // Custom initialization logic
    }
}

// Usage
$parentObject = new ParentClass();
$wrapper = new MyWrapper($parentObject);

$wrapper->someProperty = 'value'; // Delegates to $parentObject
$result = $wrapper->someMethod(); // Calls method on $parentObject

// Accessing the Parent Object: use the getWrappedObject() method to access the original parent object if needed
$original = $wrapper->getWrappedObject();
bash
php artisan winter:up
html
<img src="{{ post.picture|media|resize('750x300.crop') }}">