Jump to content
nabo

Problem with custom field in page settings

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?

Share this post


Link to post
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
    );
  }

 

Share this post


Link to post
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

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 dfile
      Hello,
      I am running ProcessWire 3.0.165 but $input->urlSegmentLast or $input->urlSegment(-1) does not work as expected.
      Or do I something wrong?
      Thank you.

    • By bramwolf
      Hi Guys,

      I found here: https://processwire.com/docs/selectors/#finding2 that I can exclude results from my $pages->find($selctor); query by using parent!=123 ( parent ID ) But I was wondering if I can
      also do so based on the parent template? I've tried doing it by itterating over the matches array and dropping the matches with the parent but since the result is limited for use with the paginator
      it only drops the items from the batch displayed on this page. Say from the results within matches 0 - 20 and not the entire 0 - 220.

      Anybody have a idea of how to achieve this? 🙂

      Thanks in advace!
      Bram 
    • By LAPS
      I've pages using the custom-page-template and I would like to display a simple message at the top of the page form when editing those pages in the Admin.
      I thought about hooking ProcessPageEdit::buildForm() but I do not well how to use that hook in order to display the message just for the custom-page-template pages.
      Any help?
       
       
      UPDATE: Solution found
      wire()->addHookAfter('ProcessPageEdit::buildForm', function(HookEvent $event) { $ProcessPageEdit = $event->object; $form = $event->arguments('form'); switch ($ProcessPageEdit->getPage()->template->name) { case 'custom-page-template': $form->prependMarkup("<div style='margin-bottom: 3.6em; margin-top: 1em; background: #ffd;'>MY MESSAGE</div>"); break; default: // do nothing } }); Any improvement is welcome!
    • By Sten
      Sorry I can't find any submit button to save my configuration on a template in the admin interface. The file is fine.
    • By carlitoselmago
      I'm building a fieldtype/inputfield to visually select a grid like Bootstrap since it's the first time coding such thing, I'm basing my code in FieldtypeColorPicker since the base structure is the same, a graphical UI helper to finally output a string as value.
      The problem is I try to save the value as something like "1,2,3" referencing the index of each column selected but it gets converted as an int value so "1,2,3" becomes "1" if input random text it gets converted as "0".
      Here is the code:
      https://github.com/carlitoselmago/FieldtypeGridSpace
      Here's an screenshot of how it looks

×
×
  • Create New...