We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Undefined indexes when loading field settings in different content type

Developer Preview

Low's avatar
Low
407 posts
10 years ago
Low's avatar Low

When I instantiate a new Checkboxes class (using the low_variables content type) and try to call the display_settings(), I get these errors:

Notice

Undefined index: field_fmt

ee/EllisLab/Addons/checkboxes/ft.checkboxes.php, line 335

Notice

Undefined index: field_pre_populate

ee/EllisLab/Addons/checkboxes/ft.checkboxes.php, line 349

Notice

Undefined index: field_list_items

ee/EllisLab/Addons/checkboxes/ft.checkboxes.php, line 353

Notice

Undefined index: field_pre_populate

ee/EllisLab/Addons/checkboxes/ft.checkboxes.php, line 361

Notice

Undefined index: field_pre_channel_id

ee/EllisLab/Addons/checkboxes/ft.checkboxes.php, line 366

Notice

Undefined index: field_pre_field_id

ee/EllisLab/Addons/checkboxes/ft.checkboxes.php, line 366

These settings don’t have a default, apparently. What’s the best way to avoid this? Should fieldtypes have default settings for fallback? Or should I be approaching this in a different manner?

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
10 years ago
Kevin Cupp's avatar Kevin Cupp

Sorry about that, fieldtypes should have defaults. The next build will have defaults for these settings forms so you shouldn’t see these errors anymore, but let us know if you run into any more.

       
Low's avatar
Low
407 posts
10 years ago
Low's avatar Low

Getting the same errors for the Multi Select and Radio Buttons fields.

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
10 years ago
Kevin Cupp's avatar Kevin Cupp

Yep, got those, plus the Select field.

       
Low's avatar
Low
407 posts
10 years ago
Low's avatar Low

When saving settings for a File field, I’m getting:

Notice
Undefined index: field_content_type
ee/EllisLab/Addons/file/ft.file.php, line 710
Severity: E_NOTICE

Notice
Undefined index: allowed_directories
ee/EllisLab/Addons/file/ft.file.php, line 711
Severity: E_NOTICE

Notice
Undefined index: show_existing
ee/EllisLab/Addons/file/ft.file.php, line 712
Severity: E_NOTICE

Notice
Undefined index: num_existing
ee/EllisLab/Addons/file/ft.file.php, line 713
Severity: E_NOTICE

The save_settings method looks at the given data. Should I pass through the entire POST, or should the fieldtype check for data and then fall back to POST data?

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
10 years ago
Kevin Cupp's avatar Kevin Cupp

Our current practice has been to pass in POST. Grid does the same thing, but kind of more intelligently only sends the relevant settings fields.

       
Low's avatar
Low
407 posts
10 years ago
Low's avatar Low

Passing the entire POST seems a bit unnecessary when you can just check for POST values in the method, right? Wouldn’t something like this be more stable in different scenarios?

$some_val = isset($data[$some_key]) ? $data[$some_key] : ee('Request')->post($some_key, $default_val);
       
Kevin Cupp's avatar
Kevin Cupp
791 posts
10 years ago
Kevin Cupp's avatar Kevin Cupp

Yes, it probably is unnecessary, that’s why Grid trims it down a bit. Yes, it would be more stable in different scenarios, but it sure is great when things are consistent across scenarios. This doesn’t look attractive to set as a standard for all fieldtypes.

       
Low's avatar
Low
407 posts
10 years ago
Low's avatar Low

Well, if you’re already going to provide defaults, then it would be easy (and elegant) to loop through default key/value pairs and check POST for those.

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
10 years ago
Kevin Cupp's avatar Kevin Cupp

I think keeping the consistency is more elegant.

       
Low's avatar
Low
407 posts
10 years ago
Low's avatar Low

We obviously have different ideas about what we consider elegant.

You already stated Grid receives slightly different data than the POST, so that’s not consistent. Also, adding checks in all fields would be consistent and less error prone. That, to me, is elegant.

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
10 years ago
Kevin Cupp's avatar Kevin Cupp

The Grid array is more of a convenience so the developer doesn’t have to dig into a nested POST array for their settings. So yes, while it’s technically inconsistent, the developer experience is much better. If they ever end up needing more easily-accessible data in that array (hasn’t happened yet), it’s easy to add it to the existing array (where they expect) without them needing to change how they access that data with long ternaries, as you’re suggesting

Yes, adding checks in every field would technically be “consistent,” but I’m talking about the method to which you access your settings. That would suddenly become inconsistent and you would need to tell all the developers who want to make fieldtypes for your add-on to pull from POST and the $data array. It’s only “error prone” if the implementer of the content type wants to choose an inconsistent way of passing data to the fieldtype. You’re creating the errors then asking others to accommodate you.

Yes, obviously different ideas about elegance.

       
Low's avatar
Low
407 posts
10 years ago
Low's avatar Low

Well, it’s your prerogative to do whatever you want. I don’t agree with your stance here, but I’ll work with it.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.