Jump to content

cosmicsafari

Members
  • Posts

    75
  • Joined

  • Last visited

Everything posted by cosmicsafari

  1. 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.
  2. 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();
  3. 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.
  4. 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?
  5. 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.
  6. 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');
  7. 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.
  8. 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.
  9. 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?
  10. 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
  11. 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(); }
  12. 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.
  13. Luckily there is a front facing log in form, so I managed to add the superuser role to a normal account and log in that way. Will update when I figure out what it was I had changed and how to undo it, figure it might be useful for others in future.
  14. Scratch that I found them under 'field_roles'
  15. Hi All, Which table within the database stores a users assigned roles?
  16. Hi All, I was playing around with the settings for various templates as I had created a new role and have inadvertantly locked myself out. I changed some of the settings on the Admin template, so I assume this is what has caused the lock out. I have direct access to the database but I have no idea what I would need to change in it to regain access. Probably also worth mentioning that all the existing pages are still accessible, but /processwire throws a 404.
  17. Hi all, Just wondering if its safe to delete the content of the cache table manually within the database?
  18. Scratch that turns out I had the 'Deference in API as' set to 'Multiple pages' under the fields Details tab. Figured this might be of use to others so i'll leave this here.
  19. Hi all, I'm just trying to update a custom field value for a page but I noticed in the DB that the old value is still there? Rather than updating, it appears to create a new record for the updated value and increments the sort value. Why is this? Is it not possible to just overwrite the value within the DB using the API? For example: $pageObject->of(false); $pageObject->customField = "Updated Value"; $pageObject->save(); $pageObject->of(true); I would have expected the value just to be overwritten and persisted to the field table in the database? Obviously I am missing something or just not grasping why it works like this?
  20. Hi all, I have created a new admin page which just lists some form submission details, it works as expected so I'm pretty happy with it. The only thing I can't figure out is how to now add a new tab which links to this custom page. From what I have read it seems like most people do this by including it as part of a module, I would like to avoid creating this a page as a module as it is specific to this website and has no reusability. However I am yet to find any documentation stating whether this is even possible without going down the module route. Any help would be much appreciated.
  21. Hi All, Fairly new to ProcessWire so apologies if this is a daft question, but I am having a go creating my first module. I have set it up and enabled it as per the docs. However I have created another class within the same module directory, which was going to be used in the main module file but I can't get it to work for the life of me and I believe its due to me not fully understanding the namespace side of things. Example: MyModule.module.php <?php namespace ProcessWire; class MyModule extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Test Module', 'version' => 1, 'summary' => 'Test module', 'href' => '', 'singular' => true, 'autoload' => true, 'icon' => 'exchange', ); } public function newMethod( $testMessage ) { $foo = new Foo($testMessage); $foo->getFoo(); } } Foo.php <?php namespace ProcessWire; class Foo { protected $foo; public function __construct($foo) { $this->foo = $foo; } public function getFoo() { return $this->foo; } } Now as I understand it both these files should exist under the ProcessWire namespace, so in theory I should be able to use Foo within MyModule without any use statements as they both exist at the same level within the ProcessWire namespace? However when I try something like so: $myModule = $modules->getModule('MyModule'); $myModule->myMethod('Foo'); I would have thought this should return 'Foo', however I keep running into errors like: Any help would be appreciated.
×
×
  • Create New...