Leaderboard
Popular Content
Showing content with the highest reputation on 01/27/2017 in all areas
-
Consistent with the plans of introducing new site profiles this year, we’ve started work on the new site profile, and have the first version ready this week. This profile contains a blog component and uses the new Uikit 3 front-end framework: https://processwire.com/blog/posts/introducing-a-new-processwire-site-profile/9 points
-
Here is a tipp for you if you want to check for validation errors in inputfields before processing php code inside a Hook function. My goal was to run the code inside the Hook function only if there are no errors after processing the form in the backend. $pages->addHookBefore('saveReady', function($event) { $page = $event->arguments[0]; //count errors during input process $errors = $page->errors('all'); $errors = count($errors); if ($errors == 0) { ......//run your code } }); In this case I run a Hook before "saveReady" inside my ready.php. But I only want to run my php.code inside this Hook function if there are no errors in the form submission. So I need to check for errors in the form submission first. These 3 simple lines of code are necessary: $page = $event->arguments[0]; //count errors during input process $errors = $page->errors('all'); $errors = count($errors); The first step is to define the page variable $page; Second step is to get the error array Last step is to count the entries in the array to get the number of the errors Thats all! Afterwards you can use the number of errors in an if-statement to run the code only if there are no errors. Hope this will be helpful for someone.4 points
-
4 points
-
Typically the way to do this is define $i=0; before the foreach loop and then at the end (just inside) do: $i++ This lets you check which iteration of the loop you are at, so if $i==0 then "continue;" Hope that helps - it's not a full code example, but hopefully it will help you to understand what is required.2 points
-
Just like $pages->get, $users->get returns a NullPage object if no match was found. Thus, you can check for that. I feel that doing it this way is better for readability (implicitly illustrating the difference between a new User object with no id and the result of a get call with no match), but that may just be a personal preference. $item = $users->get("email=example@processwire.com"); if($item instanceof NullPage) { // Not found } else { // Do something }2 points
-
Cool. Did my code work though? Probably the titles won't be changing, but if they will, it is more reliable to check by $page.2 points
-
$Item will return an Object whether or not a user was found, hence case 1 will always be true. So, yes, you need to check differently. I like to check for both the object and an ID. Sometimes if you check only ID you might get a PHP error about a 'call to member function on a non-object' blah blah..: $item = $users->get("email=example@processwire.com"); if($item && $item->id) echo $item->name; else echo 'No user found';2 points
-
I tried this module today to output a video preview from a multilanguage field. Worked like a charm. See the screenshot. I created two fields, one for the default language (English) and one for Portuguese. Here's the code for both, if someone's interested: English field: return '<iframe src="https://www.youtube.com/embed/'.$page->youtube_id.'/?showinfo=0&iv_load_policy=3&controls=1" frameborder="0" allowfullscreen width="100%"></iframe>'; Portuguese field: //1021 is the 'portuguese' language page id $youtube_id = $page->youtube_id->getLanguageValue(1021); return '<iframe src="https://www.youtube.com/embed/'.$youtube_id.'/?showinfo=0&iv_load_policy=3&controls=1" frameborder="0" allowfullscreen width="100%"></iframe>'; Thanks @kongondo for this great module!2 points
-
FieldtypeFileS3 https://github.com/f-b-g-m/FieldtypeFileS3 The module extends the default FieldtypeFile and InputfieldFile modules and adds few extra methods. For the most part it behaves just like the default files modules, the biggest difference is how you get the file's url. Instead of using $page->fieldname->eq(0)->url you use $page->fieldname->eq(0)->s3url(). Files are not stored locally, they are deleted when the page is saved, if page saving is ommited the file remains on the local server until the page is saved. Another difference is the file size, the default module get the file size directly from the local file, while here it's stored in the database. There is an option to store the files locally, its intented in case one wants to stop using S3 and change back to local storage. What it does is it changes the s3url() method to serve files from local server instead of S3, disables uploading to S3 and disables local file deletion on page save. It does not tranfer files from S3 to local server, that can be done with the aws-cli's through the sync function. Files stored on S3 have the same structure as they would have on the local server. -------------------------------------------------------- -------------------------------------------------------- Been struggling with this for quite a while, but i think i finally managed to make it work/behave the way i wanted. All feedback is welcome!1 point
-
1 point
-
Hi, I think this is not that difficult, you work already with an id which you can use now: You could add a if statement for the very first id in your foreach loop: $id = 0; // set it to zero foreach ($sections as $item) { if ($id == 0) continue else { echo "<li><a href='#section-$id'>$item->title</a></li>"; } $id ++; } NOTE: Haven't tested this As you want to skip the first element, which id is equal to 0, the first rendered <li> will have id 1, so if you add another if statement in your foreach loop for id ==1 you can filter that item out and the rest gets the normal tags. See code below: $id = 0; // set it to zero foreach ($sections as $item) { if ($id == 0) continue else { if ($id == 1){ echo "<li class='yourclassforfirstitem'><a href='#section-$id'>$item->title</a></li>"; } echo "<li><a href='#section-$id'>$item->title</a></li>"; } $id ++; } Haven't tested it so far, but I expect this works (maybe with some adjustments)1 point
-
Not directly, but it pointed me in the right direction. I had some confusing errors - my mistake - on choosing wrong type of select box/drop down on field. Couldn't figure out why the filtering wouldn't work. Eventually went to database and saw dupe records, so then checked and changed Drop downs from multi to single. Only been working on ProcessWire for a week, so very new to it. One thing, when I went to the DB to see what was being saved, I couldn't believe how lean the data model is. Ryan or whoever has really done a brilliant job here. It will be interesting to see how my coming months go as I will be 100% on Processwire, looking forward to the ride1 point
-
What @szabesz said. Best to PM Ryan to tell him you are interested in contributing.1 point
-
New version is launched! I've added some new features/options - Earlier I've launched a version with a new option to import the reference codes of your products and the EAN-numbers too - Added a link to module info which links to this module in the module section of processwire. - If you used this module before and only want to update your data, you don't need to first import your categories, then products etc. You can directly click on the import button you want to use. - Revised this module to make translations available. Also made a dutch translation for this module. Download the .zip file (attached to this post or get it via my github) and add it to your dutch language site translations file. Enjoy the new features! NL-Translations.zip1 point
-
I think you are right @adrian. I quickly read this and for some reason thought they'd already seen the CMS Critic case study and that didn't suit their needs. I raise that since the same technique is used there. I think stuff like this could make nice short tuts, somewhere outside the forums. There's some nice gems buried deep in the forums.1 point
-
Probably not yet. Ryan has been working on the new frontend site profile(s) this week, see: https://processwire.com/blog/posts/processwire-3.0.50-core-updates/#Comment12974 Anyway, you might want to ask him1 point
-
If it's not grabbing it and the fact that we know there is a value sent, it means it is not the correct implementation. In other words, that is not how you grab it . The session is only temporary (it is deleted immediately after) since you need to be able to store the value of the first date somewhere in order to do the comparison. Below is a different approach. We directly check the values in the $input->post. Seems a bit hackish (?) but it works. Here, we make sure 'erroneous' values are not saved. We revert to older values in the database or blanks if there were no saved dates and show a field error on the first date input. Also note that if no first date is input, the field error will be displayed. You can play around with the if() logic to change the behaviour. public function init() { $this->pages->addHookAfter("InputfieldDatetime::processInput", $this, "hookAfter"); } public function hookAfter(HookEvent $event) { $post = $this->wire('input')->post; // change date string to timestamp $firstdate = strtotime($post->date); $lastdate = strtotime($post->date2); // if first date greater than or equal to last date if($firstdate >= $lastdate) { $field = $event->object; if($field->name == 'date' || $field->name == 'date2') { // get the page being edited $page = $this->wire('modules')->ProcessPageEdit->getPage(); // ensure we don't save 'erroneous' dates; we revert to older saved (db) dates or blank $oldDate = $page->get($field->name); $field->value = $oldDate; // only show error on first date field if($field->name == 'date') $field->error("Last date must be greater than the first date"); } } }1 point
-
I think kongondo might be referring to the upgrade() method. From the docs: So in your module upgrade method you can do something like: // Upgrade from < v0.0.5 if($fromVersion < 5) { // do something }1 point
-
If you're moving to HTTPS, please note that Google considers your HTTPS and HTTP sites as 2 different sites. Get all your Search Console verifications set up for www, non www, https, http etc etc and monitor closely. Lots of great articles out there on making the switch without killing your rankings.1 point
-
...for such things there is no need for a whole fieldtype since you can make it in plain PHP. Usecase that i have was to depublish entries after a fix timeperiod that a user could set to his entry (1 week, 3 weeks and so on) Just as an very simple example from a .php file for a cronjob: //get all items to check foreach ($items as $e) { /// FIRST STEP - send mail 1 week before the entry is being unpublished! //set the calculate_type to the e_delay option value from the entry option field... $calculate_type = $e->e_delay; //calculate the to add time to the timestamp switch ($calculate_type) { case '1': $time_add = ' +3 week'; break; case "2": $time_add = ' +7 week'; break; case '3': $time_add = ' +11 week'; break; default: $time_add = '1'; } //timestamp to check is the modified date + $time_add $check_time = strtotime($time_add, $e->modified); //check if the current timestamp is greater than the $check_time == 1 week before e_delay is reached! if ($check_time >= $curtime) { //do something } else { //do something else } } the time peroids that you need could be a simple option field or a pagefield or even an integer field. Best regards mr-fan1 point
-
Could you explain a use case for this? Other than that, not sure if you know that there's a module that can auto-publish/unpublish at specified dates. There's also a published date property for pages. I don't know if those cover your needs, but good to know.1 point
-
I don't know how your menu dropdown logic works but you have 'has_children_class' => 'dropdown', That adds to the <li classs="..."> and you have 'inner_tpl' => '<ul class="dropdown">||</ul>',1 point
-
If you haven't seen it already, check out the new Captain Hook panel in Tracy Debugger. If you have the Editor Protocol Handler configured you can jump straight to the hookable method in your code editor. Because the line links are generated from whatever PW version you are running it will always be correct. Pretty cool. Plus it includes the hookable methods in module classes!1 point
-
Welcome to the forums @TJB. You seem to have made that page's template a system template. You cannot delete system resources like that. You would need to do it using the API. An example here:1 point
-
This isn't actually an installable profile though - you can explore the template files but without the database from the demo site it's not as useful as it could be. @ryan, could you please make an exported profile of the demo available?1 point
-
Hello all ! Just because I'm proud to be featured by Snipcart (js ecommerce solution) about my integration on my Processwire based website ! This post talks about Processwire and how I've done it : https://snipcart.com/blog/case-study-ateliers-fromagers-processwire If you wanna take a look at my website : https://www.ateliersfromagers.com/ (french & english) Have a good day everyone ! S1 point
-
Happy New Year to everyone! For a project that I'm working on, I needed to have dependent checkboxes on page edit forms in the admin. Just like dependent selects but for checkboxes. I couln't find anything and decided to write my first Inputfield module. I have only tried it on PW > 3.0. But it should also work on the 2.x branch. Would be great if some of you could try it out and give some feedback. You can find the module InputfieldDependentCheckboxes at github Here's some screenshots of the module in action and instructions on how to use it. ##An Inputfield for ProcessWire admin interface that handles the display of dependent checkboxes in page fields Sometimes we need checkboxes to depend on other checkboxes in our page edit forms. This module adds this functionality to standard page field checkboxes for 2 or more checkbox fields. ## Installation 1. Copy all of the files for this module into /site/modules/InputfieldDependentCheckboxes/ 2. In your admin, go to the Modules screen and click "Refresh". Under the 'Inputfield' section, install the 'InputfieldDependentCheckboxes' module. 3. Open Modules->Configure->InputfieldPage. Under 'Inputfield modules available for page selection' add 'DependentCheckboxes' from the select dropdown and submit ##Field Setup This inputfield extends the standard checkboxes for page fields. Therefore you need to have page fields configured already that you can extend with this Inputfield type. ###Prerequisites You need to have at least 2 fields of type page that have 'Checkboxes' defined as Input field type and live on the same template. A real world example: There are different types of instructors. Each instructor type can have multiple different certifications. For this to happen, we need 2 page fields (multiple): A) instructor_types: lists pages with template 'instructor_type' B) certifications: lists pages with template 'certification' The certification template needs to have the instructor_types page field to assign one or more instructor_types to a certification. ###Setup (link checkbox fields) 1. Edit your page field A and go to the 'Input' Tab. Under 'Input field type' choose 'DependentCheckboxes'. Hit save. Now under 'Choose the target checkboxes field' choose the name of your field B. Hit save again. 2. In your page field b make sure to choose a template under 'Input' Tab under 'Selectable Pages'->'Template of selectable page(s)'. Your fields should be setup. If you now edit a page that contains the 2 fields, the dependent checkboxes should be working. EDIT: And yes, this is working for multiple dependent checkboxes, too. (I have tried it with 3 so far) Some notes on how the module works behind the scenes: - parent checkboxes (actors) that have dependent checkboxes (targets) get custom data attributes applied which contain arrays of the targets' IDs - some Javascript is initiated on acxtors and targets to handle the display based on the id arrays in the data attributes. EDIT: since this module's mention in ProcessWire Weekly it might get some more attention. I just wanted to point out that it is still in alpha state. I will continue development and more thorough testing while implementing it in an ongoing project within the next 3-5 months or so. I will eventually release a stable version then. If you use the module with only 2 dependent checkbox fields, it should work smoothly. There are still some quirks when using 3 or more and I need to figure out how to best resolve them. So please be patient (or jump in with ideas ).1 point
-
@adrian Thanks for your help! You were right about the creatPath method, I was able to solve my problem Thanks ryan. I solved it by making wireMkdir recursive with the additional argument. In the PagefilesManager class I did the following updates: // Change _createPath() to support recursive directories protected function _createPath($path) { if(is_dir($path)) return true; return wireMkdir($path, true); } // Add new method static public function makeCustomPath(Page $page) { // Examples: ID=1780, path = /site/assets/files/17/80/ // ID=19814, path = /site/assets/files/19/81/4/ // ID=205478, path = /site/assets/files/20/54/78/ $tmpPath = ''; $digits = str_split("{$page->id}"); foreach ($digits as $k => $digit) { $tmpPath .= $digit; if (($k+1) % 2 == 0) $tmpPath .= '/'; } if (substr($tmpPath, -1) != '/') $tmpPath .= '/'; return $tmpPath; } // Custom path needs to be set in the _path() and url() methods static public function _path(Page $page) { //... //$publicPath = $path . ((int) $page->id) . '/'; $tmpPath = self::makeCustomPath($page); $publicPath = $path . $tmpPath; //... } public function url() { //return $this->config->urls->files . $this->page->id . '/'; return $this->config->urls->files . self::makeCustomPath($this->page); } Should be able to test this with many data soon, I'll report back here for those interested.1 point
-
Hey Wanze, Looks like it is here: https://github.com/ryancramerdesign/ProcessWire/blob/a8024bb49785370aa2e3867bd683094663cfeabf/wire/core/PagefilesManager.php#L135 with $this->path() coming from: https://github.com/ryancramerdesign/ProcessWire/blob/a8024bb49785370aa2e3867bd683094663cfeabf/wire/core/PagefilesManager.php#L166 The createPath function is calling this: https://github.com/ryancramerdesign/ProcessWire/blob/a8024bb49785370aa2e3867bd683094663cfeabf/wire/core/Functions.php#L184 I guess it might need the mkdir recursive switch set to true in the wireMkdir function. Is that what you are looking for, or am I missing your point? I think maybe I am1 point
-
@adamkiss, well, great question, but this is just one example where I have needed this type of thing. Usually easily solved by mod rewrite and some careful templates. But gets to be a real pain on bigger websites where there is a lot of dynamic content.1 point