kixe

Name Format Children

69 posts in this topic

Find attached the first Alpha Version of the Module ProcessSetupPageName with Multilanguage Support. I tested it under various circumstances and it is doing fine with one exception: Until now it doesn't work together with 'Page Name Extended' (since PW 3.0.12) which allows UTF8 Page Names. Module requires PHP >= 5.4.x
Download from here:
EDIT: Removed link, download last version from here: https://github.com/kixe/ProcessSetupPageName/archive/master.zip

Would be nice if you could test it and give a feedback to me. Thanks in advance.

Edited by kixe
Due to some updates, I replaced the download link.
3 people like this

Share this post


Link to post
Share on other sites

There the error with the new file.

Error: Cannot access self:: when no class scope is active (line 70 of ../site/assets/cache/FileCompiler/site/modules/ProcessSetupPageName-master/ProcessSetupPageName.module)

For use it I just remove the self::$notes and replace by ''.

Share this post


Link to post
Share on other sites

@Filkaboy
Which PHP Version do you use? Both Errors you mentioned looking like PHP = 5.3.x Could you make an update of your PHP Version and try again? Thanks.

Fatal error: Using $this when not in object context in /site/modules/ProcessSetupPageName-master/ProcessSetupPageName.module on line 68

Error: Cannot access self:: when no class scope is active (line 70 of ../site/assets/cache/FileCompiler/site/modules/ProcessSetupPageName-master/ProcessSetupPageName.module)

Share this post


Link to post
Share on other sites

@Filkaboy

Which PHP Version do you use? Both Errors you mentioned looking like PHP = 5.3.x Could you make an update of your PHP Version and try again? Thanks.

Yes exactly the problem... my previews version of php 5.3 and now with 5.5 all work fine.

Thank you

1 person likes this

Share this post


Link to post
Share on other sites

Great module but there's one thing that prevents me form using it, maybe this could be added in the future:

When adding a page and in the middle of the process you decide not to add a new page (skipping the Publish button and navigate away), then an empty page will be created. I think this coul be solved by adding a "Cancel" button next to the existing buttons ("Publish", "Save and....", "Cancel"). But perhaps there is an easier fix.

Don't get me wrong - I can delete the pages of course but I would use this module to make it easier for clients to add new pages, especially where the page name is actually irrelevant.

As a bonus feature request I would love to see message like these appear only for superusers - these may be too much for a regular client:

"SetupPageName expects value in field 'title' to autogenerate Pagename"

1 person likes this

Share this post


Link to post
Share on other sites

Ryan solved this in pagetable as that pages created but not published are deleted automatically each day by a kind of lazycron. On mobile and no details for that... Just throwing in an idea

1 person likes this

Share this post


Link to post
Share on other sites

When adding a page and in the middle of the process you decide not to add a new page (skipping the Publish button and navigate away), then an empty page will be created. I think this coul be solved by adding a "Cancel" button next to the existing buttons ("Publish", "Save and....", "Cancel"). But perhaps there is an easier fix.

In fact the page is already created in the 'middle of the process' and it has to be created to pull the page name from other page fields. If you don't like this. Create a cronjob like bernhard mentioned. Example:

$wire->addHook('LazyCron::everyDay', function() {
    // trash untitled pages
    $delay = time()-60;
    $untitleds = wire('pages')->find("created<$delay,name^=untitled,include=all");
    foreach ($untitleds as $untitled) $untitled->trash(); // to delete permanently use $untitled->delete() instead
});
Don't get me wrong - I can delete the pages of course but I would use this module to make it easier for clients to add new pages, especially where the page name is actually irrelevant.

In this case you don't need this module. Use built in 'Name Format Children' in parent template settings and create the name frome date. It is also possible in my module to create the name from any autogenerated page property like 'created' or 'id'. Read the note in 'Name Format Children' field if module is installed.

As a bonus feature request I would love to see message like these appear only for superusers - these may be too much for a regular client:

"SetupPageName expects value in field 'title' to autogenerate Pagename"

This message is needed. How could the page editor know from where the values are pulled to generate the pagename? I don't want to change this.

2 people like this

Share this post


Link to post
Share on other sites

Thanks, I will try a combination of fields then & try lazycron.

This message is needed. How could the page editor know from where the values are pulled to generate the pagename? I don't want to change this.

Sometimes the editors shouldn't care about the page name, for example when pages are created to hold content for content blocks. For example awards pages that won't have its own page at all.

1 person likes this

Share this post


