Search

I’m working on an extension that needs to look up all the configuration values for an instance of every field in a given section. I’ve noticed that in some field extensions (actually the first one I’ve looked at is Subsection Manager, because I assumed that would be relatively complex) run their own SQL queries with Database->fetchCol() rather than using the field’s get() method.

Am I correct in understanding that there would be no way for my extension to discover field configuration values that are handled with direct queries like this rather than with the field class’s methods?

Or would it be possible to run my own queries (rather than using field->get()) to get all the config values?

Or would it be possible to run my own queries (rather than using field->get()) to get all the config values?

What configuration do you need? The “core” config from sym_fields (label, required etc.), or the field’s additional config that gets stored in sym_fields_*type*? The problem with the latter is that this table has no set structure so cannot be queried easily without knowing the columns you want to get.

You should be able to achieve this with class methods with a two step approach:

$sm = new SectionManager(Administration::instance());
$section = $sm->fetch(1);
$fields = $section->fetchFields();

$field_id = 123;

foreach($fields as $field) {
    if(!$field->get('id') == $field_id) continue;
    echo('Handle: ' . $field->get('element_name'));
}

Ok, so could I get the fieldtype in a similar way, then use that to assemble a query on that fieldtype’s table (filtering it by the field ID)?

If you just want to get all the config values from a fields table, eg. sym_fields_select, you can just use $field-get() without any param which will return an array of columns.

'show_column' => string 'no' (length=2)
'id' => string '2' (length=1)
'label' => string 'Single' (length=6)
'element_name' => string 'single' (length=6)
'type' => string 'select' (length=6)
'parent_section' => string '1' (length=1)
'required' => string 'no' (length=2)
'sortorder' => int 1
'location' => string 'main' (length=4)
'field_id' => string '2' (length=1)
'allow_multiple_selection' => string 'no' (length=2)
'static_options' => string 'One, Two, Three' (length=15)
'dynamic_options' => null

Is that what you’re after?

You can pass a type to fetchFields if you’re looking to find something specific:

$fields = $section->fetchFields('checkbox');

But if you’re going to be filtering the returned array by the field ID anyway, there’s little point.

Ok, so that was much simpler than I thought it would be. Thanks guys!

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details