PHP code example of tdwesten / statamic-builder

1. Go to this page and download the library: Download tdwesten/statamic-builder 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/ */

    

tdwesten / statamic-builder example snippets




namespace App\Blueprints;

use Tdwesten\StatamicBuilder\Blueprint;
use Tdwesten\StatamicBuilder\FieldTypes\Section;
use Tdwesten\StatamicBuilder\FieldTypes\Text;
use Tdwesten\StatamicBuilder\FieldTypes\Tab;

class PageBlueprint extends Blueprint
{
    public $title = 'Page';

    public $handle = 'page';

    public $hidden = false;

    public function registerTabs(): Array
    {
        return [
            Tab::make('General', [
                Section::make('General', [
                    Text::make('title')
                        ->displayName('Title')
                        ->instructions('The title of the page')
                        ->localizable()
                        ->

   

   namespace App\Blueprints;

   use Tdwesten\StatamicBuilder\Blueprint;
   use Tdwesten\StatamicBuilder\FieldTypes\Assets;
   use Tdwesten\StatamicBuilder\FieldTypes\Section;
   use Tdwesten\StatamicBuilder\FieldTypes\Text;
   use Tdwesten\StatamicBuilder\FieldTypes\Tab;

   class PageBlueprint extends Blueprint
   {
       public $title = 'Page';

       public $handle = 'page';

       public $hidden = false;

       public function registerTabs(): Array
       {
           return [
               Tab::make('General', [
                   Section::make('General', [
                       Text::make('title')
                           ->displayName('Title')
                           ->instructions('The title of the page')
                           ->

   
       return [
           'blueprints' => [
               'collections.pages' => [
                   'page' => \App\Blueprints\PageBlueprint::class,
               ],
           ],
       ];
   

   

   namespace App\Fieldsets;

   use Tdwesten\StatamicBuilder\Fieldset;
   use Tdwesten\StatamicBuilder\FieldTypes\Assets;
   use Tdwesten\StatamicBuilder\FieldTypes\Text;

   class HeroFieldset extends Fieldset
   {
       public function registerFields(): array
       {
           return [
               Text::make('title')
                   ->displayName('Title')
                   ->instructions('The title of the hero')
                   ->

   
       return [
           'blueprints' => [
               'collections.pages' => [
                   'page' => \App\Blueprints\PageBlueprint::class,
               ],
           ],
           'fieldsets' => [
               \App\Fieldsets\HeroFieldset::class,
           ],
       ];
   

   

   namespace App\Blueprints;

   use App\Fieldsets\HeroFieldset;
   use Tdwesten\StatamicBuilder\Blueprint;

   class PageBlueprint extends Blueprint
   {
       public $title = 'Page';

       public $handle = 'page';

       public $hidden = false;

       public function registerTabs(): Array
       {
           return [
               Tab::make('General', [
                   Section::make('General', [
                       HeroFieldset::make('hero'),
                   ]),
               ]),
           ];
       }
   }
   

Field::make('custom_field')
    ->withAttributes([
        'type' => 'custom_type',
        'display' => 'Custom Field',
        'instructions' => 'This is a custom field',
        '

   

   namespace App\Collections;

   use Statamic\Facades\Site;
   use Tdwesten\StatamicBuilder\BaseCollection;

   class Articles extends BaseCollection
   {
       /**
        * Return the handle for the collection
        *
        * Example: return 'blog';
        */
       public static function handle(): string
       {
           return 'articles';
       }

       /**
        * Return the title for the collection
        *
        * Example: return 'Blog';
        */
       public function title(): string
       {
           return 'Articles';
       }

       // Add more options here...
   }
   

   
       return [
           'collections' => [
               \App\Collections\Articles::class,
           ],
       ];
   

   

   namespace App\Taxonomies;

   use Statamic\Facades\Site;
   use Tdwesten\StatamicBuilder\BaseTaxonomy;

   class Categories extends BaseTaxonomy
   {
       /**
        * Return the handle for the taxonomy
        *
        * Example: return 'tags';
        */
       public static function handle(): string
       {
           // TODO: Change to your taxonomy handle

           return 'categories';
       }

       /**
        * Return the title for the taxonomy
        *
        * Example: return 'Tags';
        */
       public function title(): string
       {
           // TODO: Change to your taxonomy title

           return 'Categories';
       }

       // Add more options here...
   }
   

   
       return [
           'taxonomies' => [
               \App\Taxonomies\Categories::class,
           ],
       ];
   

   
       return [
           'globals' => [
               \App\Globals\SiteSettings::class,
           ],
       ];
   

    

    namespace App\Sites;

    use Tdwesten\StatamicBuilder\BaseSite;

    class Blog extends BaseSite
    {
        /**
         * Return the handle for the site
         *
         * Example: return 'default';
         */
        public function handle(): string
        {
            return 'blog';
        }

        /**
         * Return the handle for the site
         *
         * Example: return 'Default';
         */
        public function name(): string
        {
            return 'Blog';
        }

        /**
         * Return the base url for the site
         *
         * Example: return '/';
         */
        public function url(): string
        {
            return '/blog';
        }

        /**
         * Return the locale of the site
         *
         * Example: return '/';
         */
        public function locale(): string
        {
            return 'en_US';
        }

        /**
         * Return the array of extra attributes for the site
         *
         * Example: return ['foo' => 'bar'];
         */
        public function attributes(): array
        {
            return [];
        }
    }
    

    
        return [
            'sites' => [
                \App\Sites\Blog::class
            ],
        ];
    
bash
   php artisan make:blueprint PageBlueprint
   
bash
   php artisan make:fieldset HeroFieldset
   
bash
   php artisan make:collection Articles
   
bash
   php artisan make:taxonomy Categories