Skip to content

Refactor fields.inc to be configuration only (CFM-218) #342

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

arlen
Copy link
Contributor

@arlen arlen commented Sep 18, 2025

No description provided.

]
],
'SUBTITLE' => [
Copy link
Contributor Author

@arlen arlen Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a convention used to insert an h3 subtitle between groups of fields. It looks like this:

'SUBTITLE' => [
    'subtitle' => __d('api_connector', 'field.ApiSources.push_mode')
  ]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is documented in the Registry Wiki

// By default, the form will POST to the current controller
// Note we need to open the form for view so Cake will autopopulate values
print $this->Form->create($vv_obj);
if(!empty($vv_alternate_template)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The controller can assert $vv_alternate_template to have a non-standard template inserted here. It will be rendered without the standard form (but one could be included in the alternate template). This is currently used to render the Petition view.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is documented in the Registry Wiki

// We will output the standard Form (for add, edit, and view).
// By default, the form will POST to the current controller.
// Note we need to open the form for view so Cake will autopopulate values.
if($this->Field->includesFileField($fields)) {
Copy link
Contributor Author

@arlen arlen Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a simple test for whether or not we have a file field. If we do, we have to change the form encoding type to multipart/form-data. The function that does this (in FieldHelper) assumes we'll know the exact level of the configuration in the $fields[] array since this will be (marginally) faster than doing a recursive search through the whole array. We do this generically to support future plugins (and probably themes). At the moment, we only use a file field for SSH Key upload.

@@ -26,10 +26,18 @@
*/

// This view does currently not support read-only
Copy link
Contributor Author

@arlen arlen Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were numerous fields.inc files (particularly in plugins) that locked down the fields exclusively to "edit". Where this test existed, I left it in - returning when $vv_action !== 'edit'.

Do we want to keep these or remove them? This looks like:

// This view only supports edit
if($vv_action !== 'edit') {
  return;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove these

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All such references have been removed.

]
]
];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approach taken here to set up the verification_code_charset field in the beforeField block will not work because the php here is no longer being generated inside Cake's form element. We need to find a different way to accommodate what we are trying to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fixed.

'postal_code',
'country',
'type_id' => [
// XXX fix fieldOptions - just make this flat
Copy link
Contributor Author

@arlen arlen Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to flatten the fieldOptions sub-array, and list its elements at the top level. (We did this in Match.) That has not yet been done here.

So this structure:

'type_id' => [
  // XXX fix fieldOptions - just make this flat
  'fieldOptions' => [
    'default' => $vv_default_type
  ]
]

would become this structure:

'type_id' => [
  'default' => $vv_default_type
]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All references to 'fieldOptions' in fields.inc files have been removed and its sub-elements flattened upward. Note that references to 'fieldOptions' remain in specialized (non-standard) templates where elements are called directly, such as in app/plugins/CoreEnroller/templates/InvitationAccepters/dispatch.inc.

// Include fields configuration for the form. This will typically include the $fields array.
$fields = []; // Backstop the fields array: some configs have no fields.
$fieldsFile = "fields.inc"; // This is the default.
if(file_exists($templatePath . DS . 'fields-' . $vv_action . '.inc')) {
Copy link
Contributor Author

@arlen arlen Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a new convention:

if(file_exists($templatePath . DS . 'fields-' . $vv_action . '.inc')) {
  // We have an action file override in the form of "fields-ACTION.inc". Use it.
  $fieldsFile = 'fields-' . $vv_action . '.inc';
}

This allows us to follow a general convention for non-standard actions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is documented in the Registry Wiki.

@@ -74,6 +75,24 @@ public function initialize(array $config): void {
$this->setPrimaryLink(['external_identity_source_id']);
$this->setRequiresCO(true);

// All the tabs share the same configuration in the ModelTable file
// XXX Reenable when this doesn't throw an error (same error as https://todos.internet2.edu/browse/CFM-475 )
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I attempted to add the subnavigation for API Sources config similar to File Sources, Sql Sources (etc). When this block is included it throws an error similar to what we see in https://todos.internet2.edu/browse/CFM-475

@arlen arlen force-pushed the feature-cfm218-fieldsIncConfigOnly branch 2 times, most recently from 984681b to 46b3261 Compare September 23, 2025 17:57
@arlen arlen changed the title Refactor fields.inc to be configuration only - first pass. (CFM-218) Refactor fields.inc to be configuration only (CFM-218) Sep 24, 2025
@arlen arlen marked this pull request as ready for review September 24, 2025 18:26
@arlen arlen requested review from Ioannis and benno September 24, 2025 18:26
@arlen arlen force-pushed the feature-cfm218-fieldsIncConfigOnly branch from 29c718b to 620cdf5 Compare October 7, 2025 14:40
* @return bool
* @since COmanage Registry v5.2.0
*/
function includesFileField(array $array): bool {
Copy link
Contributor

@Ioannis Ioannis Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arlen add missing public access modifier

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to both new functions - thanks!

@arlen arlen force-pushed the feature-cfm218-fieldsIncConfigOnly branch from 0e2698b to 1856b00 Compare October 21, 2025 19:01
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants