Jump to content

Robin S

  • Content Count

  • Joined

  • Last visited

  • Days Won


Everything posted by Robin S

  1. You asked about this once before... 🙂 But "pages.id==1234" is a pretty naff syntax, so here's a hook that lets you match pages just by typing an ID into the admin search: $wire->addHookAfter('ProcessPageSearch::findReady', function(HookEvent $event) { $selector = $event->return; $q = $event->wire('input')->get('q'); // If the admin search query is a number if(is_numeric($q)) { // Get the individual pieces of the selector $selector_pieces = explode(', ', $selector); // Modify the first piece so that it includes an ID clause in an OR-group $selector_pieces[0] = "({$selector_pieces[0]}), (id=$q)"; // Replace the original selector $event->return = implode(', ', $selector_pieces); } });
  2. Third option creates a static file so it can be cached by the browser, but the first option could also create a static file if you are using ProCache. Probably not much impact no matter which option you use.
  3. I haven't used it, but maybe this section of the documentation is relevant: https://docs.mapbox.com/studio-manual/reference/styles/#typography
  4. For a gallery of images you wouldn't want to insert the images separately into the CKEditor field. You'd want to loop over all the images in the field and output markup for each of them. A typical approach would be to show thumbnail images linked to larger images that display in a JS lightbox (I like to use Fresco), so your template code might look like this (assumes your images field is named "images"): <?php if($page->images->count): ?> <div class="gallery"> <?php foreach($page->images as $image): ?> <a href="<?= $image->maxSize(1000,1000)->url ?>" class="fresco" data-fresco-caption="<?= $image->description ?>"> <img src="<?= $image->size(300,300)->url ?>" alt="<?= $image->description ?>"> </a> <?php endforeach; ?> </div> <?php endif; ?> So the simplest scenario is if your blog text and gallery are separate from each other - e.g. the gallery appears before or after the text. This way you just output the gallery and text separately in your template file. Chances are that's what you want to do, but here are a couple of other scenarios and possible solutions... 1. You want to optionally insert one gallery somewhere within the blog text. In other words, you want some text, followed by the gallery, followed by some more text. One way to do this would be to have two CKEditor fields in your template, labelled "Before gallery" and "After gallery". You divide your text between these two fields. The two CKEditor fields and the images field are all output directly by code in your template file. Another way is to have a single CKEditor field use the Hanna Code module to insert the gallery somewhere in the text. You would create a PHP Hanna tag named "gallery" and use the gallery code shown above for the tag. Then you'd insert [[gallery]] in your CKEditor field wherever you want the gallery to appear. 2. You want to insert multiple galleries somewhere within the blog text. If you stump up some $$ to buy the excellent ProFields module you could use the included Repeater Matrix module to create separate matrix types for Text and Gallery. Then you just add alternating Text and Gallery items to the page as needed to build up the blog post content. Another approach for this that is a bit more advanced but that doesn't cost anything is to use a standard Repeater field for the galleries. You would add an Images field and the Title field to the Repeater field and create a Repeater item for each gallery on the page. Then you'd use Hanna Code to insert the galleries within a single CKEditor field. And to make it easier to select a gallery in the Hanna tag you can use the Hanna Code Dialog module. The "gallery" Hanna tag would have a "title" attribute and the code would look like this: <?php $repeater_item = $page->galleries->findOne("title=$title"); ?> <?php if($repeater_item->id): ?> <div class="gallery"> <?php foreach($repeater_item->images as $image): ?> <a href="<?= $image->maxSize(1000,1000)->url ?>" class="fresco" data-fresco-caption="<?= $image->description ?>"> <img src="<?= $image->size(300,300)->url ?>" alt="<?= $image->description ?>"> </a> <?php endforeach; ?> </div> <?php endif; ?> And the Hanna Code Dialog hook in /site/ready.php to build the dialog form would look like this: $wire->addHookAfter('HannaCodeDialog::buildForm', function(HookEvent $event) { // The Hanna tag that is being opened in the dialog $tag_name = $event->arguments(0); // The page open in Page Edit /* @var Page $edited_page */ $edited_page = $event->arguments(1); // The form rendered in the dialog /* @var InputfieldForm $form */ $form = $event->return; if($tag_name === 'gallery') { $modules = $event->wire('modules'); $gallery_titles = $edited_page->galleries->explode('title'); /* @var InputfieldSelect $f */ $f = $modules->InputfieldSelect; $f->name = 'title'; $f->id = 'title'; $f->label = 'Gallery title'; $f->addOptions($gallery_titles, false); $form->add($f); } }); And this would give you an interface in Page Edit that looks like this (when the Hanna Code dialog is open):
  5. @psy, in theory you don't need any sort of special module to put runtime markup into a field. Instead just add a Markup field to the form and then hook before the form is rendered to put whatever markup you want into it. Having said that, there are some oddities with Markup fields in FormBuilder. I raised some questions that Ryan answered here: But I still had some other problems (I can't remember exactly what they were now) that I ended up resolving by making a clone of the core InputfieldMarkup module with some minor changes. I've attached the resulting InputfieldCustomMarkup module. If you install this module and enable it for use in FormBuilder then you can use it the same as a Markup field but without the snags. InputfieldCustomMarkup.zip
  6. Thanks, I should have tested that. Fixed now in v0.1.1 Good idea, I've added this in v0.1.1
  7. A new module that should suit your needs:
  8. Displays image tags overlaid on the thumbnail using customisable colours. This makes it easier to see which images have which tags without needing to open the edit pane for individual images or changing to the list view. Screenshot Usage Enable tags for one or more image fields. Install the Image Thumbnail Tags module. Optionally configure colours for any of your tags. https://github.com/Toutouwai/ImageThumbnailTags https://modules.processwire.com/modules/image-thumbnail-tags/
  9. I'm using the very latest v5d dev version, shared by Ryan here: https://processwire.com/talk/topic/21581-repeater-matrix-v5/?do=findComment&comment=199110 But Ryan addressed that version to you so maybe you are already using it? If you're not try updating to it because this topic makes me think there might have been a problem with CKEditor fields and Repeater Matrix: https://processwire.com/talk/topic/22029-ckeditor-field-context-per-matrix-type/
  10. @schwarzdesign, I can't reproduce that issue - the toolbar dropdown appears inside Repeater Matrix fields and nested Repeater Matrix fields. Double-check that you have included "HannaDropdown" in the toolbar settings for the CKEditor field.
  11. "editable_pages" is a Page Reference field that is created by this module. Go to that field's settings and on the "Details" tab there is a setting "Allow unpublished pages?" - tick that checkbox.
  12. You want browsers to reload the CSS any time that it changes, instead of going to the browser cache. Appending a query string to the CSS URL that changes every time the CSS changes is a reliable way to achieve this. You can see an example of this approach in the PW admin, where the file modified timestamp is used in the query string:
  13. I have my doubts about how effective that strategy will be, but you have a few options: 1. Create a PW template and page that outputs the CSS. Use a "text/css" content-type header, either using the "Content-Type" select on the Files tab of the template, or by using header(). header('content-type: text/css; charset: UTF-8'); Add this page to your markup in a <link> tag: <link rel="stylesheet" type="text/css" href="/path/to/page/"> 2. Similar to the above, but rather than create a template and page instead create a PHP file in the site root (PHP files are blocked inside /site/) that bootstraps ProcessWire. 3. Use $files->filePutContents() to actually write a CSS file that you load in your markup. In all of these cases you will probably want to use a cache-busting query string based on the time the CSS was last modified.
  14. A new module that hasn't had a lot of testing yet. Please do your own testing before deploying on any production website. Custom Paths Allows any page to have a custom path/URL. Note: Custom Paths is incompatible with the core LanguageSupportPageNames module. I have no experience working with LanguageSupportPageNames or multi-language sites in general so I'm not in a position to work out if a fix is possible. If anyone with multi-language experience can contribute a fix it would be much appreciated! Screenshot Usage The module creates a field named custom_path on install. Add the custom_path field to the template of any page you want to set a custom path for. Whatever path is entered into this field determines the path and URL of the page ($page->path and $page->url). Page numbers and URL segments are supported if these are enabled for the template, and previous custom paths are managed by PagePathHistory if that module is installed. The custom_path field appears on the Settings tab in Page Edit by default but there is an option in the module configuration to disable this if you want to position the field among the other template fields. If the custom_path field is populated for a page it should be a path that is relative to the site root and that starts with a forward slash. The module prevents the same custom path being set for more than one page. The custom_path value takes precedence over any ProcessWire path. You can even override the Home page by setting a custom path of "/" for a page. It is highly recommended to set access controls on the custom_path field so that only privileged roles can edit it: superuser-only is recommended. It is up to the user to set and maintain suitable custom paths for any pages where the module is in use. Make sure your custom paths are compatible with ProcessWire's $config and .htaccess settings, and if you are basing the custom path on the names of parent pages you will probably want to have a strategy for updating custom paths if parent pages are renamed or moved. Example hooks to Pages::saveReady You might want to use a Pages::saveReady hook to automatically set the custom path for some pages. Below are a couple of examples. 1. In this example the start of the custom path is fixed but the end of the path will update dynamically according to the name of the page: $pages->addHookAfter('saveReady', function(HookEvent $event) { $page = $event->arguments(0); if($page->template == 'my_template') { $page->custom_path = "/some-custom/path-segments/$page->name/"; } }); 2. The Custom Paths module adds a new Page::realPath method/property that can be used to get the "real" ProcessWire path to a page that might have a custom path set. In this example the custom path for news items is derived from the real ProcessWire path but a parent named "news-items" is removed: $pages->addHookAfter('saveReady', function(HookEvent $event) { $page = $event->arguments(0); if($page->template == 'news_item') { $page->custom_path = str_replace('/news-items/', '/', $page->realPath); } }); Caveats The custom paths will be used automatically for links created in CKEditor fields, but if you have the "link abstraction" option enabled for CKEditor fields (Details > Markup/HTML (Content Type) > HTML Options) then you will see notices from MarkupQA warning you that it is unable to resolve the links. Installation Install the Custom Paths module. Uninstallation The custom_path field is not automatically deleted when the module is uninstalled. You can delete it manually if the field is no longer needed. https://github.com/Toutouwai/CustomPaths https://modules.processwire.com/modules/custom-paths/
  15. Release date: 7 October 2016 https://processwire.com/blog/posts/processwire-3.0.36-and-looking-forward/ This warning started in PHP 7.2, release date: 30 November 2017 https://en.wikipedia.org/wiki/PHP#Release_history PHP is adding and deprecating features all the time. Not just a ProcessWire thing, but in general you don't want to run PHP software on a PHP version that didn't exist when that software was released.
  16. Yes, good tip - thanks. Also note that if unpublished pages are to be included then the Page Reference fields in question would need to be configured to allow them, because by default they are not.
  17. A couple of issues I can see there. You need to set the $event->return instead of returning a value. And if you are hooking before and replacing a method with your own code then you need $event->replace = true. See Ryan's example in the topic I linked to. But in your case a simpler approach could be this (note that this is hooking after because it is modifying the $event->return): $wire->addHookAfter('Page::path', function(HookEvent $event) { $page = $event->object; if($page->rootParent->template != '_site') return; $event->return = str_replace('/' . $page->rootParent->name, '', $event->return); });
  18. @jonatan, what you're describing doesn't relate to the Connect Page Fields module - this module doesn't get involved with whatever inputfield you have chosen to select pages with. Maybe take a look at the Inputfield Selectize module - it shows an example with thumbnails in the readme.
  19. You hook Page::path - see Ryan's case study example: You might be reinventing the wheel... https://processwire.com/docs/more/multi-site-support/ https://github.com/somatonic/Multisite/
  20. Sweet! How about integrating lite-vimeo-embed too? Then the module could be a drop-in replacement for TextformatterVideoEmbed. 🙂
  21. I actually ended up writing my own backup script because I wanted the backup to run by cron job at a fixed time rather than have the unpredictability inherent in LazyCron. But in terms of this module my vote would go for having CronjobDatabaseBackup identify the backups that it creates either by filename prefix or something distinctive in the Description as per @horst's suggestion. Then the backups can be safely stored in /site/assets/backups/database/ where they can be viewed and restored via ProcessDatabaseBackups and there is no requirement to use a "file protection string" to protect backups not created by CronjobDatabaseBackup.
  22. FYI, the core has built-in support for relative time strings: https://processwire.com/api/ref/wire-date-time/relative-time-str/
  23. Just what is shown in the Implementation field: echo $page->comments->renderAll(); I suggest testing a Comments field on a clean installation of PW so you can determine that it does indeed work and then you can focus in on what might be different on your other site.
  24. @kixe, I feel that the settings "Maximum number of backups" and "Remove backups older than" should only apply to backups created by CronjobDatabaseBackup. If the user has made manual backups, or backups have been made by a different module, then CronjobDatabaseBackup should never delete those backups. What do you think?
  25. I think custom database tables and SQL queries would be the way to go. This is a good read on working with hierarchies in MySQL: http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/
  • Create New...