Jump to content
blackeye1987

Custom Field in Page SettingsTab

Recommended Posts

Hi Everyone,

i couldn't find a way to put a custom field into the settings tab

i'd need that field only as a superuser, to hide pages from my own search engine.
best would be a custom status, but a checkbox in the settingstab would be the smoothest solution

i wasn't able to find anything like that in the forum so far.


feel free to move the thread, if i am in the wrong subforum
 

Share this post


Link to post
Share on other sites

Here's a short snippet for site/ready.php that hooks after ProcessPageEdit::buildForm and moves a regular field (named "testfield here") from the Content tab to Settings. The methods used are from the InputfieldWrapper class.

<?php

wire()->addHookAfter("ProcessPageEdit::buildForm", null, "moveFieldToSettings");

function moveFieldToSettings(HookEvent $event) {
	$form = $event->return;
	
	$field = $form->find("name=testfield")->first();
	
	if($field) {
		$settings = $form->find("id=ProcessPageEditSettings")->first();
		// Alternatively, find a specific field to insert before/after:
		// $settings = $form->find("name=template")->first();
		
		if($settings) {
			$form->remove($field);
			$settings->append($field);
			// In the alternative, insert before or after the found field:
			// $form->insertBefore($field, $settings);
		}
	}	
}

 

  • Like 11

Share this post


Link to post
Share on other sites

You could also just use the field access settings to not show the field to anyone besides superusers.

  • Like 5

Share this post


Link to post
Share on other sites

@LostKobrakai - this would miss the feel of having it in the settings tab, besides yes i could make a custom settingsTab, but this would also miss my approach.

i am not looking for a quick solution more for a clean or even expandable solution.

using @BitPoet's approach , i am more flexible and able to communicate with my team and the customer.

having hidden fields through content tabs might give an irritational feel when working with customers

Share this post


Link to post
Share on other sites

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Ivan Gretsky
      Most of us know and use site/config-dev.php file. If present, it is used instead of site/config.php, so it is easy to set database connection and debug mode for local development, not touching the production config. It is also very useful when working with git. You can simply ignore it in the .gitignore file, so local settings won’t end up in the repo.
      But sometimes you need to add code to site/ready.php or site/init.php just for the dev environment. For example, to add ryan’s super cool on demand images mirrorer. I can’t live without it when working with big sites, which have more assets then I want to download to my desktop.
      It would be great if there was something like site/ready-dev.php for this. Not out-of-the-box, but it’s pretty easy to achieve. Unlike site/config-dev.php, site/ready.php is not hardcoded. It’s name is set with a special config setting:
      // wire/config.php $config->statusFiles = array( 'boot' => '', 'initBefore' => '', 'init' => 'init.php', 'readyBefore' => '', 'ready' => 'ready.php', 'readySite' => '', 'readyAdmin' => '', 'render' => '', 'download' => '', 'finished' => 'finished.php', 'failed' => '', ); As you can see, we can not only define, which files are loaded on init, ready and finished runtime states, but probably even add more if we need to.
      So we override this setting in site/config-dev.php like this:
      // site/config-dev.php // Change ready.php to ready-dev.php $temp = $config->statusFiles; $temp['ready'] = 'ready-dev.php'; $config->statusFiles = $temp; For some reason we can’t just do
      $config->statusFiles['ready'] = 'ready-dev.php'; and have to override the whole array. Maybe you PHP gurus can explain this in the comments.
      Now we can create the site/ready-dev.php file and place all the dev-only code there. Important thing is to include the main site/ready.php.
      // site/ready-dev.php include 'ready.php'; // DEV HOOK TO MIRROR ASSETS ON DEMAND $wire->addHookAfter('Pagefile::url, Pagefile::filename', function($event) { $config = $event->wire('config'); $file = $event->return; if($event->method == 'url') { // convert url to disk path $file = $config->paths->root . substr($file, strlen($config->urls->root)); } if(!file_exists($file)) { // download file from source if it doesn't exist here $src = 'https://mysite.com/site/assets/files/'; $url = str_replace($config->paths->files, $src, $file); $http = new WireHttp(); try { $http->download($url, $file); } catch (\Exception $e) { bd($file, "Missing file"); } } }); Do not forget to replace "mysite.com" if you’re copypasting this))
      Now, add the newly created file to the `.gitignore` and we’re done.
       
      # .gitignore # Ignore dev files site/config-dev.php site/ready-dev.php Thanks for reading!
       
    • By alanxptm
      Hi, first time here.
      I've been working on my first site with PW and it has been a pleasure, I'm around 75% of structure and logic completion I think, and polishing some things now.
      My question is: I have a parent 'category' page that musn't be editable by the author role, but they must be able to add children 'post page' to the 'category'.
      I've been playing with the settings and can just let the author create childs if is able too to edit the parent category, so.. How can I do it?
       
       
    • By MateThemes
      Hello everyone!
      I have searched the forum for quite a long time and I tried some solutions for my topic but nothing seems to work.
      I need to create a Settings Page and for a native feeling I want to create it under the main navigation on top. The settings page should hold the Main Logo, some styling and other settings. As I said nothing seems to work for me. I tried to create a Page under Admin with Admin Template and ProcessPageEdit but then I can't assign an image field. 
      I don't want to write a module because it is to much work for only 3 settings.
      I hope someone of the forum could help me out!
      Have a nice day!
    • By benbyf
      HELLO! I always struggle adding additional functionality, buttons and other settings to the CKeditor and I guess other people might have the same issue at times.
      For those who are CKeditor aces would you share your settings in this post to help others with what I guess should be a simple task to extend the default settings.
       

      Extra color select and text formating
      toolbar
      Format, Styles Bold, Italic, Underline, -, RemoveFormat TextColor, BGColor JustifyLeft , JustifyCenter, JustifyRight, JustifyBlock NumberedList, BulletedList, -, Blockquote PWLink, Unlink, Anchor PWImage, Table, HorizontalRule, SpecialChar PasteText, PasteFromWord Scayt, -, Sourcedialog extra allowed content
      small[*] section font[style] span[style]{!color} code[*] custom config options
      colorButton_colors: ec4626,ffde43,00aaeb,004a87,7b9320,ffffff extra plugins
      colorButton  
    • By EyeDentify
      Hello There fellow PW gurus.

      I am trying to make a field show as open only if the field is filled out with at string.
      for example: "my_styles.css" and stay hidden if the field is empty.

      The field in question is of type "text" if that helps.

      And i put in the "show this field only if"
      css_filename!=''

      because the field name is "css_filename"

      But no mather what the field is closed because i have choosen it as "closed" as default.

      What am i doing wrong?

      i am running PW 3.0.83 Dev.
       


×
×
  • Create New...