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

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.