paste.mozilla.org allows you to share code snippets and notes with others.
These pastes require a link to be viewed; they are not private.
Anyone with the link is able to see the paste and also delete it.
Please refrain from sharing personal or sensitive information on this website to avoid it being viewed by other parties.
- /****************************************************
- * PageDisplayController (for rendering frontend)
- */
-
- <?php
-
- namespace App\Http\Controllers\Web;
-
- use App\Repositories\PageRepository;
- use Inertia\Inertia;
- use Inertia\Response;
- use CwsDigital\TwillMetadata\Traits\SetsMetadata;
-
- class PageDisplayController
- {
- use SetsMetadata;
- public function index(string $slug, PageRepository $pageRepository): Response
- {
- $page = $pageRepository->forSlug($slug);
-
- abort_if(!$page, 404);
-
- $blocks = $page->blocks->toArray();
- $this->setMetadata($page);
-
- return Inertia::render("EnglishEditing", ['blocks' => $blocks]);
- }
- }
-
-
- /******************************
- * Controller
- */
-
- <?php
-
- namespace App\Http\Controllers\Twill;
-
- use A17\Twill\Models\Contracts\TwillModelContract;
- use A17\Twill\Services\Forms\Fields\Input;
- use A17\Twill\Services\Forms\Fields\BlockEditor;
- use A17\Twill\Services\Forms\Form;
- use A17\Twill\Http\Controllers\Admin\ModuleController as BaseModuleController;
-
-
- class PageController extends BaseModuleController
- {
- protected $moduleName = 'pages';
-
- public function getForm(TwillModelContract $model): Form
- {
- $form = parent::getForm($model);
-
- $form->add(
- Input::make()->name('description')->label('Description')
- );
-
- $form->add(
- BlockEditor::make()
- );
-
- $form->addFieldset(
- \A17\Twill\Services\Forms\Fieldset::make()
- ->title(trans('twill-metadata::form.titles.fieldset'))
- ->id('metadata')
- ->fields([
- \A17\Twill\Services\Forms\BladePartial::make()->view('twill-metadata::includes.metadata-fields')
- ->withAdditionalParams([
- 'metadata_card_type_options' => config('metadata.card_type_options'),
- 'metadata_og_type_options' => config('metadata.opengraph_type_options'),
- ]),
- ])
- );
-
- return $form;
- }
- }
-
-
-
- /*****************************************************
- * Model
- */
-
- <?php
-
- namespace App\Models;
-
- use A17\Twill\Models\Behaviors\HasBlocks;
- use A17\Twill\Models\Behaviors\HasSlug;
- use A17\Twill\Models\Behaviors\HasRevisions;
- use A17\Twill\Models\Behaviors\HasPosition;
- use A17\Twill\Models\Behaviors\Sortable;
- use A17\Twill\Models\Model;
- use A17\Twill\Models\Behaviors\HasMedias;
- use CwsDigital\TwillMetadata\Models\Behaviours\HasMetadata;
-
- class Page extends Model implements Sortable
- {
- use HasBlocks, HasSlug, HasRevisions, HasPosition, HasMetadata, HasMedias;
- public \Illuminate\Contracts\Foundation\Application|
- array|
- \Illuminate\Config\Repository|
- \Illuminate\Foundation\Application
- $metadataFallbacks = [];
-
- public $mediasParams = [
- 'cover' => [
- 'default' => [
- [
- 'name' => 'default',
- 'ratio' => 16 / 9,
- ],
- ],
- ],
- ];
-
- protected $fillable = [
- 'published',
- 'title',
- 'description',
- 'position',
- ];
-
- public $slugAttributes = [
- 'title',
- ];
-
- }
-
-
- /**********************************
- * Repository
- */
- <?php
-
- namespace App\Repositories;
-
- use A17\Twill\Repositories\Behaviors\HandleBlocks;
- use A17\Twill\Repositories\Behaviors\HandleSlugs;
- use A17\Twill\Repositories\Behaviors\HandleRevisions;
- use A17\Twill\Repositories\Behaviors\HandleMedias;
- use A17\Twill\Repositories\ModuleRepository;
- use App\Models\Page;
- use CwsDigital\TwillMetadata\Repositories\Behaviours\HandleMetadata;
-
- class PageRepository extends ModuleRepository
- {
- use HandleBlocks, HandleSlugs, HandleMedias, HandleRevisions, HandleMetadata;
-
- public function __construct(Page $model)
- {
- $this->model = $model;
- }
- }