-
Posts
5,008 -
Joined
-
Days Won
333
Everything posted by Robin S
-
You can show the field when the countries field is empty using the core inputfield dependencies feature: countries.count=0 Or you could show it when the page is unpublished (which would apply when the page is first added) with the help of my Custom Inputfield Dependencies module.
-
To me the main distinction is between the bulk importing of data (for which modules like ImportPagesCSV are great) and the occasional addition or editing of data which you do via Page Edit. But in any case it's not difficult to do what you are asking about. Add a textarea field in your template named "country_import" or something. Then use a hook to Pages::saveReady() to process the field contents and add them to the "countries" Page Reference field. In /site/ready.php: $pages->addHookAfter('saveReady', function(HookEvent $event) { $page = $event->arguments(0); // Only for the appropriate template if($page->template == 'YOUR-TEMPLATE') { // If the import field is not empty if($page->country_import) { // Get the individual country titles in an array $country_titles = explode(', ', $page->textarea_1); // Find the country pages with those titles $country_pages = $this->pages->find([ 'template' => 'country', 'title' => $country_titles, ]); // Add the country pages to the countries field $page->countries->add($country_pages); // Empty the import field $page->country_import = ''; } } }); You could use the same principle for other fields if you think there's a major benefit to it.
-
A couple more links that may be useful:
-
Who is creating the pages? You (the developer), or a client? If you are creating the pages then I think it would be better to use the API or a bulk import module (ImportPagesCSV, BatchChildEditor) to bring this data in initially rather than spend time making something special in Page Edit. API $countries_string = 'Nigeria, Kenya, Australia, Russia, France'; // Maybe you would instead create an array of country strings to process multiple pages at once // 'Page One Title' => 'Nigeria, Kenya, Australia, Russia, France', // 'Page Two Title' => 'Russia, ...' // ... $country_titles = explode(', ', $countries_string); $country_pages = $pages->find([ 'template' => 'country', 'title' => $country_titles, ]); // Set $country_pages to the Page Reference field ImportPagesCSV Use a text editor to replace instances of ', ' with '|' in your countries string. Now the country titles are in a format that can be imported to a Page Reference field by ImportPagesCSV (see the module readme). You could import all the page content via the module, or just the countries field if you prefer (create a CSV that contains two columns - the page title and the pipe-separated string of country titles).
-
I don't think you can store objects in $session. See this comment from Ryan for instance: Storing an array (without objects) seems to work: $my_array = []; $my_array['animal'] = 'cat'; $my_array['colour'] = 'orange'; $session->my_array = $my_array;
-
To solve this you need to look at the code for each method you are considering hooking and ask yourself things like: What class is the method in? Does the method fire when I need it to? Does the method have an argument or return value that I need to use in my hook? So you are considering hooking ProcessLogin::afterLogin() or Session::loginSuccess(). When you look at afterLogin() you see: It is a method of ProcessLogin, a Process module that handles the PW login form. So it is only going to fire if a user logs in via the core PW login form. Maybe that isn't what you want if you are using a custom login form or logging in users via the API as part of some script. It depends on what you are doing. The method comments in the source code say it is only intended for when a superuser logs in, which could give you a clue if it is the best method to hook or not. It has no arguments that could be useful to quickly tell you things about the user who has logged in (although you could still get the $user object in other ways). So chances are Session::loginSuccess() is going to be a better option because it is a method of Session, so more closely connected to the current user session regardless of how they logged in. And it conveniently has the $user object as an argument so you can easily check properties of the user such as name, role, etc, in your hook.
-
This is deliberate and Ryan has talked about it but I don't have a link handy. Probably because there can be situations where a field contains a lot of data in which case the user should be notified of a problem but not have all their work thrown out. See this example from @Soma where he shows how you can set a field back to its previous value when you want to reject a submission:
-
Headings Case A plugin for CKEditor fields in ProcessWire CMS/CMF. Adds a toolbar button for changing the case of all headings or selected headings between sentence case and title case. This is useful when you are copy/pasting text from a document that has been supplied with an inconsistent or incorrect system of capitalisation. Installation The plugin folder must be named "headingscase" – if needed, rename the folder to remove the "-master" suffix added by GitHub. Copy the "headingscase" folder to /site/modules/InputfieldCKEditor/plugins/ In the field settings for each CKEditor field that you want to activate the plugin for: Check the "headingscase" checkbox at Input > Plugins > Extra Plugins Add "HeadingsCase" at Input > CKEditor Settings > CKEditor Toolbar Usage To change the case of all headings, click the toolbar button with no text selected in CKEditor. The first click applies sentence case; the second click applies title case. To change the case of a single heading, select all or part of the heading in CKEditor before clicking the toolbar button. There can be situations where the results need manual correction: proper names, acronyms, etc. Exceptions for small words Certain short English prepositions and conjunctions (three letters or less) are excluded from capitalisation when title case is applied. Edit the exceptions array in the plugin source code if you want to customise this list of exceptions. https://github.com/Toutouwai/headingscase
-
Great, pull request made.
-
In general, you should do this by putting your HTML structure into your template files. Only content should come from your fields. So this... ...should be in your template file, not in a textarea field. Once you've got the hang of "normal" template files you can explore field template files too - these are more of an optional extra than a must have.
-
Not tested thoroughly, but this should work, in /site/config.php: $config->paths->files = $config->paths->assets . 'example/'; $config->urls->files = $config->urls->assets . 'example/';
-
Module Profile Export module (also upgrade PW 2.0 to 2.1)
Robin S replied to ryan's topic in Modules/Plugins
@ryan, could you please add an option to include setlocale() in the exported config.php if it is defined. Now that PW is giving warnings if setlocale() is missing it would be nice not to have to remember to manually add this each time a profile is installed. -
SmartyPants Typographer incorrect curly quote
Robin S replied to alexcapes's topic in General Support
I can't reproduce that. Maybe you have some odd unicode character in your text that is confusing SmartyPants? Or an unclosed open quote before the sentence in question?- 4 replies
-
- 1
-
-
- smartypants
- module
-
(and 1 more)
Tagged with:
-
No ideas about the cause of this issue sorry. This may not be as bad as it sounds. Export/import fields via core feature Export/import templates via core feature Export/import modules and module settings via Module Toolkit Copy PHP files: templates, config, ready, etc Here's where it gets a bit experimental: Export/import pages via new core feature. @horst has had some success with it.
-
Welcome @nasenfloete Maybe you can post the API code you are using the add the repeater items so others can see if they can reproduce the problem. I don't see why the role or permissions of the user should have any influence on adding repeater items to the user page via the API.
-
That's because "Manual drag-n-drop" is the default sort setting, i.e. choosing it is the same thing as leaving the setting empty. Manual drag-n-drop means the "Move" option in the page list actions: Whether this solves the order of your menu is another story though. You'd need to post the code you are using to generate your menu before people can help with that.
- 1 reply
-
- 1
-
-
How to change the published date format in find lister
Robin S replied to Mirza's topic in General Support
Currently you cannot. There is a @todo note in the code: // @todo make this format customizable via wireDate() https://github.com/processwire/processwire/blob/57b297fd1d828961b20ef29782012f75957d6886/wire/modules/Process/ProcessPageLister/ProcessPageLister.module#L1264-L1267 Edit: you cannot set the date format individually for the 'created', 'modified' and 'published' columns, but if you don't mind using the same format for all you can use this hook in /site/ready.php: $wire->addHookBefore('ProcessPageLister::execute', function(HookEvent $event) { $lister = $event->object; $lister->nativeDateFormat = 'Y-m-d'; // see https://processwire.com/api/ref/datetime/date/ for format options });- 3 replies
-
- 3
-
-
- published date column
- lister
-
(and 2 more)
Tagged with:
-
Getting categories that have entries with Page Reference field
Robin S replied to mciccone's topic in General Support
What @Alxndre' is suggesting is something like the below... First you get your category pages, then you loop over the categories, for each category finding pages that have that category selected in the Page Reference field. If there are some matching pages, output the category heading and the list of posts. $categories = $pages->find("template=category"); foreach($categories as $category) { $posts = $pages->find("template=article-post, category=$category"); if(count($posts)) { echo "<h3>$category->title</h3>"; foreach($posts as $post) { // whatever markup you want for the post echo "<p>$post->title</p>"; } } } This is fine for a lot of circumstances, but note that you do a database query to get the categories and then for each category you do a database query. If you have a lot of categories this would mean a lot of database queries. There is another approach that is more efficient: get all the posts sorted by category (as you are already), then for each post check if the category is different from the previous post's category. If it is different then output a heading. $posts = $pages->find("template=article-post, sort=category"); $category_title = ''; foreach($posts as $post) { if($post->category->title !== $category_title) { $category_title = $post->category->title; echo "<h3>$category_title</h3>"; } // whatever markup you want for the post echo "<p>$post->title</p>"; } -
I don't think these classes are related to anything you may or may not have defined in mystyles.js. The mystyles.js file is for populating the Styles dropdown in the CKEditor toolbar. The classes defined in the Page Edit Image module config relate only to the three alignment buttons in the module modal:
-
@szabesz, I think this is covered by $input->url() and $input->httpUrl() now, which were introduced since I wrote my post above. There's a blog post about it somewhere but I can't find it at the moment.
-
The class names are defined in the config for the Page Edit Image module (ProcessPageEditImageSelect).
-
Turns out it's not difficult to do this using the core ImageSizer. Here's a function showing the basics - could be turned into a module, enhanced with some error checking, etc. /** * Resize Pageimage using custom name/path * * @param Pageimage $pageimage * @param int $width * @param int $height * @param array $options * * @return string * */ function resizeImage($pageimage, $width = 0, $height = 0, $options = array()) { $filename = $pageimage->filename(); $basename = $pageimage->basename(); $path = rtrim($filename, $basename); $dirname = $width . 'x' . $height; $variation_name = $path . $dirname . '/' . $basename; $variation_url = rtrim($pageimage->url(), $basename) . $dirname . '/' . $basename; $force_new = isset($options['forceNew']) ? $options['forceNew'] : false; if(!file_exists($variation_name) || $force_new) { wire('files')->mkdir($path . $dirname . '/'); copy($filename, $variation_name); $sizer = new ImageSizer($variation_name); $sizer->setOptions($options); $sizer->resize($width, $height); wire('files')->chmod($variation_name); } return $variation_url; } // example $image = $page->images->first(); $src = resizeImage($image, 500, 300); echo "<img src='$src'>";
-
The built-in image sizing methods are convenient but they're not the only way to resize an image. You could use a third-party PHP library such as WideImage and save your images with any naming or directory structure you need.
-
Third normal form with processwire: How to reference data?
Robin S replied to HarryPhone's topic in Getting Started
A Page Reference field will work great for your "Homepage Listung" field. It's no problem to set a Page Reference field using data from a CSV import. You don't say how you are importing the CSV data, but let's say you are using the ImportPagesCSV module. The module readme says... Probably the easiest way in your case is to use the title of the page. So a basic outline of what's involved... The template for the pages in your Page Reference field should contain the "Title" field and a "Label" text field. Create the pages for the Page Reference field - one for each option that might occur in your CSV data. For the page Title use the value that appears in the CSV data. For the page Label use the label that belongs to that value. Example... Title: "NE2", Label: "n. Endkundenrelevant" Create the Page Reference field and add it to the template used for the pages you will be importing. Specify the pages you just created as the "Selectable pages". For the "Label field" setting, choose "label". Import your CSV data using the ImportPagesCSV module. Done.