Link to post
Share on other sites

Hi, I was trying this module, and I get this error:

Error: Uncaught Error: Call to a member function getDefault() on null in /Users/krlos/Documents/Sitios/processpdf/site/modules/ProcessSetupPageName/ProcessSetupPageName.module:99

Processwire: 2.7.2

PHP: 7.0.0

Share this post


Link to post
Share on other sites
On 2016/7/11 at 10:51 AM, Krlos said:

Hi, I was trying this module, and I get this error:


Error: Uncaught Error: Call to a member function getDefault() on null in /Users/krlos/Documents/Sitios/processpdf/site/modules/ProcessSetupPageName/ProcessSetupPageName.module:99

Processwire: 2.7.2

PHP: 7.0.0

I also get this error and found that this is due to the lack of  a core module called "Languages Support". The error is gone after install the module.

I suggest to add "Languages Support" to the dependency of this module.

Share this post


Link to post
Share on other sites

Hi,

this module throws an error when I create a new page.

Call to a member function getLanguageValue() on a non-object (Zeile 121 in /var/www/_html_default/processwire-playground/site/modules/ProcessSetupPageName/ProcessSetupPageName.module)


My name format for children is "date(Y/m/d) title", LanguageSupport is installed but the title field has the type PageName, not PageNameLanguage.

In this case, $page->title is a plain string, so this seems to work for me:

        // case 2: title default
        else if ($format == 'title') {
            if(is_object($page->title) && strlen($page->title->getLanguageValue($languageID))) {
                $pageName .= '-'.$page->title->getLanguageValue($languageID);
            } else {
                $pageName .= '-'.$page->title;
            }
        }

Further investigation might be necessary: Can $page->title->getLanguageValue(...) be an empty string?

Share this post


Link to post
Share on other sites

Hi,

it seems the module throws errors, when used together with Version Control. Pages which have version control enabled generate this error message.

I am not very good at php, so I cant investigate this further, but I would like to use this module. ATM I cant run the site without version control.

Uncaught Error: Call to a member function get() on null in /Applications/MAMP/htdocs/wire/core/Pages.php:321
Stack trace:
#0 /Applications/MAMP/htdocs/wire/core/WireArray.php(1933): ProcessWire\Pages->get('setModuleConfig...')
#1 /Applications/MAMP/htdocs/wire/core/WireArray.php(2149): ProcessWire\WireArray->implode('ProcessVersionC...', 'setModuleConfig...', Array)
#2 [internal function]: ProcessWire\WireArray->___callUnknown('setModuleConfig...', Array)
#3 /Applications/MAMP/htdocs/wire/core/Wire.php(374): call_user_func_array(Array, Array)
#4 /Applications/MAMP/htdocs/wire/core/WireHooks.php(549): ProcessWire\Wire->_callMethod('___callUnknown', Array)
#5 /Applications/MAMP/htdocs/wire/core/Wire.php(399): ProcessWire\WireHooks->runHooks(Object(ProcessWire\Modules), 'callUnknown', Array)
#6 /Applications/MAMP/htdocs/wire/core/Wire.php(402): ProcessWire\Wire->__call('callUnknown', Array)
#7 /Applications/MAMP/htdocs/site/mo (Zeile 321 in /Applications/MAMP/htdocs/bluevr/wire/core/Pages.php) 

PW: 3.0.39

Share this post


Link to post
Share on other sites

@Krlos @Karl_T

On 11.7.2016 at 4:51 AM, Krlos said:

Hi, I was trying this module, and I get this error:


Error: Uncaught Error: Call to a member function getDefault() on null in /Users/krlos/Documents/Sitios/processpdf/site/modules/ProcessSetupPageName/ProcessSetupPageName.module:99

 

I fixed the single/ multilanguage issue. Sorry for the delay ...
Please update to 2.0.1 and try out.

1 person likes this

Share this post


Link to post
Share on other sites

How can I display on the backend the pages created with this module as titles instead of names?

For example I'm currently see the pages as: test-30-jan-2017. How can I see them as: Test 30 Jan 2017?

Sorry that was my mistake.

Share this post


Link to post
Share on other sites

@kixe Are you planning to make the module to update the page name when the fields that used to generate the name have been edited?

Share this post


Link to post
Share on other sites
On 13.2.2017 at 1:02 PM, PWaddict said:

@kixe Are you planning to make the module to update the page name when the fields that used to generate the name have been edited?

