Jump to content

Robin S

Members
  • Posts

    5,009
  • Joined

  • Days Won

    333

Everything posted by Robin S

  1. This is something I used in a couple of modules recently and it could be useful as a standalone hook. It adds classes to the body tag in the admin theme for: roles the user has if the user is a non-superuser the user's name You could use this if you want to tweak the admin interface for a role using CSS/JS (e.g. with Admin Custom Files). There is also an old wishlist item requesting this. $this->addHookAfter('AdminTheme::getExtraMarkup', function($event) { $theme = $event->object; $user = $this->user; foreach($user->roles as $role) { $theme->addBodyClass("role-{$role->name}"); } if(!$user->isSuperuser()) $theme->addBodyClass("role-nonsuperuser"); $theme->addBodyClass("user-{$user->name}"); });
  2. v0.0.5 released - improved config system (screenshot updated in first post).
  3. v0.0.6 released. PageTables may now be restricted by role (uses CSS/JS so not suitable for mission-critical restrictions) New options to prevent trash, prevent drag sorting, and removal of all "Add" buttons regardless of template. Improved config system (screenshot in first post updated)
  4. @LimeWub, one thing to be aware of is that this will make your module incompatible with PW2.x. But that may not be a problem to you.
  5. Here is a server-side alternative to (or backup for) the JS validation. $this->addHookBefore('ProcessPageAdd::processInput', function($event) { $form = $event->arguments('form'); $input = $this->input; $sanitizer = $this->sanitizer; $template = $sanitizer->int($input->post->template); if($template !== 43) return; // the ID of the template you want to limit page names for $name = $sanitizer->pageName($input->post->_pw_page_name); $parent_id = $sanitizer->int($input->post->parent_id); $uri = $_SERVER['REQUEST_URI']; $blacklist = ['cat', 'dog', 'hamster']; // your blacklist if(in_array($name, $blacklist) ) { $name_field = $form->children->get('_pw_page_name'); $error = "The page name '$name' is reserved. Please choose a different name."; $name_field->error($error); $this->session->redirect("{$uri}?parent_id=$parent_id"); } }); A little awkward but does the job. You could incorporate into a module to get a configurable template selection and name blacklist.
  6. You have more than the event->return available to you in the hook - you have $event->object, which is the inputfield. $this->addHookAfter('InputfieldFile::renderItem', function($event) { $inputfield = $event->object; $files = $inputfield->value; // find file you want in $files });
  7. How is that you have a path to a file (the $filename argument in your function) that exists in a field on a page without any information about the page and field? Where does $filename come from?
  8. @ethfun, if I understand right you would like to validate the page name during the Add Page process. This ought to be possible with a hook to ProcessPageAdd::processInput or InputfieldPageName::processInput, but stuffed if I can get PW to give a field error and return to Add Page; the error is displayed but the page is still added. I thought you could set an error to the inputfield... $my_field->error('That value is not allowed'); ...and the form wouldn't validate but I can't get that work for Add Page. Hopefully someone knows how to do this. BTW, members without a Form Builder license will not be able to read the thread you linked to with the background info. Might be good to include the details here.
  9. That's not the case - I always keep my PageTable items under the Admin branch of the tree and don't have any issues with non-superusers viewing and editing PageTable pages. You just need to make sure: The editor role has edit access (and of course view access) for the template used for the PageTable pages. The editor role has "Add children" access for the template used for the parent page of the PageTable pages. You set this in the "Access" tab of the settings for each template.
  10. The field may not be necessary but I think you'll have to associate the file with a Page (it is called a Pagefile after all). You can do this: $my_files = new Pagefiles($some_page); $my_files->add('/path/to/file.pdf');
  11. Well, it has me stumped. I haven't had or heard of this issue before. I doubt the GitHub issue szabesz linked to is related as that is specific to PageTables added to the user template.
  12. So if you go to those child pages in the tree (not via the PageTable field), can the editor edit those pages? Does the editor role have edit and view permission for the template used by the pages?
  13. Doesn't see them on the front-end or in the admin? Where in the tree are the PageTable pages stored? Are the PageTable pages viewable by editor if you load them directly on the frontend (i.e not via the PageTable field)?
  14. $my_files_field->add('/path/to/file.pdf'); Same for Pageimages, which inherits the methods and properties of Pagefiles. https://processwire.com/api/ref/pagefiles/ https://processwire.com/api/ref/pagefiles/add/
  15. The use cases are the same as those for any inputfield dependency: you want to show or require one field based on the state of another. This module just adds Image and File fields to the types of fields you can use in an inputfield dependency selector. Off the top of my head: you have an images field for an optional gallery and you want to remind the site editor to add a summary/introduction for the gallery if images are added. Also, there was this request for help. @szabesz is right - the screen recorder tool is LICEcap. I discovered it via this post by @bernhard.
  16. All your fields will be added directly to your template - Page fields and other fields. For the Page fields, it is the selectable options for the field that you will create as individual pages elsewhere in the tree. You could put these 'option' pages and their parents directly under the Home page, but I like to group them under a 'Selects' page to separate them from the rest of the site pages. Home Selects Make Toyota Volkswagen ... Color ... A couple of easy ways to create these pages: 1. Use adrian's great Page Field Select Creator module. This is good for when you want to include the ability to add pages (i.e. options for the select) via Pages > Add New because it will create dedicated templates for the option page and the parent page. The module creates the Page field for you. 2. When I don't need the use of the Add New feature and want to avoid unnecessary extra templates I use ImportPagesCSV with the "Paste in CSV Data" option. If all you need is the title then for example you would enter: title Toyota Volkswagen ... With this option you would create the Page field yourself and choose selectable pages, etc.
  17. @szabesz, glad you approve. I have plans for another module relating to inputfield dependencies. Watch this space.
  18. This is off-topic, but in case anyone else is bothered by the gap/collapse issue... After spending some time seeing if this could be resolved in the JS (conclusion: not easily) I found the simplest solution is to avoid the fractional pixels by setting the menu item padding in whole pixels rather than ems. I added this with AdminCustomFiles: .ui-menu .ui-menu-item a { padding:8px 11px; }
  19. It sounds a little unusual (typically you would use an analytics service to track this kind of stuff) but quite doable. You would do it all in your Search template - I don't think there is any issue regarding GET/POST. You sanitize and check the search terms from $input and if they meet your criteria then send the email and create the page. Then output the search results. It would slow down your search results a bit. If that is a problem you could look at using a queue but I don't know much about that.
  20. accidental double post
  21. @thomas, I created a module that allows image and file fields to be used in inputfield dependencies.
  22. Image & File Dependencies Allows Image and File fields to be used in inputfield dependency selectors. Note: prefix field names with an underscore in your dependency selectors. Usage Install the ImageFileDependencies module. You can now create an inputfield dependency based on the number of images or files added to a Image or File field. When you create an inputfield dependency for a Image or File field, prefix your field name with an underscore. Example for a field named 'images': _images>3 Note that you do not include a '.count' subfield in the selector. https://github.com/Toutouwai/ImageFileDependencies Demo
  23. Output buffering works great with delayed output. Set variable default in your auto-prepended init.php: $sidebar = $page->sidebar; Override in your template as needed: <?php ob_start(); // $sidebar ?> <div class="special-promo"> <h2>My special promo sidebar</h2> <?= $page->special_promo ?> </div> <?php $sidebar = ob_get_clean(); ?> Output in auto-appended main.php: <div class="sidebar"> <?= $sidebar ?> </div> I have never entirely understood the benefit of $files->render(), aka wireRenderFile(). Seems to be similar to an include, but with limited variable scope. Personally I'd rather use includes for shared partials so I can get and set any variable inside the partial without needing to explicitly pass variables back and forth from template to rendered file. I've never had to deal with so many variables that I'm losing track of their names and accidentally overwriting them or anything like that. It is possible to get all fields in a page and loop over them: foreach($page->fields as $field) { $field_content = $page->get($field->name); // output $field_content } But there are few situations where this would be useful, because usually you are using several different types of field on a page which return different types of data (string, WireArray, PageImage, etc) and need different markup output. So most of the time you want to get individual fields by name.
  24. This is working for me (PW 3.0.40)... /site/config.php $config->imageSizes = [ "foo" => ["width" => 200, "height" => 200], "bar" => ["width" => 400, "height" => 0], ]; /site/ready.php $this->addHookAfter('InputfieldFile::fileAdded', function($event) { $inputfield = $event->object; if($inputfield->name != 'images') return; // needs to match the name of your images field // alternatively, to use for all image fields... // if($inputfield->class != 'FieldtypeImage') return; $image = $event->argumentsByName("pagefile"); $sizes = isset($this->config->imageSizes) ? $this->config->imageSizes : []; if(count($sizes)) { foreach($sizes as $size) { $image->size($size["width"], $size["height"]); } } }); You won't see the variations immediately inside PageEdit, but you can see them after you save the page.
×
×
  • Create New...