Jump to content
ryan

Module: FieldtypeConcatenate

Recommended Posts

This is exactly what I was looking for! Thank you :)

I'm using it to create a custom "Label Field". However, it shows the ID, versus the title. Is there something I need to do to get it working when concatenating fields of the Page fieldtype? Or does it only support certain fieldtypes, like Text?

Dear Ryan,

I'm having the same issue as Lauren. I'd like it to concatenate the select value of a page type field.

The field is 'ip_type' and what shows up is the id of the page (e.g. 197), rather than the text value of the page (e.g. 'dedicated'),

which I've placed in a field called 'select_value'.

I also tried changing the ip_type field to use the 'title' field instead of select_value, but there was no change.

Thanks,

Peter

Share this post


Link to post
Share on other sites

How about ip_type.title?

Dear Arjen,

Zowie! Works perfectly! Thanks!

Note that with the concat syntax 'ip_type.title', the exclamation mark for formatting doesn't work.

But I don't think it's needed anyway.

Ryan, this would be good to add to the module notes.

Thanks again, Arjen.

Peter

Share this post


Link to post
Share on other sites

Thanks Peter, you may want to file an issue on GitHub since that's easier to manage for Ryan.

Share this post


Link to post
Share on other sites

I get an error

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db_snimi-sebe-sam.field_ad_header' doesn't exist

after adding a concat field to a template and trying to edit the field. The field is editable prior to adding it to the template. Running PW 2.5.18 on local xampp on windows. Am I doing something wrong or is it a bug?

Edit: Cannot even remove the field from the template (and cannot remove the field as I can't edit it)

Edited by Ivan Gretsky

Share this post


Link to post
Share on other sites

I get an error

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db_snimi-sebe-sam.field_ad_header' doesn't exist

I get the same error for 2.5.18. 

Share this post


Link to post
Share on other sites

Same error on  2.5.20

For me it's working after the update to 2.5.20, so maybe the update clear the cause of the issue. Can't say for sure as the installation is not managed by me.

Share this post


Link to post
Share on other sites

I am still seeing the "Base table or view not found" error. The field still works as expected because of course this fieldtype doesn't need a DB table, but the error should be dealt with. I'll post a Github issue.

Share this post


Link to post
Share on other sites

I saw Adrian's GitHub issue report and just pushed a fix to dev (core) for this. It was attempting to count the number of populated rows, and of course there can't be any. Now it checks to see if the Fieldtype lacks a table definition (schema) before attempting to count rows. I suppose this only affects FieldtypeConcat, but it's possible other Fieldtypes in the future may not need their own table for one reason or another. 

  • Like 1

Share this post


Link to post
Share on other sites

@Ryan: wire()->fields does not return id, name, path, url, template Fields.

I think these "system" fields should be checked separately.

See also https://github.com/ryancramerdesign/FieldtypeConcat/issues/6

So far I've added the following piece of code that works.

        $sys_fields = ['id', 'name', 'path', 'url', 'template'];

        foreach($sys_fields as $fname) {
            if(strpos($str, $fname) === false) continue;
            $s = $str . ' ';
            while(preg_match('/\b(' . $fname . '(\.[-_.a-zA-Z0-9]+)?)\b(!?)/', $s, $matches)) {
                $fieldName = $matches[1] . $matches[3];
                $lengths[$fieldName] = strlen($fieldName);
                $s = str_replace($fieldName, str_repeat('#', strlen($fieldName)), $s);
                if(strpos($s, $fname) === false) break; 
            }
        }
  • Like 1

Share this post


Link to post
Share on other sites

Done all that described but it's not showing when editing page.

Share this post


Link to post
Share on other sites

@Ryan: wire()->fields does not return id, name, path, url, template Fields.

I think these "system" fields should be checked separately.

See also https://github.com/ryancramerdesign/FieldtypeConcat/issues/6

So far I've added the following piece of code that works.

        $sys_fields = ['id', 'name', 'path', 'url', 'template'];

        foreach($sys_fields as $fname) {
            if(strpos($str, $fname) === false) continue;
            $s = $str . ' ';
            while(preg_match('/\b(' . $fname . '(\.[-_.a-zA-Z0-9]+)?)\b(!?)/', $s, $matches)) {
                $fieldName = $matches[1] . $matches[3];
                $lengths[$fieldName] = strlen($fieldName);
                $s = str_replace($fieldName, str_repeat('#', strlen($fieldName)), $s);
                if(strpos($s, $fname) === false) break; 
            }
        }

Thanks Valan,

This also worked for me when adding a concatenate field to the user template.

I presume the field is actually hidden on the page? Unless this is another bug within the user template only?

Share this post


Link to post
Share on other sites

I am trying this out in a json-ld setting and running into some trouble.

For json-ld I need the content of the whole article om any give page.

On this particular site we build pages with different fields, including matrix repeater fields.

2 problems, I see lots of markup like h2, span etc in the output, and the matrix repeater fields are not taken into consideration at all.

What I need is the unformatted output of all the individual fields, including from the repeater matrix to show up in a concatenated field.

Thanks!

Share this post


Link to post
Share on other sites
On 13/03/2018 at 5:07 AM, OllieMackJames said:

2 problems, I see lots of markup like h2, span etc in the output, and the matrix repeater fields are not taken into consideration at all.

What I need is the unformatted output of all the individual fields, including from the repeater matrix to show up in a concatenated field.

This fieldtype wont be suitable for what you want. Instead, add a hidden textarea field to your templates, then in a saveReady hook loop over the template fields and add markup-free text (use strip_tags) to the textarea. You'll need an if/else structure to handle all the different field types you want to support.

  • Like 2

Share this post


Link to post
Share on other sites
On 3/14/2018 at 7:30 AM, Robin S said:

This fieldtype wont be suitable for what you want. Instead, add a hidden textarea field to your templates, then in a saveReady hook loop over the template fields and add markup-free text (use strip_tags) to the textarea. You'll need an if/else structure to handle all the different field types you want to support.

@Robin S thanks, much appreciated!

Share this post


Link to post
Share on other sites

is there any way to easily concatenate the id and other hidden fields?

parent.child.id will output the id but i'm using it in a "multichild" context.

thanks!

Share this post


Link to post
Share on other sites

In a template i need to find all pages with a full name but the stored data is first name and surname. So from the doc it seams this module will not help (" you cannot directly query a Concat field from $pages->find(), for example.").

As i don't know where to ask, i dare to ask here: is there a way to achieve the above by some PW magic, something like concatenation of fields $pages->find('concat("firstname surname")='.$fullname), where $fullname could be for example "Paul van Ripper" so guessing where the surname starts would inevitably lead to mistakes.

Share this post


Link to post
Share on other sites
49 minutes ago, loukote said:

In a template i need to find all pages with a full name but the stored data is first name and surname.

The simple solution is to create a new text field "full_name" and add it to your template. Set the visibility to "Hidden (not shown in the editor)".

In /site/ready.php:

$pages->addHookAfter('saveReady', function(HookEvent $event) {
	$page = $event->arguments(0);
	if($page->template == 'your_template') {
		$page->full_name = $page->first_name . ' ' . $page->last_name;
	}
});

You'll need to save all the pages once to populate the full_name field - if there are a lot then use the API to loop over the pages and save them.

Now you can search the full_name field.

  • Like 3

Share this post


Link to post
Share on other sites
12 hours ago, Robin S said:

addHookAfter()

This sounds like a solution that would work. I still wonder whether it is the way to go as i creates a dependency elsewhere, thus a need for a proper documentation. And also because the impacted template is a system template... Anyway, thank you @Robin S.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...