@PWaddict Thanks for the input. I made the module configurable with the option you mentioned. Furthermore I did some repairings for some special cases. Seems to work. Please try Version 2.0.2

1 person likes this

Share this post


Link to post
Share on other sites
8 hours ago, kixe said:

@PWaddict Thanks for the input. I made the module configurable with the option you mentioned. Furthermore I did some repairings for some special cases. Seems to work. Please try Version 2.0.2

I just tried it and unfortunately it doesn't work at all. I tried with both checked and unchecked the option just in case that was the problem.

Share this post


Link to post
Share on other sites
9 hours ago, kixe said:

I made the module configurable with the option you mentioned.

Perhaps there should be some warning about this option in the readme and/or module config page, as it has the potential to inadvertently break links if the Page Path History module is not installed.

1 person likes this

Share this post


Link to post
Share on other sites
4 hours ago, PWaddict said:

I just tried it and unfortunately it doesn't work at all. I tried with both checked and unchecked the option just in case that was the problem.

I am sorry about that. Did you get any Errors? Exceptions? Please let me know. I tested the module in 2 different environments. It worked there without problems.

@Robin S

Thanks for the hint. I added a note to the config field and the readme.

1 person likes this

Share this post


Link to post
Share on other sites
1 hour ago, kixe said:

I am sorry about that. Did you get any Errors? Exceptions? Please let me know. I tested the module in 2 different environments. It worked there without problems.

There are no errors. It's just doesn't update the page name. I'm on localhost with php 7 and ProcessWire 3.0.52.

Share this post


Link to post
Share on other sites

@PWaddict

I missed to add the hook which update pagenames even if language support isn't enabled. I fixed this in Version 2.0.3
If you use the module in single language mode this might have been the cause. Thanks for your help.

2 people like this

Share this post


Link to post
Share on other sites
52 minutes ago, kixe said:

@PWaddict

I missed to add the hook which update pagenames even if language support isn't enabled. I fixed this in Version 2.0.3
If you use the module in single language mode this might have been the cause. Thanks for your help.

Yep that was the problem. Now it's working perfect. Thank you very much.

1 person likes this

Share this post


Link to post
Share on other sites

@kixe I'm using a multi-language datetime field on the name format for children and it doesn't work properly. I'm using this format: %b %d, %Y and it can't update the page name with the format %b. It seems that it can only update the numeric formats.

Instead of getting this page name:
jan-22-2018

I'm getting this:
b-22-2018

Can you please fix it?

Share this post


Link to post
Share on other sites

