-
Posts
4,928 -
Joined
-
Days Won
321
Everything posted by Robin S
-
Thanks, interesting discussion in that first GitHub issue. It's the second GitHub issue that got me thinking about this in the first place. I understand that the current implementation only checks against the inputs in Page Edit, but that neglects the cases where a page may be created/populated/published via the API, which is an equally valid way to publish content. The way I think of the 'required fields' feature is that the fields are 'strongly recommended' rather than strictly required since it is possible to leave required fields empty in many different ways. But the feature should provide the information that a field has been marked as 'required' for this circumstance (template overrides, 'required if' settings, etc), and that information should be available from the API as well as Page Edit. Will look into this some more and consider placing a GitHub request.
-
Does PW have any API method for checking if a given field is in fact required on a given page? I'm thinking here of fields with a 'Required only if' condition. Or do I have to write my own code for parsing the field, operator and value from the $field->requiredIf string and checking against the page's fields? I know about the functions in inputfields.js but I want to check the required status in PHP.
-
I get an error and can't edit any pages, when logged in as superuser
Robin S replied to bbeer's topic in General Support
As I said, that error message should include file name and line number. Maybe easiest to just post a screenshot of the error message. -
Excellent tutorial. Not too verbose at all - I appreciated the detail and thoroughness. Good idea using the footnotes. The tutorial was really well structured, the way you worked through the essential steps in order and ended with optional enhancements. Thanks for a great read!
-
PHP has a useful array_chunk function: it is used to split an array into a number of smaller arrays ('chunks') of a size you specify, which are returned to you in a new array (i.e. an array of arrays). ProcessWire doesn't provide a method for WireArrays that is the equivalent of array_chunk, but we can add a new method for this in hook. In /site/init.php... // Add a new 'chunk' method to WireArray, the equivalent of PHP's array_chunk $wire->addHookMethod('WireArray::chunk', function($event) { $wire_array = $event->object; $size = $event->arguments[0]; if( !((int) $size > 0) ) throw new WireException('WireArray::chunk requires an integer $size argument greater than zero'); $array = array(); $count = count($wire_array); for($n = 0; $n < $count; $n += $size) { $array[] = $wire_array->slice($n, $size); } $event->return = $array; }); Now we can use this new chunk() method on any WireArray to return an array of smaller WireArrays. Remember that many array-like objects in PW are WireArrays, including PageArrays, Pageimages and Pagefiles. An example using a PageArray of 'workshop' pages. We are running a series of workshops and there is only time for four workshops per day, so we want to divide the workshops into groups of no more than four and put each group under a heading... // Get all workshop pages $workshops = $pages->find("template=workshop"); // say this returns 12 pages // Split the workshops into PageArrays of no more than 4 pages each $chunked_workshops = $workshops->chunk(4); // an array of 3 PageArrays of 4 pages each foreach($chunked_workshops as $key => $chunk) { // $key is the zero-based index of the array $num = $key + 1; // Output a heading followed by the workshop links echo "<h3>Day $num</h3>"; echo $chunk->each("<p><a href='{url}'>{title}</a></p>"); // $chunk is a PageArray } Another example, this time using images. Say we want to divide the images into groups of three or less - maybe they are to be arranged into rows or we are giving the groups some special styling. // Say this page's 'images' field holds 8 images // Split the images into Pageimages objects of no more than 3 images each // 8 does not divide evenly by 3 so the last Pagesimages object will contain only 2 images $chunked_images = $page->images->chunk(3); foreach($chunked_images as $chunk) { echo "<div class='image-group'>"; // $chunk is a Pageimages object foreach($chunk as $image) { echo "<img src='{$image->size(300, 300)->url}'>"; } echo "</div>"; }
- 9 replies
-
- 13
-
In your code $wireTempDir will only give the path to the temp directory, but file_put_contents() requires a filename too. So something like: file_put_contents($wireTempDir . '/temp.pdf', $output);
-
I get an error and can't edit any pages, when logged in as superuser
Robin S replied to bbeer's topic in General Support
Your first post is missing the information needed in order for people to help: what file name and what line number is triggering the error? The error message should include that. -
More likely than this, you just have one or more of... wrong database name wrong database username wrong password for that username ...in /site/config.php Your host should have some control panel (cPanel, Plesk, etc) where you can... check the database name check the database username reset the password for that username ...and then update /site/config.php accordingly. Edit: sorry, I spoke too soon. The error message for wrong db user/pass is slightly different. So it must be either wrong database name (hopefully) or no database at all (oh dear ). P.S. I know it's not much help now but as @cstevensjr mentioned these two modules are essentials for every PW installation IMO: http://modules.processwire.com/modules/process-database-backups/ http://modules.processwire.com/modules/cronjob-database-backup/
-
No, doing this would only allow the exact URL segment 'category'. Instead, don't place any restrictions on the segment in the template settings and do your segment validation inside the 'news' template. Rather than rewrite or render anything from a category page you can handle all the output within your 'news' template. Here is an example from a recent project: $limit = 5; $news_selector = "template=news_item, post_date<=today, limit=$limit, sort=sort"; $categories = $pages(1139)->children(); $segment_1 = $sanitizer->pageName($input->urlSegment1, true); // URL segments are already sanitized as page names but not to lowercase if($segment_1) { $current_category = $categories->get("name=$segment_1"); if($current_category) { // the segment is a valid news category $news_selector .= ", news_category=$current_category"; $page_title = "$current_category->title news"; } else { // the segment is invalid so throw 404 throw new Wire404Exception(); } } $news_items = $pages->find($news_selector); $total_pages = ceil($news_items->getTotal() / $limit); The effect of this is that if there is a valid URL segment then only news items from that category are listed, but if there is no URL segment then all news items are listed.
-
@ethfun, thanks for the module I suggest you prefix the classes coming from the parent pages with "parents-" (or better "parent-" for the direct parent and "parents-" for grandparents). This is because a page name may start with a digit but CSS selectors don't like that. That is from the CSS2 spec - I can't lay my hands on the CSS3 equivalent right now but I believe it is still advisable to avoid classes starting with digits.
-
Anyone successfully added CKEditor shortcut keys?
Robin S replied to Robin S's topic in General Support
Hi @stufru, welcome to the forums. The file is still downloadable, but maybe there is some forum restriction that prevents users with no posts from downloading (?). Now that you have made a post perhaps it works? If not the entire plugin code is in the post above - just copy it into a file named "plugin.js" and put that inside a folder named "keystrokes". Then copy that folder to /site/modules/InputfieldCKEditor/plugins and activate the plugin from your CKEditor field settings under "Extra Plugins". -
Just adding to what abdus and Macrura have said: you use URL segments to do this, but you don't need to hook page paths or render any different page. Your category pages can use a template with only a title field and with no corresponding template file - these category pages only exist for the purpose of being selected in a Page Reference field in your news article pages. In your 'news' template (the template of the parent page of the news articles) you check for a URL segment and if there is one you use that in a selector to match only news articles that have that category selected. You can do a kind of sanitizing of the URL segment by first checking if there is any page by that name using your category template or under your category parent - if there isn't then you throw a 404.
-
I think I get it now - you are talking about a "Fieldset in Tab" fieldtype, right? An InputfieldWrapper is something different. Thanks for the report - should be fixed in v0.0.3.
-
Unfortunately there's no good solution to this that I can see while still using ProcessPageEditLink (i.e. the link modal window). That's because ProcessPageEditLink applies $sanitizer->url to existing link hrefs and the options for it are not configurable within the module. And even if the options were configurable it turns out that it's impossible for javascript links to pass this sanitizer because PHP's FILTER_VALIDATE_URL is always applied. The workings of ProcessPageEditLink seem a bit inconsistent to me so I have opened a GitHub issue. A workaround you could use is to create a Hanna code for inserting javascript links, with attributes for 'href' and 'text'. If you install Hanna Code Dialog you can get a dialog UI in CKEditor.
-
One more option: when debug mode is true you can hover the inputfield open/close toggle to see the field name.
- 14 replies
-
- 1
-
- field name
- field label
-
(and 1 more)
Tagged with:
-
@Pretobrazza, I just tested CSV import of FieldtypeLeafletMapMarker fields with the ImportPagesCSV module and it works fine but needs a couple of simple modifications to the ImportPagesCSV module. Add FieldtypeLeafletMapMarker to the array of allowed fieldtypes: /** * List of Fieldtypes that we support importing to * */ protected $fieldtypes = array( 'FieldtypePageTitle', 'FieldtypeText', 'FieldtypeTextarea', 'FieldtypeInteger', 'FieldtypeFloat', 'FieldtypeEmail', 'FieldtypeURL', 'FieldtypeCheckbox', 'FieldtypeFile', 'FieldtypePage', 'FieldtypeLeafletMapMarker', ); Tell the module how to handle the import of the FieldtypeLeafletMapMarker fieldtype: /** * Assign a value to a page field * */ protected function importPageValue(Page $page, $name, $value) { $field = $this->fields->get($name); if($field->type instanceof FieldtypeFile) { $value = trim($value); // split delimeted data to an array $value = preg_split('/[\r\n\t|]+/', $value); if($field->maxFiles == 1) $value = array_shift($value); $data = $page->ImportPagesCSVData; $data[$name] = $value; $page->ImportPagesCSVData = $data; } elseif($field->type instanceof FieldtypeLeafletMapMarker) { $value = trim($value); // If importing pipe-separated latitude and longitude values, e.g. "-46.0026999|168.03567" // list($lat,$lng) = explode('|', $value); // $page->$name->lat = $lat; // $page->$name->lng = $lng; // If importing address string (automatically geocoded on import) $page->$name->address = $value; } else { $page->set($name, $value); if($name == 'title') $page->name = $this->sanitizer->pageName($value, 2); // Sanitizer::translate } } You'll see I added two ways to import the map pin location: lat/lng (commented out) or address. If you import an address string the lat and lng are geocoded automatically on import. If you import lat and lng without an address then the pin is placed at that location but no address string is automatically generated. If you were to import an address string and a lat/lng (not shown here and not recommended) then the lat/lng is ignored and the location is geocoded from the address string - i.e. the same as just importing an address string. You could add a zoom value if you wanted - just separate from the other value(s) with a pipe and adapt the example for lat/lng, i.e. explode() and list().
-
How to capture page containing a pagetable?
Robin S replied to bmacnaughton's topic in API & Templates
@bmacnaughton, give the following hook a try (must be in /site/init.php or in init method of module). Seems to work well for both PageTable additions and edits of existing items. $this->addHookBefore('InputfieldPageTableAjax::checkAjax', function($event) { $page_id = (int) $this->input->get('id'); $item_id = (int) $this->input->get('InputfieldPageTableAdd'); if($page_id) $page = $this->pages->get($page_id); // $page is the container page if($item_id) $item = $this->pages->get($item_id); // $item is the PageTable item // ... }); Edit Nov 2017: more information in this post... -
Could you explain some more about what you are doing at the time you see this error? I'm not sure what you mean by 'edit the inputfieldwrapper field'. Are you editing a field's settings in admin or via the API?
-
The role must have Edit permission for the template: page-sort and page-move are sub-permissions of the page-edit permission.
-
It looks like ProcessPageEdit does not use the addActionValue() method but builds the dropdown independently: https://github.com/processwire/processwire/blob/3fc9f69da75e1bc4a3f0842f12a57bd6a1b65099/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.module#L454-L491 Doesn't seems like it would be easy to modify that - probably via JS would be the only way. Maybe you could open a GitHub request asking to make it easier to modify that dropdown menu.
-
I think this would do the job: $cloneable = $page->parent->addable($page); // boolean true/false Plus check that the user has the page-clone permission, as @arjen suggested.
-
Thanks @abdus, that gave me the clue to getting Tracy working in modals. Just uncheck the "Hide Debug Bar in Modals" options in the Tracy config.
-
Hi @adrian, just leaving this here now while I remember for when you are back. I'm not able to use Tracy inside a ProcessPageEdit hook when the page being edited is a PageTable page (i.e. in the modal window). In /site/ready.php (or /site/init.php)... $this->addHookBefore('ProcessPageEdit::execute', function($event) { bd('testing'); });