PHP code example of two16d / block-kit-php

1. Go to this page and download the library: Download two16d/block-kit-php 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/ */

    

two16d / block-kit-php example snippets


use BlockKitPHP\Surfaces;
use BlockKitPHP\Blocks;
use BlockKitPHP\Elements;
use BlockKitPHP\Objects;
use BlockKitPHP\RichTextElements;
use BlockKitPHP\RichTextObjects;

$modal = Surfaces::modal(
    'Create Task',
    [
        Blocks::section([
            'block_id' => 'intro',
            'text' => Objects::markdownText("*Create a new task* and assign it to your team.\nPlease fill in the details below."),
        ]),
        Blocks::input(
            'Task title',
            Elements::plainTextInput([
                'action_id' => 'title_input',
                'placeholder' => 'e.g. Prepare Q4 report',
            ]),
            ['block_id' => 'task_title'],
        ),
        Blocks::input(
            'Due date',
            Elements::datePicker([
                'action_id' => 'due_date_select',
                'placeholder' => 'Select a date',
            ]),
            ['block_id' => 'due_date'],
        ),
        Blocks::section([
            'block_id' => 'priority',
            'text' => Objects::markdownText('Set the task *priority*:'),
            'accessory' => Elements::staticSelect([
                'action_id' => 'priority_select',
                'placeholder' => 'Choose priority',
                'options' => [
                    Objects::option('Low', 'low'),
                    Objects::option('Medium', 'medium'),
                    Objects::option('High', 'high'),
                ],
            ]),
        ]),
        Blocks::actions(
            [
                Elements::button('Preview', ['action_id' => 'preview_task', 'style' => 'primary']),
                Elements::button('Clear', [
                    'action_id' => 'delete_draft',
                    'confirm' => Objects::confirmationDialog(
                        'Clear all fields?',
                        'This will remove all entered information.',
                        'Yes, clear',
                        'Keep editing'
                    ),
                ]),
            ],
            ['block_id' => 'footer_actions']
        ),
    ],
    [
        'close' => 'Cancel',
        'submit' => 'Save',
        'callback_id' => 'task_create_modal',
    ]
);

// Convert to JSON
$json = $modal->toJson();

// Or convert to array
$array = $modal->array();


// Helper style
$text = Objects::plainText('Hello world', ['emoji' => true]);

// Object style
$text = new PlainText('Hello world', ['emoji' => true]);

// Method chaining
$button = Elements::button('Click me')->setStyle('primary')->setActionId('click_me');
bash
composer