Jump to content

Module: FieldtypeConcatenate


ryan

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

Link to comment
Share on other sites

  • 2 months later...

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
Link to comment
Share on other sites

  • 3 weeks later...
  • 3 weeks later...

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.

Link to comment
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
Link to comment
Share on other sites

  • 4 months later...

@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
Link to comment
Share on other sites

  • 1 month later...

@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?

Link to comment
Share on other sites

  • 2 years later...

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!

Link to comment
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
Link to comment
Share on other sites

  • 2 weeks later...
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!

Link to comment
Share on other sites

  • 3 months later...
  • 1 year later...

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.

Link to comment
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
Link to comment
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.

Link to comment
Share on other sites

  • 2 years later...

Fantastic little module, and I especially like the “magic” that happens when certain interpolated punctuation marks (“,”, “|”) are used between concatenated strings and one of the concatenated strings is blank: they’re left out! ?

Would it be simple to add an ellipsis (“”) to the list of characters so treated? My use case involves long paragraphs where I keep track of opening- and closing-words separately (in text fields), but I’d like to be able to represent the whole paragraph with

      Starting words concluding words.

Occasionally, there’s a very short paragraph, and I don’t want to imply that something has been left out (which an ellipsis, of course, does) — and in those unusual cases I include all of the text in the “starting words” field, leaving the “ending words” field empty. But (unlike with , and with |) the ellipsis shows up regardless.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...