MadeMyDay Posted August 31, 2014 Share Posted August 31, 2014 I am trying to develop a module which extends the great new pageTable module. This module consists of two modules, the FieldtypePageTable and the InputfieldPageTable module, which themselves extend the FieldtypeMulti module and the Inputfield module. I am now trying to extend both of them, but I can't get access to my configuration of the Inputfield. Also I have a general question about the architecture and how those modules interact. The configuration of the Fieldtype module (shortened): public function ___getConfigInputfields(Field $field) { $inputfields = parent::___getConfigInputfields($field); $f = $this->wire('modules')->get('InputfieldText'); $f->attr('name', 'sortfields'); $f->label = $this->_('Sort fields'); $f->description = $this->_('Enter the field name that you want your table to sort by. For a descending sort, precede the field name with a hyphen, i.e. "-date" rather than "date".'); // sort description 1 $f->description .= ' ' . $this->_('You may specify multiple sort fields by separating each with a comma, i.e. "last_name, first_name, -birthday".'); // sort description 2 $f->notes = $this->_('Leave this blank for manual drag-and-drop sorting (default).'); $f->collapsed = Inputfield::collapsedBlank; $f->attr('value', $field->sortfields); $inputfields->add($f); return $inputfields; } InputfieldPageTable: public function ___getConfigInputfields() { $inputfields = parent::___getConfigInputfields(); $f = $this->wire('modules')->get('InputfieldTextarea'); $f->attr('name', 'columns'); $f->label = $this->_('Table fields to display in admin'); $f->description = $this->_('Enter the names of the fields (1 per line) that you want to display as columns in the table. To specify a column width for the field, specify "field_name=30" where "30" is the width (in percent) of the column. When specifying widths, make the total of all columns add up to 100.'); // Columns description $f->notes = $this->_('You may specify any native or custom field. You may also use subfields (field.subfield) with fields that contain multiple properties, like page references.') . ' '; // Columns notes $columns = $this->columns ? $this->columns : $this->getConfigDefaultColumns(); $f->attr('value', $columns); return $inputfields; First question: Why is this different? FieldtypePageTable references $field, whereas the InputfieldPageTable doesn't and uses $this->setting. When I try to extend the configuration options in the Inputfield like this: public function ___getConfigInputfields() { $inputfields = parent::___getConfigInputfields(); $f = $this->wire('modules')->get('InputfieldCheckbox'); $f->attr('name', 'renderLayout'); $f->attr('value', 1); //$f->attr('checked', 'checked'); if($this->renderLayout) $f->attr('checked', 'checked'); $f->label = $this->_('Render Layout instead of table rows?'); $f->description = $this->_('If checked, layout is rendered instead of table row.'); // renderLayout option description $f->notes = $this->_('Make sure that your PageTable templates render only html fragments and not complete websites.'); //$f->collapsed = Inputfield::collapsedBlank; $inputfields->add($f); $f = $this->wire('modules')->get('InputfieldText'); $f->attr('name', 'pathToCSS'); $f->attr('value', $this->pathToCSS); $f->label = $this->_('Path to Stylesheet'); $f->description = $this->_('Custom CSS to include for styling pageTable entries in Admin.'); // page name format description $f->notes = $this->_('More information to follow.'); // page name format notes $inputfields->add($f); return $inputfields; } I can see the options in the field configuration and after save I can see the settings in the field's database row: But the configs are empty again after save: Obviously the $f->attr('value', $this->pathToCSS) part is not correct. But how do I access the value in my module? In other modules this seems to be the way to go... If I try to extend the Fieldtype module's configuration, I can access the value with $field->mysetting, but here I want to extend the Inputfield and it doesn't work. Thanks in advance! Link to comment Share on other sites More sharing options...
Soma Posted August 31, 2014 Share Posted August 31, 2014 I think you're missing the inputfield init() to set the properties // fieldtype and inputfield config settings $this->set('parent_id', 0); $this->set('template_id', 0); // placeholder only $this->set('columns', ''); $this->set('nameFormat', ''); 2 Link to comment Share on other sites More sharing options...
MadeMyDay Posted August 31, 2014 Author Share Posted August 31, 2014 Yeah, Soma, thx! Had parent:init(), but didn't know I have to define the new values. So solution is: public function init() { parent::init(); $this->set('pathToCSS', ''); $this->set('renderLayout', ''); } Now the tricky part begins Perhaps you can help me: I want to hook into a (hookable) method from the InputfieldPageTable module. I try this: public function init() { parent::init(); $this->set('pathToCSS', ''); $this->set('renderLayout', ''); $this->addHook('InputfieldPageTable::renderTable', $this, 'hookRenderTable'); } with protected function hookRenderTable(HookEvent $event) { // do something } I figured for example that $event->return is the original return of the parent module. Is there some overview which other arguments are "hidden" in $event. Var_dump is so huge, I can't find the values I'm looking for (in this case the id of the page, which is rendered in the table row). 1 Link to comment Share on other sites More sharing options...
Soma Posted August 31, 2014 Share Posted August 31, 2014 Why would you "hook" into render or renderTable when you're extending the modules? If you wanted to hook into InputfieldPageTable you wouldn't need to extend it. Since you extend the inputfield you just overwrite the render method from the parent, or use its render method. public function ___renderTable(array $columns) { if($this->renderLayout) { $out = $this->attr("value"); // your method } else { $out = parent::___renderTable(); // InputfieldPageTable method } return $out; } 1 Link to comment Share on other sites More sharing options...
MadeMyDay Posted August 31, 2014 Author Share Posted August 31, 2014 Why would you "hook" into render or renderTable when you're extending the modules? Perhaps because I obviously don't know what I am doing Hooking only makes sense for events, extending for altering methods, right? I think I got it (say, a little more) Thanks Soma! Link to comment Share on other sites More sharing options...
adrian Posted August 31, 2014 Share Posted August 31, 2014 @MadeMyDay - I love what I think you are doing with this module - I was having an idea just like this the other day - can't wait to see what you come up with Link to comment Share on other sites More sharing options...
MadeMyDay Posted August 31, 2014 Author Share Posted August 31, 2014 Yeah, me too (Skills are very limited, but I WANT THIS) 1 Link to comment Share on other sites More sharing options...
MadeMyDay Posted August 31, 2014 Author Share Posted August 31, 2014 Getting there Will try to finish a first version tomorrow. Basically same function as PageTable but with the option to render the parts for a better visual interface for editors. 7 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