Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by jploch

  1. @kongondo Thanks! This worked very well. With your help I implemented a setting to use my admin theme for the login. It works only if I also set the guest user to use my admin theme. This needs to be done manually in the profile settings, in addition to the module settings. For better usabillity it would be nice to set the guest user admin theme via api as well. I know that "$user->admin_theme" gives me the name for the admin theme of the current user but I have no Idea how to set the theme for the guest user. Any ideas?
  2. This seems to be it. The problem is that I don't know how to change that setting. My admin theme is based on reno and is not extending 'AdminThemeFramework' like the Uikit based themes, but the original 'AdminTheme'. So I could not integrate that setting in my theme. I tried this in my theme (taken from AdminThemeFramework.php), wich resets the login settings on all the admin themes, but then it switches back to AdminThemeUikit as the default: $class = $this->className(); foreach($this->modules->findByPrefix('AdminTheme') as $name) { if($name == $class) continue; $cfg = $this->modules->getConfig($name); if(!empty($cfg['useAsLogin'])) { unset($cfg['useAsLogin']); $this->modules->saveConfig($name, $cfg); $this->message("Removed 'useAsLogin' setting from $name", Notice::debug); } } In the docs I found this: AdminThemeFramework::useAsLogin
  3. Thx Kongondo! I already tried to find the code inside the AdminThemeUikit module files, but could not find this setting. I will take another look and repost my findings
  4. Hey folks, Iam working on a new Admin Theme, based on AdminThemeReno, which I would like to release for the public soon. Now I want to style the login page to fit the look and feel of the backend. After some research, I found out that I have to set the "$config->defaultAdminTheme = 'AdminThemeName' " inside my site config.php file to load all the styles from my admin theme on the login page instead of the default ones. Is it possible to set this via api from my Admin Theme settings, without the need of editing the config file?
  5. good to know. Never mind than 😝 Somehow I never saw "Premium Modules". Should have looked more carefully
  6. Great news! Currently I work on a rather complex module, that I would like to be able to support for a longer time. So Iam thinking to release it as a commercial module. As far as I know there is no place for community made commercial modules on the processwire website. While I really appreciate all the awesome open source modules that the community is making, sometimes a commercial module makes sense and is actually helping the developer to be able to put more resources into it. So I wonder if the new modules directory could also list commercial modules, to give developers more exposure and motivation to build complex modules.
  7. Thanks for this module! After I implemented the banner into a client website. A client complained recently that the visitor numbers drop to circa 1/4 of the usual numbers from Google Analytics. Now I need to verify that nothing is wrong with my implementation. Iam using pro cache on the website and implemented the GA code with the "pwcmbAllowCookies" check like this inside the head of my main template ("my UA Number" is replaced with the real number on my live site, I just removed it for this post) : <script> if (localStorage.getItem('pwcmbAllowCookies') === 'y') { window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'my UA Number'); } </script> Is this the correct way of implementation, could the cache somehow cause trouble? EDIT: Never mind! I forgot to also fire the cookies right after the "accept cookies" button was clicked. The tracker was only fired once the browser reloaded, so the first visit wasn't tracked, even if the user clicked accept.
  8. @Robin S this is perfect! Works like a charm. Thank you!! EDIT: After some testing I realized that the icons disappear once a new item is added to the pagetable. So I guess the ajax call and update of the pagetable removes any changes to the buttons? Do you know how to hook into the add item action and reset those icons after the ajax update is finished? EDIT2: Got it. I had to put the hook inside the init instead of ready function. Now it works!
  9. this is working great for a pagetable with a single item/button. I would like to adapt this code to set icons to multiple buttons, based on the icon that is set in the template settings of the item template (in backend GUI). Here is what I have so far, wich sets the icon markup as an attribute for the first item: $this->addHookBefore('InputfieldPageTable::render', function ($event) { $table = $event->object; $templateIconName = $this->templates->get(['id=' => $table->hasField()->template_id])->getIcon(); $templateIcon = wireIconMarkup($templateIconName); $this->addHookBefore('InputfieldButton::render', null, function (HookEvent $event) use ($templateIcon) { $button = $event->object; $button->attr('icon', $templateIcon); }); }); Any Idea how I can adapt that to work with multiple Items? And is it also possible to set the Icon markup inside a span tag or something? If its easier to set the attribute, I think I could set the markup using javascript after page load...
  10. I keep answering my own questions. Sorry this was a noob mistake. Its working fine with this php loop: $someArray=json_decode($page->pgrid_style_base, true); foreach ($someArray as $object) { foreach ($object['item'] as $item) { echo $item['id']; } }
  11. Hey there! For a module Iam working on I need an easy way to save some data as json (the data does not need to be searchable). I have trouble to save a json array in a textarea and then loop over the array with php. I don't understand why this is not working (Iam not experienced with json). JS to save the json in textarea: var s_data = []; $('.pgrid-item').each(function () { // JSON Test Storing data: myObj = { "item": [{ id: "id-test", name: "test" }] }; s_data.push(myObj); }); myJSON = JSON.stringify(s_data); $('#Inputfield_pgrid_style_base').val(myJSON); php code to decode the string and loop over the array: $someArray=json_decode($page->pgrid_style_base, true); foreach ($someArray->item as $value) { echo $value->id; }
  12. I found a post on how to check if a field type is present. Now it seems to work great: // add style fields $this->addHookAfter('Pages::added', function(HookEvent $event) { $page = $event->arguments(0); $fields = wire('fields'); // add fields only if FieldtypePageTableExtendedGrid is inside template foreach ( $page->fields as $field ) { if ( $field->type instanceof FieldtypePageTableExtendedGrid ) { if(!$fields->get('pgrid_settings_style_large')) { $field = new Field; $field->type = $this->modules->get("FieldtypeTextarea"); $field->name = "pgrid_settings_style_large"; $field->label = $this->_("Style Large"); $field->tags = 'pgrid'; $field->save(); } if(!$page->hasField('pgrid_settings_style_large')) { $field = $fields->get('pgrid_settings_style_large'); $template = $page->template; $template->fieldgroup->add($field); $template->fieldgroup->save(); } } } });
  13. Hey there, Iam working on a module (that extends FieldtypePageTable) that needs some fields to work. I want to create those fields and add them to a template automatically via api. To create and add the fields I use the "Pages::added" hook. I only want to add the field if the page that is created also has a "FieldtypePageTableExtendedGrid" field. I have a working example that uses a hard coded template name to check for the right template, but this approach would need the user to stick to the naming, wich I would like to avoid. Here is my code so far: $this->addHookAfter('Pages::added', function(HookEvent $event) { $page = $event->arguments(0); $fields = wire('fields'); if($page->template == 'main_grid') { // would like to avoid hard coded template name if(!$fields->get('pgrid_settings_style_large')) { $field = new Field; $field->type = $this->modules->get("FieldtypeTextarea"); $field->name = "pgrid_settings_style_large"; $field->label = $this->_("Style Large"); $field->tags = 'pgrid'; $field->save(); } if(!$page->hasField('pgrid_settings_style_large')) { $field = $fields->get('pgrid_settings_style_large'); $template = $page->template; $template->fieldgroup->add($field); $template->fieldgroup->save(); } } }); Maybe I need another hook? I tried a before "InputfieldPageTable::render" hook with no success. Any help would be appreciated!
  14. this looks like a good fit for my usecase! Now I hit another roadblock. I want the fields to be grouped together in a fieldset that can be collapsed. How would I do this with the inputfields approach? EDIT: Figured it out, here is my final code: $this->addHookAfter('ProcessPageEdit::buildForm', function (HookEvent $event) { $form = $event->return; $page = $event->object->getPage(); // make sure we're editing a page and not a user if ($event->process != 'ProcessPageEdit') return; if (!$page->template->hasField("pgrid")) return; $submitButton = $form->getChildByName('submit_save'); if ($submitButton) { $fieldset = $event->wire('modules')->get('InputfieldFieldset'); $fieldset->label = 'Fieldset Test'; $field1 = $event->wire('modules')->get('InputfieldText'); $field1->set('label', __('Test123')); $field1->set('name', __('test123')); $field1->addClass('test123'); $fieldset->append($field1); // append the field $form->insertBefore($fieldset, $submitButton); } $event->return = $form; }); @MoritzLost thanks again for your help, this was very helpful!
  15. Thanks @MoritzLost ! yep thats what I meant. So just to understand your approach better. You insert the fields after buildForm so they won't get saved to bd when the page is saved? This would be called everytime the page is loaded, wouldn't this be bad for performance with a lot of fields?
  16. Hey there! Iam working on a module (pagebuilder based on pagetable) that creates fields on install and adds them to a template, so the user don't have to create those fields manually. I don't need these fields to be saved in database, they are just used to generate and save some settings in a textarea field on that page (my module saves css values based on breakpoints and I don't want to create fields for every breakpoint, so I just use the fields to manipulate the css and than save all the css in one textarea). So my question is, if it will be bad for performance or bad practice to save all these fields to the database, even if I don't need them there? Or is there a way to create fields that don't save to bd? I could just insert the field markup with JS, but that would only work for certain admin themes and is kind of hacky. I hope this makes sense 🙂
  17. this is very helpful. I use this to create some select options for a module Iam working on. However this creates a blank option as the first option. How can I remove the first blank option? $this->manager = new \ProcessWire\SelectableOptionManager(); $options = 'Manual Auto'; $this->manager->setOptionsString($field, $options, true); $field->save();
  18. Hey there, so Im working on this module wich adds css grid drag and drop functionality to a pagetableextended like field and I wonder if the following working approach would cause security issues? I save the positions and dimensions of the pagetable items in one text field (named style) on the page in css syntax (its also easy to save css for different responsive sizes this way using my js code). Now I created a file for my css called style.php: <?php namespace ProcessWire; //in admin page var needs to be set if($isAdmin = $this->page->rootParent->id == 2) { $page = $this->pages->get((int) wire('input')->get('id')); } ?> <style id='pgrid-style'> <?php echo $page->style ?> </style> This is how I include that file in my module for the backend: $this->addHookAfter('Page::render', function($event) { $page = $event->object; $value = $event->return; // Return Content $p = $this->pages->get((int) wire('input')->get('id')); // // include style if page has style field if ($page->process == 'ProcessPageEdit' && count($p->pgrid_style_desktop)) { $dir = dirname(__FILE__); ob_start(); include("$dir/css/style.php"); $contents = ob_get_contents(); ob_end_clean(); $event->return = str_replace("</head>", "\n\t{$contents}</head>", $value); // Return All Changes } }); On frontend in head of main template: <!-- module css--> <?php include($config->paths->site ."modules/PageTableExtendedGrid/css/style.php");?>
  19. Thank you! This looks promising, as I could make the folder name dynamic (it's for a module based on pagetable). However this throws me an error (Method Page::renderBlock does not exist or is not callable in this context) on the frontend and also the page tree in the backend stops working after I insert that hook inside my module inside public function ready()
  20. I can't set a path this way. I think this defines only the name of the template, if I input the path it gets removed after page save.
  21. this is working: <?php echo $item->render($config->paths->templates . "blocks/" .$item->template->name. ".php"); ?> It would be better if I could get the folder of the PageTable settings (the settings where you can specify an alternative folder for your templates) programmatically
  22. Hey folks, I have a question regarding rendering of template files that are in a subfolder of the template folder. How would I for example render these PageTable items, when their template files are inside templates/blocks/: <div class="grid"> <?php foreach($page->grid_ext as $item): ?> <div id="pteg_<?= $item->id ?>"> <?php echo $item->render(); ?> </div> <?php endforeach; ?> </div> I tried this, but get an error: <?php echo $item->render(wire('config')->paths->templates . '/blocks/'); ?>
  23. Thanks @teppo! This was it! I ended up putting my hook inside the Fieldtype Module instead of the Inputfield Module and made the Fieldtype Module autoload with 'autoload' => 'template=admin'. This way the hook works and the Inputfield still seems to be only initialized when the corresponding field is on the page being edited is rendered. Here is my code (adapted from PageTableExtended): <?php namespace ProcessWire; class FieldtypePageTableExtendedGrid extends FieldtypePageTable { public static function getModuleInfo() { return array( 'title' => __('PageTable extended grid'), // Module Title 'summary' => __('Extends PageTable entries for rendering in admin', __FILE__), // Module summary 'version' => 233, 'requires' => array('FieldtypePageTable'), 'installs' => 'InputfieldPageTableExtendedGrid', 'autoload' => 'template=admin', ); } public function init() { parent::init(); } public function ready() { parent::ready(); if ($this->pages->get((int) wire('input')->get('id'))->style) { // add dynamically created styles from field back to document $this->addHookAfter('Page::render', function($event) { $value = $event->return; // Return Content $style = "<style type='text/css' class='pagegrid-styles'> ". $this->pages->get((int) wire('input')->get('id'))->style ." </style>"; // Add Style inside bottom head $event->return = str_replace("</head>", "\n\t$style</head>", $value); // Return All Changes }); } } /** * Get the Inputfield used for input by PageTableExtended * * @param Page $page * @param Field $field * @return Inputfield * */ public function getInputfield(Page $page, Field $field) { $inputfield = $this->modules->get('InputfieldPageTableExtendedGrid'); $inputfield->attr('value', $page->getUnformatted($field->name)); return $inputfield; } } Seems to work great, my hook only triggers when the style field is present on the page. Are there any drawbacks to this approach? Would my field still work with frontend editor, when I do 'autoload' => 'template=admin'?
  • Create New...