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




return [
    'backend' => [
        'switch_column_icons'        => true,  // switch list columns as a green check / red cross
        'pages_viewbag_primary_tabs' => true,  // Winter.Pages: page settings in the main tabs
        'assets'                     => true,  // backend JS/CSS: dynamic section titles, Translate language selector
    ],
];

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

    // form field name => relation name
    public $relationable = [
        'items_list' => 'items',
    ];

    public $hasMany = [
        'items' => [GalleryItem::class, 'key' => 'gallery_id', 'delete' => true],
    ];
}

  public function validateItemsList(array $items): ?string
  {
      return count($items) > 10 ? 'A gallery can have at most 10 items.' : null;
  }
  

use NumenCode\Fundamentals\Traits\Publishable;

class Post extends Model
{
    use Publishable;
}

const PUBLISHED_COLUMN = 'active';

$post->isPublished();              // bool
Post::withUnpublished()->get();    // all records, also on the frontend
Post::onlyUnpublished()->get();    // only unpublished records

use NumenCode\Fundamentals\Traits\ComponentRenderer;

class Gallery extends ComponentBase
{
    use ComponentRenderer;

    public function defineProperties()
    {
        return [
            'layout' => [
                'title'   => 'Layout',
                'type'    => 'dropdown',
                'default' => '@default',
            ],
        ];
    }
}

Gallery::$overrideLayout = true;

use NumenCode\Fundamentals\Classes\CmsPermissions;

public function boot()
{
    CmsPermissions::revokeDelete(['owners', 'publishers'], \Acme\Demo\Controllers\Posts::class);
    CmsPermissions::revokeDuplicate('publishers', \Acme\Demo\Controllers\Posts::class);
}

if (CmsPermissions::canDelete($this)) {
    // ...
}

use NumenCode\Fundamentals\Bootstrap\ConfigOverride;

ConfigOverride::extendFields(\Winter\Blog\Models\Post::class, function (array $config) {
    $config['fields']['subtitle'] = ['label' => 'Subtitle', 'type' => 'text'];

    return $config;
});

$fields = array_insert($fields, 'content', ['subtitle' => ['label' => 'Subtitle']]);