Jump to content

Recommended Posts

Posted

There's native `Fieldset in Tab` for creating editor tabs, but sometimes it could make more sense to put a field that's not directly related to `Content` into `Settings` or `Children` tab (such as for body class or some toggles that I see being used often). You can use the hook below to move fields between the tabs.

 

image.thumb.png.a395bbc6f409f8db3a5c02abf488f9cf.png

 

// site/ready.php

wire()->addHookAfter('ProcessPageEdit::buildForm', function (HookEvent $e) {
    // make sure we're editing a page and not a user
    if ($e->process != 'ProcessPageEdit') return;

    // RESTRICT BY TEMPLATE
    // $page = $e->object->getPage();
    // if ($page->template != 'home') return;

    // RESTRICT BY ROLE
    // $user = $e->user;
    // if (!$user->hasRole('editor')) return;

    $form = $e->return;

    $contentTab = $form->children->get('id=ProcessPageEditContent');
    $settingsTab = $form->children->get('id=ProcessPageEditSettings');
    // $childrenTab = $form->children->get('id=ProcessPageEditChildren');

    // if page template is set noSettings = true, $settings will not exist
    if (!$settingsTab) return;

    // MOVE TITLE FIELD TO SETTINGS TAB
    $title = $contentTab->get('title');
    if (!$title) return;
    $contentTab->remove('title');
    $settingsTab->prepend($title);
});

 

 

  • Like 14
  • Thanks 1
Posted
5 minutes ago, maxf5 said:

Great tip! it is also possible to add new tabs? Like a tab called SEO where i put my seo fields.

There's Fieldset in Tab (Open) for that. Create one, add to a template and move fields that you want to show in the tab between tabField and tabfield_END fields

image.png.25c07e6eeab56f7e9821e2c8db1dbae6.png

image.png.133983ac03a5c77b07f819512b4ada95.png

Which gives you a tab like this

image.thumb.png.4c0a35fd256f41ea88774cbc6933d25f.png

  • Like 2
  • Thanks 1
Posted

Cool stuff! But in the example you would definitely want that template check at the top of the hook (or check the current process with $this->process) or you will get an error when creating or editing a user (no Settings tab exists).

  • Like 3
Posted
12 minutes ago, Robin S said:

Cool stuff! But in the example you would definitely want that template check at the top of the hook (or check the current process with $this->process) or you will get an error when creating or editing a user (no Settings tab exists).

Good point. I left page template optional (but it's really encouraged), but I didn't consider user pages at all.

Updated the OP.

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...