Last active
February 2, 2019 17:20
-
-
Save Nks/7e7e96c035041206063825e1337fc068 to your computer and use it in GitHub Desktop.
Flexible content block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace App\Orchid\Entities; | |
use App\Orchid\Layouts\HomePage\FlexibleContent\TestLayout; | |
use Nakukryskin\OrchidFlexibleContentField\Screen\Fields\FlexibleContentField; | |
use Orchid\Press\Entities\Single; | |
use Orchid\Screen\Fields\InputField; | |
use Orchid\Screen\Fields\PictureField; | |
use Orchid\Screen\Fields\TextAreaField; | |
class HomePage extends Single | |
{ | |
/** | |
* @var string | |
*/ | |
public $name = 'Home Page'; | |
/** | |
* @var string | |
*/ | |
public $description = 'Edit home page'; | |
/** | |
* @var string | |
*/ | |
public $slug = 'home'; | |
/** | |
* Return default fields | |
* | |
* @return array | |
*/ | |
public function main(): array | |
{ | |
return [ | |
InputField::make('meta_title') | |
->type('text') | |
->title('Meta Title') | |
->max(255), | |
TextAreaField::make('meta_description') | |
->title('Meta Description') | |
->maxlength(360) | |
->rows(5), | |
TextAreaField::make('meta_keywords') | |
->title('Meta Keywords') | |
->rows(5) | |
]; | |
} | |
/** | |
* Rules Validation. | |
* | |
* @return array | |
*/ | |
public function rules(): array | |
{ | |
return [ | |
'id' => 'sometimes|integer|unique:posts', | |
'meta_title' => 'string|max:255|nullable', | |
'meta_description' => 'string|max:360|nullable', | |
'meta_keywords' => 'string|nullable', | |
'content.*.repeater' => 'required' | |
]; | |
} | |
/** | |
* Return all fields for the page | |
* | |
* @return array | |
*/ | |
public function fields(): array | |
{ | |
return [ | |
PictureField::make('hero_background_image') | |
->title('Hero Background Image') | |
->required() | |
->width(2000) | |
->height(740), | |
FlexibleContentField::make('flexible_content') | |
->title('Flexible Content') | |
->layouts([ | |
TestLayout::class | |
]) | |
->required() | |
]; | |
} | |
/** | |
* @return array | |
* @throws \Throwable | |
*/ | |
public function options(): array | |
{ | |
return []; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Orchid\Layouts\HomePage\FlexibleContent; | |
use App\Orchid\Fields\RepeaterFields; | |
use Nakukryskin\OrchidFlexibleContentField\Screen\Fields\FlexibleContentField; | |
use Nakukryskin\OrchidFlexibleContentField\Screen\Layouts\FlexibleContentLayout; | |
use Nakukryskin\OrchidRepeaterField\RepeaterField; | |
use Orchid\Screen\Field; | |
use Orchid\Screen\Fields\InputField; | |
use Orchid\Screen\Fields\SelectField; | |
/** | |
* Class TestLayout | |
* @package App\Orchid\Layouts\HomePage\FlexibleContent | |
*/ | |
class TestLayout extends FlexibleContentLayout | |
{ | |
/** | |
* Return name of the layout such a 'gallery' | |
* | |
* @return string | |
*/ | |
public function name(): string | |
{ | |
return 'test_layout'; | |
} | |
/** | |
* Return title of layout such a "Gallery" | |
* | |
* @return string | |
*/ | |
public function title(): string | |
{ | |
return 'Test Layout'; | |
} | |
/** | |
* Return array of the fields | |
* | |
* @return array | |
*/ | |
public function fields(): array | |
{ | |
return [ | |
Field::group([ | |
InputField::make('test_text') | |
->title('Test text') | |
->required(), | |
InputField::make('test2') | |
->title('Test text') | |
->required(), | |
]), | |
InputField::make('test3') | |
->title('Test text') | |
->required() | |
->hr(), | |
InputField::make('test4') | |
->title('Test text') | |
->required(), | |
SelectField::make('select_test.') | |
->title('Select') | |
->options([ | |
'text' => 'Text', | |
'test' => 'Test', | |
]) | |
->multiple(), | |
FlexibleContentField::make('flexible_content2') | |
->title('Flexible Content') | |
->layouts([ | |
LolLayout::class, | |
]) | |
->required(), | |
RepeaterField::make('repeater') | |
->title('repeater') | |
->handler(RepeaterFields::class), | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment