Jump to content

Robin S

Members
  • Posts

    4,928
  • Joined

  • Days Won

    321

Everything posted by Robin S

  1. You can nest as many regions as you want, so long as they are all defined in _main.php. In other words, the only limitation is that you can't define new regions in a template file that is then included in another template file. So despite the first blog post on Markup Regions saying... ...Ryan later decided to remove this feature. If you are concerned about performance remember to use markup region hints to make the regions parsing more efficient.
  2. Are you using Option A? If so, switch to Option B, C or D and then you'll only get editable fields where you ask for them in your template file.
  3. That's a great tip, will do that myself in future. So often an otherwise nice typeface has a weird unrecognisable ampersand or something. Cases in point... http://www.myfonts.com/fonts/font-fabric/nexa/regular/glyphs/716952/445 http://www.myfonts.com/fonts/intelligent-foundry/averta/regular/glyphs/756381/1184
  4. Admin users: when migrating a live site to a new host, and you don't want users making changes to DB content during the migration. Front-end users: temporarily suspending member-only privileges for a user (e.g. because of some infraction).
  5. This is a question about using the system notices: $this->message(), $this->warning(), $this->error(). If I have a method that is is called by an AJAX request, I can't trigger a system notice immediately (would be great if this was possible). But is there some way to "queue" the notice so that it appears on the next admin page load? P.S. I know about the System Notifications module, but it's of no use if you need AJAX notices for a publicly shared module as there is no guarantee that the user will have System Notifications installed. Edit: found it... $session->message() $session->warning() $session->error()
  6. That did the trick. Another little thing I noticed is your font stack: font-family: "Hind Madurai", "woodford_bourne", sans-serif; You are specifying "Hind Madurai" from Google Fonts as the first preference, but this is not actually rendered anywhere (that I could see) and instead all the text renders in the first fallback "woodford_bourne" which you are self-hosting. So maybe "woodford_bourne" is actually the typeface you actually intend to use and specifying/loading "Hind Madurai" is unnecessary?
  7. I agree it would be handy, but that would be a completely different thing to what this module is doing. This module is essentially just using Pageimages::add() on the submitted URLs, and that method has no support for clipboard data. I don't think I want to disappear into the browser clipboard rabbit-hole with this module. I'll have a think about it. It would make the module significantly more complex and I'm not sure how much time I want to put into it. Maybe if I get bored sometime...
  8. Very nice! One issue I noticed is that if you scroll down one increment of the mousewheel, as well as triggering the animated scroll past the hero section the text below is also scrolled, meaning the first couple of lines are already obscured behind the header. How many text lines are scrolled perhaps depends on the OS mouse settings. Maybe you could somehow capture the first mouse scroll interaction so that it only triggers the hero scroll and not scroll the rest of the page content?
  9. I would do the validation a little differently, to avoid loading any more pages than you need to: // if there is a URL segment 1 if($segment1) { // get catType page $catType = $pages->findOne("parent=/type/, name=$segment1"); // if catType page exists if($catType->id) { // add this to the selector $selector .= ", catType=$catType"; } else { // invalid URL segment 1 throw new Wire404Exception(); } } Not sure in what way you were considering using has(), but that method is for checking against a PageArray/WireArray that is already loaded to memory - better to load just the page (category) you want than to load many just to filter it down again.
  10. Could you give some more info about the OS and device where the problem occurs? I tested in iOS and Android and could select, copy and paste okay (a bit awkward as expected, but doable). Technique was the same on both platforms: double-tap on some text in the CKEditor window to start the selection, then drag the selection handles around the content you want to select.
  11. I opened a new GitHub issue for this: https://github.com/processwire/processwire-issues/issues/454
  12. Hi @tpr, AOS seems to be suppressing the "required" icon in the template editor. Without AOS: With AOS:
  13. Cool, thanks for this! A couple of little issues I noticed after a quick try-out: 1. You have undefined variables $buttontext and $href in addAjaxSaveButton(). 2. It would be good to set a default value for the button text, both in the module config inputfield and in a construct() method, in case a user does not save the module config after installation or a user saves the config inputfield in an empty state. Other thoughts: 1. I see the module submits the form to a separate Process module. Seems like it should be possible to instead do an AJAX submission to the "action" url of the form in ProcessPageEdit, but maybe there is a good reason not to do it this way. 2. It would be cool if the module could handle/show errors in the submission - e.g. empty required fields or other inputfield errors.
  14. You can turn Repeater into a kind of poor man's Repeater Matrix by adding all the fields you need to the Repeater, then adding a Page Reference field at the top to select the type of item. Use inputfield dependencies to show/hide inputfields according to what type is selected.
  15. Repeaters can scale up much better in recent versions of PW, so long as you set your repeater items to collapsed by default and use the AJAX-loading option. I suggest creating a page structure where you have a dedicated parent and template for each of Movies, Television and Theatre and all of the items for each category go under these parents. Movies Apocalypse Now Magnolia ... Television Six Feet Under Twin Peaks ... Theatre Waiting for Godot Uncle Vanya ... Then you create a Page Reference field "Roles" using the Page Autocomplete inputfield and add it to your actor template. You can easily divide the roles by category when you output the roles in your template file. You might like to try the Connect Page Fields module too - I even used the example of actors in the readme. For the awards field, I think I would stick to a repeater. Each repeater could consist of just a text field for entering the award name, or if there are certain awards that are given out each year you could use a Page Reference field to select the award and an integer field to enter the year.
  16. Best not to give users access to fields that they are not trusted to manage. So if only certain roles should be allowed to edit a field (for a files field editing means adding or deleting files) then set up access permissions for that field. I'm not sure it makes sense to allow users to upload files to a field but not delete them. Otherwise how do they correct their own mistakes if they accidentally upload a file to the wrong field or on the wrong page? But if you're sure you want to do this you could use the following hook in /site/ready.php: $wire->addHookBefore('Pagefiles::delete', function(HookEvent $event) { // The item about to be deleted $item = $event->arguments(0); // Only for ProcessPageEdit if($this->process != 'ProcessPageEdit') return; $page = $this->process->getPage(); $field = $item->pagefiles->field; // Now optionally use $page and $field to limit the below to particular pages, templates, fields if($this->user->hasRole('YOUR_ROLE')) { // Prevent the normal delete() method $event->replace = true; // Show the user an error message $this->error('Sorry, you are not allowed to delete files.'); } }); I don't recommend it because it will be slow and potentially result in a lot of sent mail, but the following example is a proof-of-concept for sending an email notification of deleted files. $wire->addHookBefore('Pagefiles::delete', function(HookEvent $event) { // The item about to be deleted $item = $event->arguments(0); // Only for ProcessPageEdit if($this->process != 'ProcessPageEdit') return; $page = $this->process->getPage(); $field = $item->pagefiles->field; // Now optionally use $page and $field to limit the below to particular pages, templates, fields if($this->user->hasRole('YOUR_ROLE')) { // Send email notification $m = $this->mail->new(); $m->to('someone@domain.com') ->from('someone@domain.com') ->subject('File deleted') ->body("File '{$item->basename}' was deleted by '{$this->user->name}' from field '{$field->name}' on page {$page->httpUrl}.") ->send(); } });
  17. Thanks, I discovered this myself while I was experimenting yesterday, but it seems less than ideal for a couple of reasons. 1. When you do this, it seems that the image is first downloaded to your local disk, then uploaded to the site. This makes it unnecessarily slow for larger images or on slow connections. 2. The filename of the image is not preserved as per the original. On Windows Chrome at least, every filename gets "_1" appended to it. But on the positive side this approach does allow for client-side resizing. I had a go at a module that allows images to be added to a field via pasted URLs: I had a few concerns about the approach because the page and image field are identified by values that could potentially be manipulated client-side. But I've included some checks that hopefully mitigate this. Another niggle is that the API method $page->images_field->add() is surprisingly relaxed about what it will add to an images field. It doesn't seem to do any validation against the field settings or even disallow non-images from being added to an images field. So all the validation must be done independently (@Macrura, this might be something that affects your module too). I think I've accounted for most things, but if you guys will take a look and let me know if you spot any potential issues that would be great. Because the browser is not involved in the upload, no client-side resizing is possible but is done server-side instead (for max width/height settings).
  18. Add Image URLs A module for ProcessWire CMS/CMF. Allows images/files to be added to Image/File fields by pasting URLs or using the API. Installation Install the Add Image URLs module. Configuration You can add MIME type > file extension mappings in the module config. These mappings are used when validating URLs to files that do not have file extensions. Usage A "Paste URLs" button will be added to all Image and File fields. Use the button to show a textarea where URLs may be pasted, one per line. Images/files are added when the page is saved. A Pagefiles::addFromUrl method is also added to the API to achieve the same result. The argument of this method is expected to be either: a URL: "https://domain.com/image.jpg" an array of URLs: ["https://domain.com/image1.jpg", "https://domain.com/image2.jpg"] Example: // Get unformatted value of File/Image field to be sure that it's an instance of Pagefiles $page->getUnformatted('file_field')->addFromUrl("https://domain.com/path-to-file.ext"); // No need to call $page->save() as it's already done in the method Should you have an issue using the method, please have a look at the "errors" log to check if something was wrong with your URL(s). WebP conversion The core InputfieldImage does not support images in WebP format. But if you have the WebP To Jpg module installed (v0.2.0 or newer) then any WebP images you add via Add Image URLs will be automatically converted to JPG format. https://github.com/Toutouwai/AddImageUrls https://modules.processwire.com/modules/add-image-urls/
  19. You would think this would work, but if you test it I think you'll find that individual keys set like this have no effect. However, Ryan recently alerted me to this working alternative for setting individual keys: $config->imageSizerOptions('cropping', 'north');
  20. That would be fine, but how do you add an image to an image field via a URL? I feel like I've read something here in the forums about doing this but looking at the image field interface I can't see how it's possible. There is only the "Choose file" button for uploading an image and the drag-and-drop zone.
  21. Does anyone have any tips to share for moving an image from one image field to another on the same page in Page Edit? I know it can be done with the API but it seems like there should be some way via the admin interface. Like adding an image to an image field by pasting a URL - is that possible via the core or a module?
  22. One button in the footer is expected - you are appending the rendered button to the Lister output after all. So there is just a single unexpected button being added. I think this is because your execute() method is called twice, once when the page is first rendered and once in an AJAX request from Lister. So you can make the rendering of the button conditional on it not being an AJAX request. $pl = $this->modules->get("ProcessPageLister"); $out = $pl->execute(); if(!$this->config->ajax) $out .= $btnAddNew->render(); return $out;
  23. For a repeater field named "image_tags" in the "home" template, setting the tags list for an images field named "images"... // Save repeater titles to images tags list $pages->addHookAfter('saveReady', function(HookEvent $event) { $page = $event->arguments(0); // For the home template if($page->template == 'home') { // Get a string of tags from the repeater item titles $tags = $page->image_tags->implode(' ', 'title'); // Get the images field $images_field = $this->fields->images; // Set the list of allowed tags $images_field->tagsList = $tags; // Save the field $images_field->save(); } }); The titles of the repeater items will need to abide by the rules for image tags, so no spaces allowed.
  24. Welcome to the forums @adiemus The description field is named "description" and you can include it as a subfield of an images field in your selector. So for a repeater field named "repeater" containing an images field named "images" your selector would be something like: $matches = $pages->find("repeater.images.description~=foo");
  25. @drjones, you could add a "sort_name" field (hidden perhaps) to your template to store the number with leading zeros added. You would populate this field in a hook to Pages::added in /site/ready.php $pages->addHookAfter('added', function(HookEvent $event) { $page = $event->arguments(0); if($page->template == 'stick') { $page->setAndSave('sort_name', str_pad($page->name, 8, '0', STR_PAD_LEFT)); } }); Then you would use the sort settings of the parent page to sort its children by sort_name.
×
×
  • Create New...