Leaderboard
Popular Content
Showing content with the highest reputation on 02/24/2021 in all areas
-
Did a little tinkering since I'm going to need another API endpoint for a new project soon and came up with this PoC: https://github.com/BitPoet/WireApi-PoC It's very crude and all as its just meant as a playground for ideas for now (wouldn't dare to clutter up the Wire namespace), and it does still use pages behind the scene (though not the implicit 404 redirect). Perhaps hiding the endpoints from the tree for everybody but superusers might be an option, but I haven't fully thought that out. Here are a few very simple examples of an API template (in fact, very close to what I thought up above): <?php namespace ProcessWire; $api->routeGET('/api/hello/{name}/', null, 'helloWorldApi', true); $api->routeGET('/api/pagelist/', 'apitemplates/pagelist') ->roles('superuser') ->setDebug(true) ; $api->route(['GET'], '/api/custom/{value}/', function($url, $values) { wire('api')->jsonResponse([ 'success' => true, 'youare' => wire('user')->name, 'data' => $values ]); })->check(function($url, $route, $check, $values) { return ctype_digit($values['value']); }); $api->handleRequest(['debug' => true]); // ________________Only function declarations below_____________________ function helloWorldApi($url, $values) { wire('api')->jsonResponse(['Hello', $values['name']]); } Oh, and it ships with a near-one-click endpoint installer ? Let me know what you think, and if you have any ideas about improvements or doing things differently, bring it on.2 points
-
There's a really useful page https://stackoverflow.com/tags/timezone/info - though it'll make you realise you're opening something of a can of worms! I think, but I'm definitely not sure, that PHP uses the IANA/Olson Time Zone Database (linked on the above page). However, even if it does, I don't know how up to date PHPs list of time zones is. The Geolite2 database from MaxMind, at https://dev.maxmind.com/geoip/geoip2/geolite2/, is free and gives IANA time zone codes. This is another option: https://www.ip2location.com/free/olson-timezone. And there may well be quite a few other such sources out there. I don't know of any ready-made tool, but that doesn't mean there isn't one!1 point
-
1 point
-
Yes, that's correct. The default value is only used for the interface, it's not applied to any existing pages. You can fix that in two ways: 1. Anywhere you use the value in your code, assume the default if no value is set. Something like this: // default to behavior option one $behaviorField = $fields->get('speciality_text_behavior'); $textBehavior = $page->speciality_text_behavior->id ?: $behaviorField->type->getOptions($behaviorField)->get('id=1')->id; You could also put that in a hook to get that behaviour anywhere you use this field. 2. Write a script to manually change the value of all pages with an empty value in that field to your new default: $valueMissing = $pages->find('speciality_text_behavior=""'); foreach ($valueMissing as $p) { $p->of(false); $p->speciality_text_behavior = 1; $p->save(); } You can quickly execute that snippet in the Tracy Debugger console module. BTW am I the only one who's annoyed by the field name? "speciality" in British English but "behavior" in American English, who does that ?1 point
-
To me it looks like https://www.timeanddate.com/time/map/ is doing what you're after. You can search by name and then you have the timezone of the city you've entered inside the "Timezone" tab.1 point
-
@ryan - what do you think about having a referencesRaw() page method. If you're outputting a long list of pages referenced to another page, often all you need are the title and url field values. As an example, I am outputting a list of publications for a staff member. I believe this would really speed things up. Thanks for considering.1 point
-
@ryan I'm trying out the new join feature within a regular page selector. I believe you mentioned that it is possible to join subfields of page fields. I'm wondering if you can explain that in a bit more detail. Does this still all happen within a single SQL query? If I want to join the id and the title of a page in a page reference field, which of the following is the proper way to do this? $pages->find("template=foo, join=pageField|pageField.title"); $pages->find("template=foo, join=pageField.title"); // Can I join pageField.title without also joining the pageField? If so, would I still have access to the page id? $pages->find("template=foo, join=pageField.id|pageField.title") // Is joining pageField.id the same thing as joining pageField? I could answer these questions for myself if I knew of a good way of checking which data has already been loaded in the resulting page. What is the best way to double check what field data is already loaded on the page objects after performing a find (in order to make sure the join worked properly)? Edit: I just realized I wasn't thinking clearly when I wrote this. Being able to join subfields of page reference fields would require loading those pages as their own separate page objects, which would always include the page ID, name, modified, and created dates. I am still wondering whether doing either join=pageField or join=pageField.title would actually cause those pages to be preloaded as part of the find, or whether it would only lazy load them when first requested, per the normal PW behavior.1 point
-
@benbyf Did this project ever go ahead? I'd be happy to pay the usual $140-150 dev licence fee for such a module. ProcessWire seriously lacking any kind of membership solution.1 point
-
@BillH Man, you saved my live. I had a nightmare last night, seeing myself migrating dozens of entries manually but your code came to the rescue. It works! Here is my code: page()->of(false); foreach (page()->images as $image) { $image->artist_name = $page->title; if($image->description): $image->title = $image->description; $image->image_caption = $image->description; endif; // first save inside loop saves the field value $page->save('images'); } // saves the page $page->save(); Yesterday I had the output formatting statement inside the loop and I assume this was the mistake. Thanks for helping me!1 point
-
Thanks for the report @adrian. The newly released v0.3.6 adds support for ProcessProfile and ProcessUser, and also adds a config field to show the Tracy debug bar in the dialog which can be helpful for debugging if you are building the dialog form with a hook.1 point
-
@Robin S - I have been using this module since it was released and always thought it was a necessary tool for inserting Hanna codes, but I just starting using some of its other features like: linked_page__pagelistselect which makes it an entirely new beast - amazing. Thanks!1 point
-
Following the above discussion, I decided that it made more sense to display the title rather than the path (since it is only for display purposes). I also wanted a solution for attribute types pagelistselectmultiple, not just pagelistselect. In case it is useful to anyone else, my suggested js is: $(document).ready(function() { /* Author: Mark Evens, based on an original script by Robin Sallis */ /* This version displays the title text rather than the path name */ /* It also works for pagelistselectmultiple as well as pagelistselect */ /* Hide the text field */ /* id_title is the name of a text attribute in the hanna code*/ /* change id_title throughout the code below to match your attribute name */ $('#wrap_id_title').addClass('hide-field'); // Must use mousedown instead of click event due to frustrating event propagation issues across PW core // https://github.com/processwire/processwire-issues/issues/1028 // .PageListActionSelect is the button 'Select' with appears when a page is clicked (no normally visible - loaded by js) $(document).on('mousedown', '.PageListActionSelect a', function (event) { var id_title; // Adapt unselect label to suit your language if ($(this).text() === 'Unselect') { id_title = ''; } else { id_title = ($(this).closest('.PageListItem').children('.PageListPage').text()); // replace .text() by .attr('title') for path name } $('#id_title').val(id_title); }); // For pagelistselectmultiple, get all the selected pages when the selection is updated // This returns the contents of the label displayed in the pagelist item. This can be set in your HannaCodeDialog::buildForm hook // The default is the page title. For the path name, set $f->labelFieldName = 'path'; in your hook $(document).on('change', '.InputfieldPageListSelectMultiple', function(event) { var id_title = []; $(this).find('.InputfieldContent ol li:not(.itemTemplate)').each(function(){ id_title.push($(this).children('span.itemLabel').text()) }) $('#id_title').val(id_title); }); }); To hide the id_title attribute in the dialog, you need to add the following css: #hanna-form .hide-field { display: none !important; }1 point
-
The core Page Reference inputfields output only a page ID and expect a page ID as input. Possibly you could create your own custom inputfield module that works with a page path instead of an ID. Or here's a hacky solution that involves adding an extra "path" attribute to your Hanna tag... Hook: $wire->addHookAfter('HannaCodeDialog::buildForm', function(HookEvent $event) { // The Hanna tag that is being opened in the dialog $tag_name = $event->arguments(0); // The form rendered in the dialog /* @var InputfieldForm $form */ $form = $event->return; $config = $event->wire()->config; $modules = $event->wire()->modules; if($tag_name === 'select_page') { /* @var InputfieldPageListSelect $f */ $f = $modules->InputfieldPageListSelect; $f->name = 'selected_page'; $f->id = 'selected_page'; $f->label = 'Selected page'; $f->parent_id = 1268; $form->add($f); // Add JS file to Hanna Code Dialog form $js_file = $config->paths->templates . 'hannas/select_page.js'; if(is_file($js_file)) { $js_url = $config->urls->templates . 'hannas/select_page.js?v=' . filemtime($js_file); $form->appendMarkup = "<script src='$js_url'></script>"; } } }); select_page.js $(document).ready(function() { // Must use mousedown instead of click event due to frustrating event propagation issues across PW core // https://github.com/processwire/processwire-issues/issues/1028 $(document).on('mousedown', '.PageListActionSelect a', function(event) { var path; // Adapt unselect label to suit your language if($(this).text() === 'Unselect') { path = ''; } else { path = $(this).closest('.PageListItem').children('.PageListPage').attr('title'); } // Adapt path field ID to suit $('#path').val(path); }); });1 point
-
I can see why that isn't optimal and I agree that it would be good to be able to selectively disable particular textformatters when outputting. The Hanna Code Dialog module depends on Hanna Code and isn't intended to be used independently of it. The way you're using it is unusual so although I don't want to make changes to the module that I think could compromise the experience for typical users you could use a custom hook/module that would load the Hanna Code Dialog CKE plugins to suit your circumstances. So you'd create your own custom version of HannaCodeDialog::afterCkeRenderReady(). $wire->addHookAfter('InputfieldCKEditor::renderReadyHook', function (HookEvent $event) { $inputfield = $event->object; $field = $inputfield->hasField; // For your field name(s)... if(!$field || $field->name !== 'body') return; $config_name = "InputfieldCKEditor_{$field->name}"; $config_name_matrix = "InputfieldCKEditor_{$field->name}_matrix"; $config = $this->wire('config'); $js_config = $config->js(); foreach($js_config as $key => $value) { if($key === $config_name || strpos($key, $config_name_matrix) === 0) { $js_config[$key]['extraPlugins'] .= ',hannadropdown,hannadialog'; $config->js($key, $js_config[$key]); } } });1 point
-
1 point
-
Thanks, but I already looked at this one and it doesn't give the timezone in the PHP name format I linked to in my post. It gives a timezone like "PST" when I need "America/Los_Angeles".0 points