The module uses php function date() and NOT strftime(). To get what you expect use the following format string: 'date(M-d-Y)'.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By cosmicsafari
      Hi all,
      I am working on a module which creates templates, fields & pages upon install.
      I have ran into an issue where I have a numerous fields which I would like to override their labels depending on the template they are used in.
      Is it possible to do this dynamically via API at the point where I am creating the field group and template using the API.
      The following is the code which I am using at the moment.
      foreach($templatesArray as $name => $cTemplate) { if(array_key_exists('fieldGroup',$cTemplate)) { $fg = new Fieldgroup(); $fg->name = $name . '-fg'; foreach ($cTemplate['fieldGroup'] as $field) { //possibly at this point? $fg->add($this->fields->get($field)); } $fg->save(); } $t = new Template(); $t->name = $name; $t->fieldgroup = $fg; $t->noChildren = 1; $t->setIcon($cTemplate['icon']); $t->save(); } Is this even possible?
    • By psy
      I've configured my PW site to use regions and mostly it's fabulous. However I encountered a strange problem when appending scripts to the body tag of a template. The body tag id is "bodyTag" (duh!).
      There are 3 scripts - two external and one inline. My first attempt was to append each script individually thinking they'd appear in the same order on the output:
      <script id="googlemapskey" type="text/javascript" src="https://maps.google.com/maps/api/js?key=XXXXXXXXXXXXXXXXXXXXXX" pw-append="bodyTag"></script> <script id="localMapsJS" type="text/javascript" src="<?=$bootstrap?>js/jquery.gmap.js" pw-append="bodyTag"></script> <script type="text/javascript" pw-append="bodyTag"> jQuery(document).ready(function($){ ... }); </script> Not so! Got lots of js errors and discovered the output had placed the scripts in the incorrect order, ie:
      <script type="text/javascript" pw-append="bodyTag"> jQuery(document).ready(function($){ ... }); </script> <script id="localMapsJS" type="text/javascript" src="/site/assets/mytheme/js/jquery.gmap.js"></script> <script id="googlemapskey" type="text/javascript" src="https://maps.google.com/maps/api/js?key=XXXXXXXXXXXXXXXXXXXXXX"></script> In other places I've appended multiple HTML regions to the same tag and it's worked fine. It only happens with scripts.
      After trying a few things, I discovered a workaround which was to wrap all the scripts into one div which is then appended to the body tag. This is OK but not ideal. I think (?), the partial is rendered in its entirety before being appended to the body tag:
      <div pw-append="bodyTag"> <script id="googlemapskey" type="text/javascript" src="https://maps.google.com/maps/api/js?key=XXXXXXXXXXXXXXXXXXXXXX"></script> <script id="localMapsJS" type="text/javascript" src="<?=$bootstrap?>js/jquery.gmap.js"></script> <script type="text/javascript" pw-append="bodyTag"> jQuery(document).ready(function($){ ... }); </script> </div> Curious to know where I went wrong in the first example with each script appended individually or is this behaviour with scripts an undocumented feature of regions?
      Using PW 3.0.61 with both Chrome and Firefox
    • By louisstephens
      I have been scratching my head on this one for a while, so I thought maybe someone could shed some light on this issue. I am using a grid layout (that I have created over the years) with a class for responsive images (very similar to bootstrap, but very stripped down). Using this, I created a gallery using a foreach loop, and included a "print button" to print each image. I got the classes and everything worked out, but I ran into a small problem with the print functionality. My images (which are around 2400px wide to fill the space) are just fine in the grid and on resize, but when I print, they "run off" the page. I understand that they are just too big to be printed in portrait mode, which led to me think that I could use $image->size(); to print a scaled down version of the image (which adds a bit more load time as now the site needs to load the image large scale and the scaled down version). However, I can't seem to wrap my head around serving just the scaled down version for print only (obviously display:none; doesn't do the trick). Has anyone tackled this before, or does anyone know of a more elegant solution to the conundrum that I have found myself in?
      The Foreachloop:
      $printclass = 1; foreach($page->galleries as $gallery) { $printclass++; $printimage = $gallery->gallery_image->width(600)->url; $out = ""; $out .= "<div class=\"row\">"; $out .= "<div class=\"grid-12\">"; $out .= "<img src=\"{$gallery->gallery_image->url}\" class=\"reimage\"/>"; $out .= "</div>"; $out .= "</div>"; $out .= "<div class=\"row\">"; $out .= "<div class=\"grid-12\">"; $out .= "<a href=\"#\" onClick=\"printCoupon('printable{$printclass}');\">Print</a>"; $out .= "</div> "; $out .= "</div> "; $out .="<div id=\"printable{$printclass}\"><img src=\"{$printimage}\"/></div>"; echo $out; }  
       
    • By cosmicsafari
      Hi All,
      I was playing around with the settings for various templates as I had created a new role and have inadvertantly locked myself out.
      I changed some of the settings on the Admin template, so I assume this is what has caused the lock out.
      I have direct access to the database but I have no idea what I would need to change in it to regain access.
      Probably also worth mentioning that all the existing pages are still accessible, but /processwire throws a 404.
    • By Martin Muzatko
      Hello!
      I'm trying to use the data I create in Processwire as much as possible.
      So for a form, I try to use the fields description, name and also its built-in validation rules I defined in ProcessWire on the front-end. (minlength, ranges, patterns, etc)
      I already looked into this tutorial, but it is using external resources to validate the form.
      Since ProcessWire does all the heavy lifting, when processing data, I don't have to sanitize anything - ___processInput should do the job just fine.
      However, it is not actually working correctly. 
      $fields = $templates->get('user')->fields; $submission = $input->post; foreach ($submission as $key => $value) { $field = $fields->{$key}; if ($field instanceof Field) { $field = $field->getInputfield($user); $field->___processInput(new WireInputData([$key => $value])); var_dump($field->getErrors(true)); // retrieve validation error } } This works for some constraints, but the values are not correctly validated.
      Example: 

      All the fields are required and zip is an integer field.
      Yet, I get no validation error for zip, although it was entered as a string, and not an integer. Funny enough: if I provide a number outside the range, I get "Specified value 2 removed because it is out of bounds (min=1000, max=99999)".
      firstname will not return any error for being a required field.
      From what I have looked through the source code, there is no check for "required". Some fields only validate on setAttribute. Am I missing anything or am I doomed to build my own validation process?
      Thank you in advance!
      Best,
      Martin