Jump to content

Recommended Posts

Posted

Struggling with this, trying to obtain a list of fields under a specific tab in admin.

$this->addHookAfter("ProcessPageEdit::buildForm", $this, 'hookField');

 public function hookField(HookEvent $event) {
        $form = $event->return;
        $fieldset = $form->find("id=ProcessPageEditContent");
        $fields = $fieldset->fields;

        foreach($fields as $f) {
            echo $f->name.'<BR>';
        }
    }

This only outputs all fields from all templates, not the fields from the specific page & table I'm editing.

Posted
wire()->addHookAfter("ProcessPageEdit::buildForm", function($event) {
	$form = $event->return;
	$fieldset = $form->find("id=ProcessPageEditContent")->first();
	$fields = $fieldset->children;
	bd($fields->each('name'));

});

 

  • Like 6
Posted

Thanks Zeka, my next issue is I've created a custom textarea against a field, and value is saved, but I cannot return the value at render time.

I've been modeling a bit of code from:

https://processwire.com/talk/topic/9857-page-field-edit-links/

I cannot seem to replicate the rendering of saved values, here is my code:

// this works, and saves values against a custom field
$this->addHookAfter("InputfieldPage::getConfigInputfields", function($event) {
			$f = $event->object;
			if($f->hasFieldtype !== false) {
				$field = wire('modules')->get('InputfieldTextarea');
				$field->attr('name', 'helpTipContent');
				$field->attr('value', $f->helpTipContent);
				$field->collapsed = $f->helpTipContent ? false : true;
				$field->label = __('Help tip content');
				$field->description = __('Enter the help tip content that will appear in the tool tip.');
				$event->return->append($field);
			}
		});

// at render time
 $this->addHookAfter("InputfieldPage::renderReadyHook", function($event) {
			$object = $event->object;
			d($object);
		 });

// $object does not include my new field, helpTipContent.

 

Posted

@Mackski

wire()->addHookAfter("InputfieldPage(name=categories)::renderReadyHook", function($event) {
	$object = $event->object;
	bd($object->helpTipContent);
});

Just tested it and it works. 

1085310358_FireShotCapture23-EditPage_greengrocer.t_-http___greengrocer.test_admin_page_edit_.thumb.png.af9215845902e5e61993d64ba457a6be.png

Posted

@Mackski

From your screenshot, it looks like you are looking for data in the wrong place.

Your first hook adds inputfieldTextarea to InputfieldPage (page reference field)  editing page.

The second one is executed on pages which includes page reference fields.

Posted
8 minutes ago, Zeka said:

@Mackski

From your screenshot, it looks like you are looking for data in the wrong place.

Your first hook adds inputfieldTextarea to InputfieldPage (page reference field)  editing page.

The second one is executed on pages which includes page reference fields.

I've modified the hooks to add the field to every inputField.

// first hook to add field (works as expected)
$this->addHookAfter("ProcessField::buildEditFormBasics", function(HookEvent $event) {
			$f = $event->object->getField();
			if($f->hasFieldtype !== false) {
				$field = wire('modules')->get('InputfieldTextarea');
				$field->attr('name', 'helpTipContent');
				$field->attr('value', $f->helpTipContent);
				$field->collapsed = $f->helpTipContent ? false : true;
				$field->label = __('Help tip content');
				$field->description = __('Enter the help tip content that will appear in the tool tip.');
				$event->return->append($field);
			}
		});

// second hook to render
$this->addHookBefore("Inputfield::renderReadyHook", function($event)

I still cant find the helpTipContent field in the second method, maybe I'm hooking into the wrong place?

Posted

Hi @Mackski

wire()->addHookAfter("ProcessField::buildEditForm", function(HookEvent $event) {
	$form = $event->return;
	$process = $event->object;
	$f = $process->getField();

	$t = $this->wire(new InputfieldWrapper());
	$t->attr('title', $this->_x('HelpTipContent', 'tab'));
	$t->attr('class', 'WireTab');
	$t->attr('id', 'help_tip_tab');

	$field = wire('modules')->get('InputfieldTextarea');
	$field->attr('name', 'helpTipContent');
	$field->attr('value', $f->helpTipContent);
	$field->collapsed = $f->helpTipContent ? false : true;
	$field->label = __('Help tip content');
	$field->description = __('Enter the help tip content that will appear in the tool tip.');

	$_form = $this->wire(new InputfieldWrapper());
	$_form->attr('id', 'helptip_inputfield_wrapper');
	$_form->append($field);

	$template_delete_tab = $form->find('id=delete, class=WireTab')->first();

	$t->add($_form);
	$form->insertAfter($t, $template_delete_tab);
	$event->return = $form;
});

wire()->addHookBefore('ProcessField::executeSave', function($event) {
	$field = wire()->fields->get($this->input->post->id);
	$field->set('helpTipContent', $this->input->post->helpTipContent);
});

// at render time
wire()->addHookAfter("Inputfield::renderReadyHook", function($event) {
	$inputfield = $event->object;
	d($inputfield->get('hasField')->helpTipContent);
});

I have tested it with several types of inputfields and it works. But I'm not sure about this part 

d($inputfield->get('hasField')->helpTipContent);

 

Posted

Thanks for your help @Zeka

I managed to get both hooks working after a bit of debugging.

$this->addHookAfter("ProcessField::buildEditFormBasics", function(HookEvent $event) {
			$f = $event->object->getField();
			if($f->hasFieldtype !== false) {
				$field = wire('modules')->get('InputfieldTextarea');
				$field->attr('name', 'helpTipContent');
				$field->attr('value', $f->helpTipContent);
				$field->collapsed = $f->helpTipContent ? false : true;
				$field->label = __('Help tip content');
				$field->description = __('Enter the help tip content that will appear in the tool tip.');
				$event->return->append($field);
			}
		});

		// inject our markup fields into the form right after the source elements
		$this->addHookAfter('ProcessPageEdit::buildForm', function($event) {

			$form = $event->return;
			$page = $this->process->getPage();
		
			foreach($form->fields as $f) {
				$content = $f->helpTipContent;
				if($content) {

					$_field = $form->get($f->name);
					if($_field->id) {
						// add hidden field with tooltip content
						$field = wire('modules')->get('InputfieldMarkup');
						$field->attr('name', 'toolTipContent');
						$field->attr('value', $content);
						$field->skipLabel = true;
						
						$form->insertAfter($field, $_field);
					}
				}
			}
		});

 

  • 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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...