Jump to content

Name Format Children


kixe

Recommended Posts

Hi @kixe or others who might be able to help me out,

I cannot seem to figure out something, I hope you can help. The children Pages – which need auto generated page names – have a Page Reference field called set_part_image. I would like its Title to be part of the name, like this (contrary to its name, it is NOT an image field!): 
date(Y-m-d_H-i-s) set_part_image.title

Meaning I need a time stamp like string followed by the title of that Page field. While this one works:
date(Y-m-d_H-i-s) set_part_image
generating something like: 2017-07-30_11-24-35-1053 where 1053 is the ID of the Page referenced by the field (of course), when using set_part_image.title the name is set to be untitled.

I also get the warning message: 
SetupPageName expects value in field 'set_part_image.title' to autogenerate Pagename

set_part_image.title DOES have a value filled in, so it should not be a problem for the module to get it.

I am using ProcessSetupPageName 2.0.8, BTW.

What am I doing wrong? Any Ideas? Thanks in advance!

Link to comment
Share on other sites

@szabesz I'm using a page reference field "countries.title"on name format for children without problem. What is your page field value type? I have it on "Single page Page or boolean false when none selected". Have you tried with ONLY set_part_image.title on the name format to see if it works? Make sure that you're using the template's Name format for children and NOT the Automatic Page Name Format of a Page Table.

  • Like 3
Link to comment
Share on other sites

1 hour ago, PWaddict said:

What is your page field value type? I have it on "Single page Page or boolean false when none selected".

Bingo! Thanks a lot @PWaddict. Of course it does make a difference whether it is a PageArray or a Page. In my case I need to stick to a PageArray but obviously set_part_image.title is not what I need. "Luckily" set_part_image.first.title does work, meaning the issue is solved!

On a side note, I need a PageArray because the InputField Type is Visual Page Selector which currently supports PageArrays only.

Cheers,

Edited by szabesz
typo
  • Like 2
Link to comment
Share on other sites

One more question regarding generated page names: currently different values referenced in "Name format children" are concatenated by a dash character separating them. Can I somehow use underscore instead?

That way I could easily tell the various values apart even in the generated name.

Link to comment
Share on other sites

21 hours ago, szabesz said:

That way I could easily tell the various values apart even in the generated name.

Since I am dealing with children of PageTables which do not need any public names/urls I use the title instead which is much more meaningful anyway. I realized that I do not even need this module for what I want to achieve. It just seemed convenient at first sight to use it, instead I switched to using my own hook in order to do whatever I need.

Link to comment
Share on other sites

  • 11 months later...

@kixe The 175 line of the module is causing the issue:

if (wire('fields')->get($format) && wire('fields')->get($format)->type instanceof FieldtypeOptions) $value = $page->get($format)->get('value|title');

I had to change this to this in order to get the title of the options field:

if (wire('fields')->get($format) && wire('fields')->get($format)->type instanceof FieldtypeOptions) $value = $page->get($format)->title;

 

Additional languages for the options field are ignored cause I'm only getting the default one for all page names.

Please check it out and update the module. Thanks.

Link to comment
Share on other sites

  • 3 months later...

The idea is to generate the page name from field values and not from labels. I will not change this. But I added support for dot syntax for the options fieldtype which should feed your needs.
 

// no fallback to default language if not set. Options should be populated in each language

my_options_field.title
my_options_field.value
my_options_field.id

// always fallback to default language. If values are set pagename is pulled from the value, otherwise from title

my_options_field

 

  • Thanks 1
Link to comment
Share on other sites

  • 2 months later...

i'm getting errors when this module is installed, using the latest version of PW. Had to uninstall it to remove the error; this is ok in my situation as i wasn't doing anything complex; but would be good to see if this can be fixed somehow.. TIA

Admin_Bug_Reporting_Here_on_Elliott_Carter_Website___Trello.thumb.jpg.289871736bff01188fe9d621c9368e6e.jpg

Link to comment
Share on other sites

  • 2 weeks later...

I'm getting the same error with PW 3.0.62. I installed it, updated my parent template with the format I wanted to use and then went to create a child page.

I got the error, uninstalled the module as suggested by Macrura and refreshed the page I was trying to create and got redirected to page/edit/?id=XXXX&new=1 and it had created the name/title in the format I'd specified.

Now I can create more child pages which automatically skip the add new page and have the expected name/title format, even though the module is no longer installed.

Link to comment
Share on other sites

  • 2 months later...

@kixe can you please update the module to display the warning "SetupPageName expects value in field 'my_field' to autogenerate Pagename" ONLY on debug mode? It's not user friendly and it can confuse site editors who have no idea about these stuff as it displayed instantly when adding a new page.

Replacing the 236 line with this would do the trick:

if ($warning === true) $this->warning(sprintf($format_warning, $format), Notice::debug);

 

Link to comment
Share on other sites

On 1/29/2019 at 11:58 PM, Macrura said:

i'm getting errors when this module is installed, using the latest version of PW. Had to uninstall it to remove the error; this is ok in my situation as i wasn't doing anything complex; but would be good to see if this can be fixed somehow.. TIA

