Jump to content

Limiting subfields for InputfieldSelector


MarkE
 Share

Recommended Posts

The InputfieldSelector module documents the property 'limitFields'. This property is very useful as it enables you to present the user with only the fields you want them to use. Not documented (as far as I can see) is that you can also limit subfields by use of a dot - e.g. 'field.subfield'. This is also really useful. However, it does not seem to operate with parent, which is where it would be really really useful.

There is a subtle line in the module (line 915 in my version 3.0.239):

if($name === 'parent' && empty($selected)) continue; // we only show "parent." unless "parent" it was somehow already selected

It looks like it is trying to prevent the use of parent in limitFields UNLESS it has a subfield. I'm not quite sure why, but in any case in practice it seems to eliminate both 'parent' and 'parent.xxx' (presumably the dot got stripped somewhere - I haven't investigated closely). If I comment out the line then parent will be included in the field selection, but subfield selection is not possible, so clearly something else is going on as well).

Is this a bug, or am I missing something?

Link to comment
Share on other sites

Still struggling with this. It seems like just including 'parent.' (notice the dot) in the limitFields will show parent as an option. HOWEVER, the subfield options are then the same (main) field names as those that are in limitFields, which obviously makes no sense in the context of the parent. Using parent.subfield has no effect.

Link to comment
Share on other sites

Solution?

I do think the InputfieldSelector module needs enhancing.

What I have done is to add the following:

after line 841:

if($settings['limitFields']) $this->set('limitFields', $settings['limitFields']);

after line 915 (line numbers are assuming line inserted as above):

if($name === 'parent' && isset($limitSubfields['parent'])) {
					$name = 'parent.';
				}

after (now) line 1516:

$limitSubfields = array();
			if(is_array($this->limitFields)) {
				foreach($this->limitFields as $limitField) {
					if(strpos($limitField, '.') === false) continue;
					if(strpos($limitField, $fieldName) !== 0) continue;
					list($limitField, $limitSubfield) = explode('.', $limitField);
					if($limitField) {
					} // ignore
					if($limitSubfield) $limitSubfields[$limitSubfield] = $limitSubfield;
				}
			}

(the above is a copy from elsewhere in the script so would probably be better as a new method)

after  (now) line 1535:

'limitFields' => $limitSubfields,

If anyone wants to play with that and let me know what they think, then that would be great. Otherwise, I'll just post it as an issue.

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
 Share

  • Recently Browsing   0 members

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