PHP code example of ffhs / filament-package_ffhs_custom_forms

1. Go to this page and download the library: Download ffhs/filament-package_ffhs_custom_forms 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/ */

    

ffhs / filament-package_ffhs_custom_forms example snippets


// App/Providers/Filament/xxPanelProvider 

->plugins([CustomFormPlugin::make()])

use Ffhs\FilamentPackageFfhsCustomForms\CustomForms\CustomForm\FormConfiguration\CustomFormConfiguration;  

class SimpleForm extends CustomFormConfiguration {  

	public static function identifier(): string     {         
		return 'simple_form';     
	}      
	
	public static function displayName(): string
	{         
		return __('Simple Form');     
	} 
}

// config/ffhs_custom_forms.php 
'forms' => [ SimpleForm::class, ],`

CustomFormConfiguration.php

class MyType extends CustomFieldType  
{  
	public function getTranslatedName(): string  
	{  
	    return __('type.label');  
	}

    public static function identifier(): string  
    {  
        return 'text';  
    }  
  
    public function viewModes(): array  
    {  
        return [  
            'default' => MyTypeView::class,  
        ];  
    }  
  
    public function icon(): string  
    {  
        return 'bi-input-cursor-text';  
    }  
} 


// config/ffhs_custom_forms.php
'custom_field_types' => [  
    MyType::class,
    [..]
]

class MyTypeView implements FieldTypeView  
{  
    use HasDefaultViewComponent;  
  
    public function getFormComponent(  
        CustomFieldType $type,  
        CustomField $record,  
        array $parameter = []  
    ): FormsComponent {  
        /** @var TextInput $input */  
        return $input = $this->makeComponent(TextInput::class, $record);  
    }  
  
    public function getInfolistComponent(  
        CustomFieldType $type,  
        CustomFieldAnswer $record,  
        array $parameter = []  
    ): InfolistsComponent {  
        /** @var TextEntry $input */  
        return $input = $this->makeComponent(TextEntry::class, $record);  
    }  
}

// MyType.php
public function extraTypeOptions(): array  
{  
    return [  
       'alpine_mask' => AlpineMaskOption::make()
	       ->modifyDefault(fn($oldDefault) => '...'),  
       'max_length' => MaxLengthOption::make()
	       ->modifyOptionComponent(fn($component) => $component->columnStart(1)),    
       'min_length' => MinLengthOption::make(),  
    ];  
}

class MyTypeOption extends TypeOption  
{  
  
    public function getDefaultValue(): mixed  
    {  
        return null;  
    }  
  
    public function getComponent(string $name): Component  
    {  
        return Toggle::make($name)  
            ->label('MyTypeOption')  
            ->columnSpanFull()  
            ->live();  
    }  
    
	public function modifyFormComponent(FormsComponent $component, mixed $value): FormsComponent  
	{  
	    return $component->modify(...);  
	}  
	  
	public function modifyInfolistComponent(InfolistComponent $component, mixed $value): InfolistComponent  
	{  
	    return $component->modify(...);  
	}
}

//MyType.php
public function extraTypeOptions(): array  
{  
    return [  
       'my_option' => FastTypeOption::makeFast(  
		    default: false,  
		    Toggle::make('my_option')
		)
    ];  
}

// MyTypeView.php
$myOption = $this->getOptionParameter($record, 'my_option');

/** @var TextInput $input */  
$input = $this->makeComponent(TextInput::class, $record);

if($myOption){
	$input->modify(...);
}

return $input

//MyType.php
public function extraTypeOptions(): array  
{  
    return [  
        TypeOptionGroup::make('MyGroup', [  
		    'alpine_mask' => AlpineMaskOption::make(),  
			'max_length' => MaxLengthOption::make(),  
			'min_length' => MinLengthOption::make(),
		]),
		ValidationTypeOptionGroup::make(),  
	    LayoutOptionGroup::make()
		    ->mergeTypeOptions([  
			    'my_option' => MyTypeOption::make(),  
			])
			->removeTypeOption('...'),
    ];  
}

// MyTrigger.php
class MyTrigger extends FormRuleTriggerType  
{  
	use HasTriggerEventFormTargets; // <= Adds an CustomField Select
	
    public static function identifier(): string  
    {  
        return 'my_trigger';  
    }  
  
    public function getDisplayName(): string  
    {  
        return 'My Trigger';  
    }  
  
    public function isTrigger(array $arguments, mixed &$target, RuleTrigger $rule): bool  
    {  
      return ...;
    }  
  
    public function getFormSchema(): array  
    {  
        return [  
            Toggle::make('option for my trigger'),
            this->getTargetSelect() // <= Adds an CustomField Select
        ];  
    }  
}
  
// config/ffhs_custom_forms.php
'trigger' => [
	MyTrigger::class
	...
]  

// MyTrigger.php
class MyEvent extends FormRuleEventType  
{  
	use HasTriggerEventFormTargets; // <= Adds an CustomField Select
	
    public static function identifier(): string  
    {  
        return 'my_event';  
    }  
  
    public function getDisplayName(): string  
    {  
        return 'My Event';  
    }  
  
    public function getFormSchema(): array  
    {  
        return [  
            Toggle::make('option for my trigger'),
            this->getTargetSelect() // <= Adds an CustomField Select
        ];  
    }  

	// Implement one or more handler functions below depending on your use case:
    // - handleAnswerLoadMutation
    // - handleAnswerSaveMutation
    // - handleBeforeRender
    // - handleAfterRenderForm
    // - handleAfterRenderInfolist
}
  
// config/ffhs_custom_forms.php
'event' => [
	MyEvent::class
	...
],  

CustomFormEditor::make('custom_forms')
	->relationship('customForm')

EmbeddedCustomForm::make('custom_form_answer')
	->relationship('customFormAnswer')

EmbeddedCustomForm::make('custom_form_answer')
	->relationship('customFormAnswer')
	->autoSave()

use Ffhs\FilamentPackageFfhsCustomForms\CustomFieldType\LayoutType\Types;

EmbeddedCustomForm::make('custom_form_answer')
	->relationship('customFormAnswer')
	->useLayoutTypeSplit()
	->layoutTypeSplit(SectionType::make())

EmbeddedCustomForm::make('custom_form_answer')
	->relationship('customFormAnswer')
	->useFieldSplit()
	->fieldSplit(CustomField....)

EmbeddedCustomForm::make('custom_form_answer')
	->relationship('customFormAnswer')
	->usePoseSplit()
	->poseSplitStart(5)
	->poseSplitEnd(10)

EmbeddedAnswerInfolist::make('custom_form_answer')
	->relationship('customFormAnswer')

EmbeddedAnswerInfolist::make('custom_form_answer')
	->relationship('customFormAnswer')
	->useLayoutTypeSplit()
	->layoutTypeSplit(SectionType::make())

EmbeddedAnswerInfolist::make('custom_form_answer')
	->relationship('customFormAnswer')
	->useFieldSplit()
	->fieldSplit(CustomField....)

EmbeddedAnswerInfolist::make('custom_form_answer')
	->relationship('customFormAnswer')
	->usePoseSplit()
	->poseSplitStart(5)
	->poseSplitEnd(10)
bash
php artisan vendor:publish --tag="filament-package_ffhs_custom_forms-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="filament-package_ffhs_custom_forms-config"
bash  
php artisan vendor:publish --tag="filament-icon-picker-config"  
bash
php artisan vendor:publish --tag="filament-package_ffhs_custom_forms-views"