Boost Posted October 23, 2023 Share Posted October 23, 2023 Hello, I'm aware that Overrides are not necessarily dangerous; most of the time, they are simply misused, just like I did. However, I believe there is a lack of documentation on this topic. So, I would love some clarity on Overrides, as I think I might have misunderstood the concept. Here's what I've gathered: I created a FieldsetPage fieldtype named Hero, with the following fields: image, text, body, and URL. I added the Hero field to the basic-page template. I created three pages: A, B, and C, all using the basic-page template. Now, here's where it gets interesting. On page A, I made no changes to the Hero. I used it as it is. On page B, I overrode the label of the image field to "logo". On page C, I overrode the Hero by adding an extra field, such as a textarea. Now, the changes made on page B and C will affect page A, correct? Is there a way to allow overrides by individual pages, rather templates? This would provide us with a lot of flexibility, wouldn't it? My issue happened when I started adding extra fields and removing some, like I did on page C. I forgot it was one template-based page, so I ended up messing up the other pages. One last thing. I don't understand the warning: " WARNING: enabling settings beyond those specified by the Fieldtype/Inputfield module may not always work, or may cause problems" So, folks, I'd be extremely grateful for any insights regarding overrides, perhaps some best practices and what to avoid. Cheers! Link to comment Share on other sites More sharing options...
poljpocket Posted October 24, 2023 Share Posted October 24, 2023 Interesting topic. Assuming you have enabled the override for "Details: fields in fieldset", the warning you are talking about applies to your case. It simply means that any fields not rendered bold in the Overrides list are untested and may cause problems when using an override on them. It doesn't say it wouldn't work, though. It says you must test whatever you enable. Now, I don't get how you achieved Overrides outside the template context. As far as I know, this isn't possible and from a frontend point of view also doesn't make any sense. You can easily create multiple templates (and their respective template files) which only differ in Overrides for a specific field. There is simply no need to have Overrides on a per-page basis. Can you clarify on that last part? Link to comment Share on other sites More sharing options...
Boost Posted October 24, 2023 Author Share Posted October 24, 2023 44 minutes ago, poljpocket said: Now, I don't get how you achieved Overrides outside the template context. As far as I know, this isn't possible and from a frontend point of view also doesn't make any sense. You can easily create multiple templates (and their respective template files) which only differ in Overrides for a specific field. There is simply no need to have Overrides on a per-page basis. I did not get Overrides outside the template. So, maybe here is my confusion about how to use Overrides correctly. Link to comment Share on other sites More sharing options...
gebeer Posted October 27, 2023 Share Posted October 27, 2023 It just so happens, that I needed to do overrides for a FieldTypeFieldsetPage field from the API inside a hook. Took some effort to finally get this working. Just wanted to share this. /** * HOOK for changing label, description, notes for fields inside a FieldtypeFieldsetPage field */ $wire->addHookAfter("ProcessPageEdit::buildFormContent", function (HookEvent $event) { $page = $event->object->getPage(); if ($page->template->name !== 'your-template-name') return; $form = $event->return; // product_description is our target field // which holds fields 'image', 'headline', 'description' // product_description is of type FieldtypeFieldsetPage (FieldtypeRepeater under the hood) // get InputField /** @var InputfieldRepeater $inputField */ $inputField = $form->get('product_description'); // get actual Field from InputField /** @var RepeaterField $field */ $field = $inputField->hasField->getContext($page->template); // change label, description, notes for 'image' field /** @var Field $field */ $field->fields('image')->label = 'Hero Image'; $field->fields('image')->description = 'Also shows on overview cards'; $field->fields('image')->notes = 'Dimensions: 800x600px'; }); @Boostdid you manage to do the overrides in the template settings? On my install this does not work. Here are my field settings: And here's how the override settings in a template look like: Just being curious how that looks on your install :-) 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now