cosmicsafari

Members
  • Content count

    26
  • Joined

  • Last visited

Community Reputation

3 Neutral

About cosmicsafari

  • Rank
    Jr. Member
  1. public function fieldGroupOverrides($name, $overrides){ foreach($overrides as $key => $field){ if (is_array($field)) { error_log('==> Override Field: ('.$key.')'); $t = wire('templates')->get($name); $fg = $t->fieldgroup; $f = $fg->getField($key, true); //All Fields, override label if(isset($field['label'])) { $f->label = $field['label']; error_log('===> Override Label Success! ('.$key.') -> ('.$field['label'].')'); } //Page Field, overide selectable pages if(isset($field['parent_of_selectable'])){ error_log('===> Override Parent of Selectable'); $parent = wire('pages')->get('name='.$field['parent_of_selectable']); $f->set('parent_id', $parent->id); error_log('===> Override Success! Parent of Selectable = ('.$field['parent_of_selectable'].')'); } wire('fields')->saveFieldgroupContext($f, $fg); } } }
  2. I tried using $f->set('parent_id', $parent->id); But I get a warning on the page This field needs to be configured before it can be used.
  3. This was what I ended up at and it seems to work ok even if it is a bit hacky. $sql = "SELECT data FROM fields WHERE id=:fieldid"; $query = wire('database')->prepare($sql); $query->bindValue(':fieldid', $f->id); $query->execute(); $data = $query->fetchAll(); $parts = json_decode($data[0][0],true); $parts['derefAsPage']='0'; $parts['collapsed'] = '0'; $parts['parent_id'] = $parent->id; $parts['labelFieldName'] = 'title'; $parts['inputfield'] = 'InputfieldSelect'; $data = json_encode($parts); $sql = "UPDATE fields SET data=:data WHERE id=:fieldid"; $query = wire('database')->prepare($sql); $query->bindValue(':data', $data); $query->bindValue(':fieldid', $f->id); $query->execute();
  4. So from messing around in the database it looks like the when you manually select a parent under the 'Selectable Pages' section and save, it adds "parent_id":X," to the 'data' cell for the field in questions record within the fields table. In context {"tags":"Page-Multi-Select","derefAsPage":0,"collapsed":0,"parent_id":1,"labelFieldName":"title","inputfield":"InputfieldSelect"} So in theory is there any reason why I can't just update the database directly without going through the API? Seems hacky but still can't find any examples of being able to do it through the API.
  5. Hi all, I am creating a page field (field of type FieldtypePage) via the API, however im still trying to find some documentation as to how I would go about setting the Selectable Pages for said field using the API. From what I have found it looks like it involves the use of, albeit this looks like a getter rather than a setter: $field->getInputfield($page) Which looks like it would make sense if I wanted to specify the selectable pages by a parent page, but what if I wanted to specify it by say a template?
  6. Hmm so I edited my code to test this an it appears that no would be the answer. It appears that you can't assign multiple as it will just overwrite the existing field group for that template.
  7. Im an idiot, turns out I had already figured this out previously somewhere else among the code for the same module! Anyway for anyone wondering I managed to retrieve them with: $fg = wire('fieldgroups')->get('field-group-name');
  8. Hi all, Just another quick question, how would I select a previously created field group so that I can add it to a template using the API? All the examples I have seen thus far are creating the field group and adding it to a template at that point, I would rather create all my field groups beforehand and then assign them to their templates in batch.
  9. Hi all, Just a quick question before I jump in and inevitably break the module I am working on. Is it possible to assign multiple field groups to a single template via the api? I am creating a whole bunch of fields, templates and pages on the fly at install and being able to assign multiple field groups to a template would be quite advantageous.
  10. Magic, thanks!
  11. Hi all, I am working on a module which creates templates, fields & pages upon install. I have ran into an issue where I have a numerous fields which I would like to override their labels depending on the template they are used in. Is it possible to do this dynamically via API at the point where I am creating the field group and template using the API. The following is the code which I am using at the moment. foreach($templatesArray as $name => $cTemplate) { if(array_key_exists('fieldGroup',$cTemplate)) { $fg = new Fieldgroup(); $fg->name = $name . '-fg'; foreach ($cTemplate['fieldGroup'] as $field) { //possibly at this point? $fg->add($this->fields->get($field)); } $fg->save(); } $t = new Template(); $t->name = $name; $t->fieldgroup = $fg; $t->noChildren = 1; $t->setIcon($cTemplate['icon']); $t->save(); } Is this even possible?
  12. Nice, thanks man!
  13. That would go some way as to why I couldn't find anything then I suppose lol I just want the page to appear at the bottom of the list under Pages > Home
  14. Hi All, I am working on a module at the moment which in theory will create a few simple fields, templates and pages which will all be linked together. All is going well so far, I have it generating said fields, templates and pages, however I would like to also set the pages sort order and icon programmatically at this stage also. I have yet to see any documentation or any other threads where this has been brought up, is it even possible programmatically without interacting with the database directly? This is the snippet which is generating my pages on the fly at the moment. foreach($arrayOfPages as $name => $page) { $p = new Page(); $p->template = 'page'; $p->name = $page['URL']; $p->title = $name; $p->parent = wire('pages')->get('name='.$page['parent']); //is it possible to set the icon and sort order at this point, before saving? $p->save(); }
  15. Seems like Tom. was correct, the problem wasn't with the admin template after all. I forgot that I had built a module which would limited who could access pages based on the admin template depending on their roles. It appears that in creating the new role it totally messed with the logic of the module, I have since updated the module and I can log back in again as expected.