Confirmed, same error using PW  3.0.123 and 2.1.3 module version, in my case still doesn't work even after uninstalled the module.

Fatal Error: Uncaught Error: Call to a member function get() on null in ...\site\assets\cache\FileCompiler\site\modules\ProcessSetupPageName\ProcessSetupPageName.module:129
Stack trace:
#0 ...\site\assets\cache\FileCompiler\site\modules\ProcessSetupPageName\ProcessSetupPageName.module(298): ProcessSetupPageName->createFromFormat(Object(ProcessWire\Page), 'parent.title')
#1 ...\wire\core\Wire.php(386): ProcessSetupPageName->___SetupPageName(Object(ProcessWire\Page), Array)
#2 ...\wire\core\WireHooks.php(723): ProcessWire\Wire->_callMethod('___SetupPageNam...', Array)
#3 ...\wire\core\Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessSetupPageName), 'SetupPageName', Array)
#4 ...\site\assets\cache\FileCompiler\site\modules\ProcessSetupPageName\ProcessSetupPageName.module(93): ProcessWire\Wire->__call('SetupPageName', Array)
#5 ...\wire\core\WireHooks.php(813): ProcessSetupPageName->{closure}(Object(ProcessWire\HookEv (line 129 of ...\site\assets\cache\FileCompiler\site\modules\ProcessSetupPageName\ProcessSetupPageName.module) 

 

 

Link to comment
Share on other sites

  • 1 month later...

@jonassalen, open the ProcessSetupPageName.module file in your code editor and try replacing this section at the top of the createFromFormat() method...

if ($languageID == null && $this->languageSupport == true) $languageID = $this->wire('languages')->getDefault()->id;
$langID = $this->wire('languages')->get($languageID)->isDefault()? null : $languageID;

if ($this->languageSupport) {
	$userLang = $this->wire('user')->language;
	$this->wire('user')->language = $this->wire('languages')->get($languageID);
}

...with...

$langID = null;
if ($this->languageSupport) {
	if ($languageID == null) $languageID = $this->wire('languages')->getDefault()->id;
	$langID = $this->wire('languages')->get($languageID)->isDefault()? null : $languageID;
	$userLang = $this->wire('user')->language;
	$this->wire('user')->language = $this->wire('languages')->get($languageID);
}

 

  • Like 3
Link to comment
Share on other sites

@Robin S thanks for that! That got the basic functions of the module to work for me.

I may be missing something, but is part of the function of this module to give the child pages titles as well as names? The names are working, but the page titles are not being constructed according to the naming convention I'm assigning via the module.

Link to comment
Share on other sites

On 7/6/2019 at 5:47 AM, thistimj said:

I may be missing something, but is part of the function of this module to give the child pages titles as well as names?

No, I don't think the module sets page titles. I was expecting something similar using the core "Name format for children" feature, but if you want to automatically set a title you have to use a hook. It's discussed in the topic below:

 

Link to comment
Share on other sites

  • 8 months later...
On 7/2/2019 at 12:27 AM, Robin S said:

@jonassalen, open the ProcessSetupPageName.module file in your code editor and try replacing this section at the top of the createFromFormat() method...


if ($languageID == null && $this->languageSupport == true) $languageID = $this->wire('languages')->getDefault()->id;
$langID = $this->wire('languages')->get($languageID)->isDefault()? null : $languageID;

if ($this->languageSupport) {
	$userLang = $this->wire('user')->language;
	$this->wire('user')->language = $this->wire('languages')->get($languageID);
}

...with...


$langID = null;
if ($this->languageSupport) {
	if ($languageID == null) $languageID = $this->wire('languages')->getDefault()->id;
	$langID = $this->wire('languages')->get($languageID)->isDefault()? null : $languageID;
	$userLang = $this->wire('user')->language;
	$this->wire('user')->language = $this->wire('languages')->get($languageID);
}

 

Sorry for not looking in here. I replaced the code as recommended by @Robin S without further testing and hope it works well now. I didn't use the module by myself for a long time. Stay healthy!

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

Very cool module @kixe.

Would it be hard to implement date formatting for custom datetime fields instead of just PW's built in "date" field?

Setting up an event planner over here, where every event has a event_date field (datetime) that I'm trying to prepend to the event's url slug (or name in PW's terminology ?).

If i use "event_date title" as the name format it works, if i try "event_date(Y-m-d) title" I get an error:

Quote

Error: 'Name Format Children' in settings of template 'location'. Unknown property, field or subfield: 'event_date(Y-m-d)'

Currently working around the issue by changing the field's output formatting directly, but I was wondering if that would be a feature that might come in handy in the future.

Cheers and happy easter!

Link to comment
Share on other sites

  • 10 months later...

Thanks for the module - I had to change this

COLLATE utf8_general_ci

to this though

 

COLLATE utf8mb4_general_ci

because it errored when I created pages due to my database setup. Not sure if there's a way to check the character set of the DB or something and set that bit accordingly?

Link to comment
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
×
×
  • Create New...