Jump to content

Problem with custom field in page settings


nabo
 Share

Recommended Posts

Hello

this is my snippet

  public function init() {
    if($this->wire('user')->isSuperuser()) {
      $this->wire()->addHookAfter('ProcessPageEdit::buildFormSettings', $this, 'buildForm');
      $this->wire()->addHookBefore('ProcessPageEdit::processInput', $this, 'saveForm');
    }
  }

  public function buildForm(HookEvent $event) {

    $p = $event->object->getPage();
    $inputfields = $event->return;

    $fieldset = $this->wire('modules')->get("InputfieldFieldset");
    $fieldset->attr('id', 'my_fieldset');
    $fieldset->label = __("My Renders");
    $fieldset->collapsed = Inputfield::collapsedYes;

    $field = $this->wire('modules')->get("InputfieldTextarea"); 
    $field->attr('name', 'renders'); 
    $field->attr('value', $p->renders); 
    $field->label = $this->_('Renders');
    $fieldset->append($field); 

    $inputfields->append($fieldset);

  }

  public function saveForm($event) {
    $page = $this->pages->get($this->input->post->id);
    $page->set('renders', $this->input->post->renders);
  }

It builds correctly the inputs, I edit the field renders but when I save the page the value of this inputfield remain blank.

What's wrong?

Link to comment
Share on other sites

45 minutes ago, flydev 👊🏻 said:

Hi,

Which is the class derived from ? Can you paste all the module code ?

 

Hi

class Renders extends WireData implements Module, ConfigurableModule {

  static public function getModuleInfo() {
    return array(
      'title'    => 'title',
      'summary'  => 'summary',
      'version'  => '1',
      'author'   => 'me',
      'autoload' => true
    );
  }

 

Link to comment
Share on other sites

I got a solution (maybe there are others better than mine)

public function init() {
    if($this->wire('user')->isSuperuser()) {
      $this->wire()->addHookAfter('ProcessPageEdit::buildFormSettings', $this, 'buildForm');
      $this->wire()->addHookBefore('Pages::saveReady', $this, 'saveForm');
    }
  }

  public function buildForm(HookEvent $event) {

    $p = $event->object->getPage();
    $inputfields = $event->return;

	$data = wire('modules')->getConfig($this);

    $fieldset = $this->wire('modules')->get("InputfieldFieldset");
    $fieldset->attr('id', 'my_fieldset');
    $fieldset->label = __("My Renders");
    $fieldset->collapsed = Inputfield::collapsedYes;

    $field = $this->wire('modules')->get("InputfieldTextarea"); 
    $field->attr('name', 'renders'); 
    $field->attr('value', $data['RendersPages'][$p->id]['renders']); 
    $field->label = $this->_('Renders');
    $fieldset->append($field); 

    $inputfields->append($fieldset);

  }

  public function saveForm($event) {
    $data = wire('modules')->getConfig($this);
    $data['RendersPages'][$this->input->post->id]['renders'] = $this->input->post->renders;
    $this->wire('modules')->saveConfig($this, $data);
  }

 

  • Like 1
Link to comment
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
 Share

×
×
  • Create New...