This site uses cookies and similar technologies.

If you don't change browser settings, you agree to it.

I understand
12 Posts
stevemoss
1 year ago
6
Topic

I am trying to do the following query within a select dynamic field:

SELECT refresher_period as value, refresher_period as text
FROM #__cck_store_join_seb_site_training
WHERE site_id=$site->id
AND course_id=$config['pk']
ORDER BY text

But I don't seem to be able to access the $config variable? I can access the $uri variable it seems, but this only works to retrieve the value when displaying/editing the form, and not when trying to use the field in a list and search, but I need to access it in both circumstances.

Get a Book for SEBLOD
12 Posts
stevemoss
1 year ago
5
Level 1

I've just looked at the code here. It seems I can use $uri, $context, $user and $site, as well as any J(STRING). Are there any plans to expand this to make $fields and $config available also?

4229 Posts
Kadministrator
1 year ago
4
Level 2

In forms field don't have any values so this doe not make sense, fields become values only after form is saved.

12 Posts
stevemoss
1 year ago
3
Level 3

Thanks for the info.

I added the following code to the replaceLive function to make $config accessible, but it doesn't appear to be working as expected in the list/search view?

if ( $str != '' && strpos( $str, '$config' ) !== false ) {
  $matches     =   '';
  $search       =   '#\$config\[\'([a-zA-Z0-9_]*)\'\]#';
  preg_match_all( $search, $str, $matches );
  if ( count( $matches[1] ) ) {
    foreach ( $matches[1] as $k=>$v ) {
      $v2     =   ( isset( $config[$v] ) ) ? $config[$v] : '';
      $str   =   str_replace( $matches[0][$k], $v2, $str );
    }
  }
}

 When I do a dump($str); it seems to be replacing with the correct values, however, e.g.:

SELECT refresher_period as value, refresher_period as text
FROM #__cck_store_join_seb_site_training
WHERE site_id=505
AND course_id=1426 ORDER BY text

Any thoughts?

12 Posts
stevemoss
1 year ago
2
Level 4

This was due to the field I was using not having a storage location in the database. I managed to work around this by using a join and query in the search and a free text field to retrieve the variable from the search in the search form. Thanks to Olivier Nolbert for the direction on this.

12 Posts
stevemoss
1 year ago
1
Level 5

I have created a PR with the changes mentioned above here.

1223 Posts
Bucklash
1 year ago
0
Level 6

Very Nice!

Get a Book for SEBLOD