Pierre-Luc Posted June 21, 2014 Share Posted June 21, 2014 Field Generator is a module to help you create random character strings and automatically assign them to one or multiple fields of your choice when a page is created. When setup, it will automatically do so whether you create a page through the administration panel or through code, meaning you don’t need to set $page->name or any other field of your choice, it just works automagically. Field Generator uses PHP’s openssl_random_pseudo_bytes() function to generate its random strings. It thus has both PHP >= 5.3.0 and OpenSSL as dependencies. Usage After installation, add rules through Setup > Field Generator. That’s it! Rules only run when first creating the page. For more information : https://github.com/plauclair/FieldGenerator Release : Version 0.9.0 This is the initial release. This is near stable and you shouldn’t be too worried to use it in production. Here is a screencast on how to use it. 10 Link to comment Share on other sites More sharing options...
apeisa Posted June 21, 2014 Share Posted June 21, 2014 Congratulations on your module Pierre-Luc! I was little confused about the module name, since it doesn't really generate fields, but field values? 1 Link to comment Share on other sites More sharing options...
Pierre-Luc Posted June 21, 2014 Author Share Posted June 21, 2014 Thanks! You’re right apeisa, think it would be better to rename it? 2 Link to comment Share on other sites More sharing options...
Pierre-Luc Posted June 25, 2014 Author Share Posted June 25, 2014 Version 0.9.5 - Adds language fields support I just pushed version 0.9.5 to master. This version adds support for multilingual fields. I made a few tests but let me know if you stumble on something weird. Link to comment Share on other sites More sharing options...
Pierre-Luc Posted July 9, 2014 Author Share Posted July 9, 2014 Version 0.9.9 - Generators for all! Download on GitHub 0.9.9 fixes an access problem preventing users other than the superadmin to use it and other minor bugs. I've removed the ability to delete the stored settings, I figured if someone disabled the module temporarily and wanted to reactivate it, you shouldn't lose your settings for that. What do you guys think? Link to comment Share on other sites More sharing options...
Soma Posted July 9, 2014 Share Posted July 9, 2014 There is no disable just uninstall or install. You could add a checkbox to disable and not execute hooks 1 Link to comment Share on other sites More sharing options...
Pierre-Luc Posted July 9, 2014 Author Share Posted July 9, 2014 There is no disable just uninstall or install. You could add a checkbox to disable and not execute hooks That's what I was thinking, I'll look at implementing that for 1.0.0 Link to comment Share on other sites More sharing options...
hafa Posted November 5, 2014 Share Posted November 5, 2014 (edited) Hi guys I'm using the Field Generator module to generate random strings of numbers and assign them to one field of my choice when a page is created. In the module description, it says we don't need to set $page->name (or any other field), it just works automagically. As in my case, I'm using the module to create urls (for example, mysite.com/image/131602236844), so I'd need to use the $page->name field to create the string, but it won't work. It works on any other custom field, but not with "name" field. Here are a few screenshots: Field Generator setup with "name" field: http://api.drp.io/files/544295d764173.png But nothing happens on the "name" field: http://api.drp.io/files/544295d75bb0e.png // http://api.drp.io/files/544295d7523ad.png I've already tried putting "name" and "$page->name" but nothing happens. Any ideas if I'm doing something wrong? Edited November 9, 2014 by kongondo Moved your topic to the module's support forum Link to comment Share on other sites More sharing options...
hafa Posted November 6, 2014 Share Posted November 6, 2014 Anyone? Link to comment Share on other sites More sharing options...
kongondo Posted November 6, 2014 Share Posted November 6, 2014 (edited) Maybe PM Pierre-Luc the module author or file an issue in the project's page at GitHub since the module does not seem to have a support forum.... Edited November 9, 2014 by kongondo Had totally missed the support forum Link to comment Share on other sites More sharing options...
kixe Posted November 7, 2014 Share Posted November 7, 2014 I don't know how the module works. But 'name' is a reserved word for the pagename, which is stored in database table 'pages'. It is not a field like 'title', which is assigned to the page. Try another word than 'name'.some other reserved words, which cannot be used for field names: created modified status sort Link to comment Share on other sites More sharing options...
hafa Posted November 8, 2014 Share Posted November 8, 2014 Maybe PM Pierre-Luc the module author or file an issue in the project's page at GitHub since the module does not seem to have a support forum.... I've tried I don't know how the module works. But 'name' is a reserved word for the pagename, which is stored in database table 'pages'. It is not a field like 'title', which is assigned to the page. Try another word than 'name'. some other reserved words, which cannot be used for field names: created modified status sort Hmm, I've figured this... so there's no way to do custom urls? Link to comment Share on other sites More sharing options...
Macrura Posted November 9, 2014 Share Posted November 9, 2014 is this not the support forum? https://processwire.com/talk/topic/6727-field-generator/ in the video it clearly shows 'name' as the field being targeted. Could be a compatibility issue if it is not working.. maybe you have to check OpenSSL dependency? you could easily write a much simpler module (see example code below), or use processwire's new automatic page name feature (i'm using it a lot).. here is an example of a simple module to create a randomy page name, using PHP uniqid() function (untested): <?php public function generateRandomName() { if ($this->input->get->parent_id == 1019) { // 1019 = some page where we want to auto-generate child page names $page = new Page(); $page->parent = $this->input->get->parent_id; $page->template = 'child-template-name'; $page->name = uniqid(); $page->addStatus(Page::statusUnpublished); $page->save(); $this->session->redirect("../edit/?id=$page"); } } 3 Link to comment Share on other sites More sharing options...
kongondo Posted November 9, 2014 Share Posted November 9, 2014 @Macrura,....ah, yes, thanks. That's the support forum. I was checking via the modules directory and it isn't listed there... Merging this topic there... Link to comment Share on other sites More sharing options...
kixe Posted November 10, 2014 Share Posted November 10, 2014 (edited) processwire's new automatic page name feature (i'm using it a lot).. $page->name = uniqid(); @Macrura This is not processwires new automatic page name feature. It is a php function which generates a hex converted string of microtime(). Since it is quite unlikely that the same page name is generated your example will work, but it is not a clean solution. Edit: Forget about the preceding line If you want to generate a page by processwires api with a unique page name, you have to could use the add() method. No need to instantiate a page object in your template. $parent = 'parentname'; $template = 'templatename'; $name = 'foo'; $pages->add($template,$parent,$name); With this function you get pages with the title 'foo' and the name 'foo-[n]'. [n] is a counter which makes the name unique. You could add a fourth parameter to set other page properties like status or so. The fourth parameter has to be an array. $pages->add($template,$parent,$name,array('status'=>1)); Even if you leave out $page->name = uniqid(); in your example the page will be generated unique. In both cases the counter doesn't work properly since it counts all siblings and not only those with the same name. Edited November 10, 2014 by kixe 3 Link to comment Share on other sites More sharing options...
Macrura Posted November 10, 2014 Share Posted November 10, 2014 @kixe - sorry for some misunderstanding/misreading of my post (it wasn't clear); what i was trying to say is you could the built in auto-name (in the admin): OR make your own 'simpler' module, which is what i was trying to give an example of. Since the module in question (Field Generator) uses a function with openSSL dependency and the OP was not able to get said module to work, the use of uniqid() is there to give the possibility of a random looking page name as an alternative; but it is probable that the results would not be much different than using Ymdhis as your field setting Link to comment Share on other sites More sharing options...
kixe Posted November 10, 2014 Share Posted November 10, 2014 or use processwire's new automatic page name feature (i'm using it a lot).. @macrura Ahh, thats what you are talking about For everybody: If you want to use this feature you have to create a new field of fieldtype PageTable. 'Automatic Page Name Format' could be set under the 'Input' Tab. Since it is quite unlikely that the same page name is generated your example will work, but it is not a clean solution. Edit: Forget about the preceding line I tried it out again and I have to correct myself again. Not good, because you will get an mysql error if you do it more than one time $page = new Page(); $page->parent = 'parentname'; $page->template = 'templatename'; $page->name = 'foo'; $page->save(); Better, because name will be autogenerated unique. $page = new Page(); $page->parent = 'parentname'; $page->template = 'templatename'; $page->title = 'foo'; $page->save(); // or $page = new Page(); $page->parent = 'parentname'; $page->template = 'templatename'; $page->save(); Link to comment Share on other sites More sharing options...
Pierre-Luc Posted November 11, 2014 Author Share Posted November 11, 2014 Hey guys, sorry for not answering for a while, I've been quite busy with other things lately. All fields should be supported, name included. It is compatible with 2.4 and 2.5, I have a few sites running it without any problem. As was mentioned, there are dependencies that MUST be met, check the GitHub page for documentation. Link to comment Share on other sites More sharing options...
Pierre-Luc Posted November 11, 2014 Author Share Posted November 11, 2014 Questions: 1) do you have any of the ProcessWire language modules enabled? If so, which ones? 2) Do you still have problems with the name field when you use letters in the dictionary (I had this happen once, but I thought I fixed it) Link to comment Share on other sites More sharing options...
hafa Posted November 16, 2014 Share Posted November 16, 2014 Questions: 1) do you have any of the ProcessWire language modules enabled? If so, which ones? 2) Do you still have problems with the name field when you use letters in the dictionary (I had this happen once, but I thought I fixed it) Hi Pierre, 1) nope 2) i'm using only numbers, but i tried letters to test and it doesn't work either btw, i'm using the latest processwire version (2.5.2) in the video it clearly shows 'name' as the field being targeted. Could be a compatibility issue if it is not working.. maybe you have to check OpenSSL dependency? Yes, it's enabled. Link to comment Share on other sites More sharing options...
hafa Posted November 30, 2014 Share Posted November 30, 2014 Seems Pierre-Luc hasn't been too active on the forums, unfortunately. By any chance does anyone know how I can auto-generate slugs like that without using this module? Link to comment Share on other sites More sharing options...
kongondo Posted November 30, 2014 Share Posted November 30, 2014 @Hafa, I suggest you first rule out if MAMP/OpenSSL is the issue. I don't use MAMP myself so I don't know how to enable OpenSSL. Maybe others will chime in but meanwhile you can find out. Can you also confirm you are running the required PHP version? Additionally, to rule out the problem of your environment, you can test your site in lightning.pw....(when it's back online ) Link to comment Share on other sites More sharing options...
Macrura Posted November 30, 2014 Share Posted November 30, 2014 @hafa - i would probably make a module that uses a different crypto library, maybe flourish although this looks like it might be in beta.. also found this.. http://www.gilfether.com/phpcrypt/ would be easy to make the module to generate the slug; i think examples were provided earlier in this thread Link to comment Share on other sites More sharing options...
hafa Posted November 30, 2014 Share Posted November 30, 2014 Hi @Macrura! I wanted to test your code right way but I'm not sure where I should include it? A functions.php file? And can the "uniqid" function generate numbers only? Is it possible to set a length? Thank you very much for taking the time to try help me out! here is an example of a simple module to create a randomy page name, using PHP uniqid() function (untested): <?php public function generateRandomName() { if ($this->input->get->parent_id == 1019) { // 1019 = some page where we want to auto-generate child page names $page = new Page(); $page->parent = $this->input->get->parent_id; $page->template = 'child-template-name'; $page->name = uniqid(); $page->addStatus(Page::statusUnpublished); $page->save(); $this->session->redirect("../edit/?id=$page"); } } @Kongondo Waiting for lightning.pw to get back online! Thank you for the tip! Link to comment Share on other sites More sharing options...
Macrura Posted November 30, 2014 Share Posted November 30, 2014 @hafa - this would need to be inside a module - maybe take a look at the helloworld module, or check this out: https://processwire.com/talk/topic/1908-automatically-generating-new-page-names/?p=48421 as far as uniqueid - you would want to use that if you don't care about anything with security, just for random numbers; if you wanted something more cryptographically sound, maybe try flourish fCryptography - there is a flourish autoloader module for processwire. - - - http://php.net/manual/en/function.uniqid.php WarningThis function does not create random nor unpredictable strings. This function must not be used for security purposes. Use a cryptographically secure random function/generator and cryptographically secure hash functions to create unpredictable secure IDs. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now