Skip to content

Restructure CoreEnroller for top-level form generation (CFM-218) #358

Merged
merged 4 commits into from
Dec 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ $this->Field->enableFormEditMode();
]
);

print $this->element('form/listItem', [
print $this->element('CoreEnroller.listItem', [
'arguments' => [
'fieldName' => 'comment',
'fieldOptions' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ $this->Field->enableFormEditMode();
</li>

<?php
print $this->element('form/listItem', [
print $this->element('CoreEnroller.listItem', [
'arguments' => [
'fieldName' => 'mail',
'fieldOptions' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if($vv_action == 'dispatch') {
// Make the Form fields editable
$this->Field->enableFormEditMode();

print $this->element('form/listItem', [
print $this->element('CoreEnroller.listItem', [
'arguments' => [
'fieldName' => 'accepted',
'fieldLabel' => __d('operation','accept.invitation'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

print __d('core_enroller', 'information.EmailVerifiers.code_sent', [$vv_verify_address]);

print $this->element('form/listItem', [
print $this->element('CoreEnroller.listItem', [
'arguments' => [
'fieldName' => 'code',
'fieldLabel' => __d('field', 'code'),
Expand Down
2 changes: 1 addition & 1 deletion app/plugins/CoreEnroller/templates/element/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,5 @@
'formArguments' => $formArguments
]),
// Default use case
default => $this->Field->getElementsForDisabledInput('form/listItem', $formArguments)
default => $this->Field->getElementsForDisabledInput('CoreEnroller.listItem', $formArguments)
};
75 changes: 75 additions & 0 deletions app/plugins/CoreEnroller/templates/element/fieldDiv.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/**
* COmanage Registry Field Div Element for CoreEnroller
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link https://www.internet2.edu/comanage COmanage Project
* @package registry
* @since COmanage Registry v5.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/


declare(strict_types = 1);
?>

<div class="field">
<?php
// Name Div
print $this->element('form/nameDiv');

// This configuration isn't necessary anymore.
if(isset($vv_field_arguments['fieldDescription'])) {
unset($vv_field_arguments['fieldDescription']);
$this->set('vv_field_arguments', $vv_field_arguments);
}

// Info Div
?>
<div class="field-info">
<?php
// Insert the beforeField supplement:
if(!empty($vv_before_field)) {
print $vv_before_field;
}

// Include the correct sub-element based on the field configuration
if(isset($vv_field_arguments['fieldPrefix'])) {
print $this->element('form/infoDiv/withPrefix');
} elseif(isset($vv_field_arguments['autocomplete'])) {
print $this->element('form/infoDiv/autocomplete');
} elseif(isset($vv_field_arguments['status'])) {
print $this->element('form/infoDiv/status');
} elseif(isset($vv_field_arguments['groupedControls'])) {
print $this->element('form/infoDiv/grouped');
} elseif(isset($vv_field_arguments['entity'])) {
print $this->element('form/infoDiv/source');
} elseif(isset($vv_field_arguments['groupmember'])) {
print $this->element('form/infoDiv/groupMember');
} else {
print $this->element('form/infoDiv/default');
}

// Insert the afterField supplement:
if(!empty($vv_after_field)) {
print $vv_after_field;
}
?>
</div>
</div>
88 changes: 88 additions & 0 deletions app/plugins/CoreEnroller/templates/element/listItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
/**
* COmanage Registry Unordered List Element for CoreEnroller
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link https://www.internet2.edu/comanage COmanage Project
* @package registry
* @since COmanage Registry v5.2.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/


declare(strict_types = 1);

// Make the element configuration available downstream
// XXX Unfortunately CAKEPHP doe not create a viewvar space for the element
// parameters. As a result we do not know which one is which unless we:
// - add a prefix and create a namespace
// - wrap them in an array.
// We choose the latter.
$this->set('fieldName', $arguments['fieldName']);
$fieldName = $arguments['fieldName'];
$this->set('vv_field_arguments', $arguments);

// Pass along the field supplements if they are configured.
$this->set('vv_before_field', $beforeField ?? '');
$this->set('vv_after_field', $afterField ?? '');

// If an attribute is frozen, inject a special link to unfreeze it, since
// the attribute is read-only and the admin can't simply uncheck the setting
if($fieldName == 'frozen' && $this->Field->getEntity()->frozen) {
$url = [
'label' => __d('operation', 'unfreeze'),
'url' => [
'plugin' => null,
'controller' => \App\Lib\Util\StringUtilities::entityToClassname($this->Field->getEntity()),
'action' => 'unfreeze',
$this->Field->getEntity()->id
]
];
$arguments = [
...$arguments,
'status' => __d('field', 'frozen'),
'link' => $url,
];
$this->set('vv_field_arguments', $arguments);
}

// If an attribute is a plugin, return the link to its configuration
if($fieldName == 'plugin' && $vv_action == 'edit') {
$url = [
'label' => __d('operation', 'configure.plugin'),
'url' => [
'plugin' => null,
'controller' => \App\Lib\Util\StringUtilities::entityToClassname($this->Field->getEntity()),
'action' => 'configure',
$this->Field->getEntity()->id
]
];
$arguments = [
...$arguments,
'status' => $this->Field->getEntity()->$fieldName,
'link' => $url,
];
$this->set('vv_field_arguments', $arguments);
}

?>

<li class="<?= trim($this->Field->calculateLiClasses()) ?>">
<?= $this->element('CoreEnroller.fieldDiv')?>
</li>
68 changes: 68 additions & 0 deletions app/plugins/CoreEnroller/templates/element/unorderedList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* COmanage Registry Unordered List Element for CoreEnroller
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link https://www.internet2.edu/comanage COmanage Project
* @package registry
* @since COmanage Registry v5.2.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/


declare(strict_types = 1);

// View vars
// $vv_obj
// $vv_required_fields
// $vv_action
// $vv_fields_inc
// $vv_template_path
// $vv_field_types
// $vv_submit_button_label

?>
<ul id="<?= $vv_action . '_' . $this->name ?>" class="fields form-list">
<?php
// We allow the fields.inc file to be specified for Controllers that have more
// complicated/non-default actions.
// XXX Each fields.inc file will calculate and provide the hidden controls.
$fieldsFile = $vv_fields_inc ?? 'dispatch.inc';
// The controller will calculate the template path for us, since it could be
// in one of several paths if we are in a plugin context.
// The include files will contain the listItem elements
include($vv_template_path . DS . $fieldsFile);

if(!isset($suppress_submit) || !$suppress_submit) {
// The Submit element will be printed only if we are adding or updating, and if not
// suppressed by the field configuration
$vv_submit_button_label = $vv_submit_button_label ?? __d('operation', 'save');
print $this->element('form/submit', ['label' => $vv_submit_button_label]);
}
?>
</ul>

<?php
// Import all the hidden fields in the Form
if(!empty($hidden)) {
// Inject any hidden variables set by the included file
foreach($hidden as $attr => $v) {
print $this->Form->hidden($attr, ['value' => $v]);
}
}
8 changes: 2 additions & 6 deletions app/src/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,10 @@ public function getCOID(): ?int {
*/
public function getCurrentTable(): \Cake\ORM\Table
{
/** @var string $modelsName */
$modelsName = $this->getName();
$plugin = $this->getPlugin();

$alias = $this->getPlugin() !== null
? $this->getPlugin() . '.' . $modelsName
: $modelsName;

return $this->fetchTable($alias);
return $this->fetchTable(StringUtilities::getQualifiedName($plugin, $modelsName));
}


Expand Down
2 changes: 1 addition & 1 deletion app/src/Controller/StandardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ public function index() {
$this->set('vv_permission_set', $this->RegistryAuth->calculatePermissionsForResultSet($resultSet));

// Default index view title is model name
[$title, , ] = StringUtilities::entityAndActionToTitle($resultSet, $modelsName, 'index');
[$title, , ] = StringUtilities::entityAndActionToTitle(null, $modelsName, 'index');
$this->set('vv_title', $title);

// Let the view render
Expand Down
44 changes: 39 additions & 5 deletions app/src/Controller/StandardEnrollerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,45 @@ public function beforeRender(\Cake\Event\EventInterface $event) {

if(!empty($link->value)) {
$currentTable = $this->getCurrentTable();
$efsTable = $currentTable->getAssociation('EnrollmentFlowSteps')->getTarget();

$this->set('vv_bc_parent_obj', $efsTable->get($link->value));
$this->set('vv_bc_parent_displayfield', $efsTable->getDisplayField());
$this->set('vv_bc_parent_primarykey', $efsTable->getPrimaryKey());
// Not all enroller plugin tables have a direct EnrollmentFlowSteps association
if (method_exists($currentTable, 'hasAssociation')
&& $currentTable->hasAssociation('EnrollmentFlowSteps')) {

$efsTable = $currentTable->getAssociation('EnrollmentFlowSteps')->getTarget();

$this->set('vv_bc_parent_obj', $efsTable->get($link->value));
$this->set('vv_bc_parent_displayfield', $efsTable->getDisplayField());
$this->set('vv_bc_parent_primarykey', $efsTable->getPrimaryKey());
} else {
// Two-hop case: foreign key from $link (e.g. attribute_collector_id)
// -> AttributeCollectors
// -> EnrollmentFlowSteps
// Useful for deeply nested enrollment configuration objects.
if (!empty($link->attr)) {
// Derive the table class name from the foreign key name
$fkClassName = StringUtilities::foreignKeyToClassName($link->attr); // e.g. 'AttributeCollectors'

// Qualify with plugin if present
$tableAlias = !empty($link->plugin)
? $link->plugin . '.' . $fkClassName // e.g. 'CoreEnroller.AttributeCollectors'
: $fkClassName;

$attributeCollectorsTable = TableRegistry::getTableLocator()->get($tableAlias);

// Load the intermediate object (AttributeCollector, in your case)
$collector = $attributeCollectorsTable->get((int)$link->value);

// From the AttributeCollector, go up to the EnrollmentFlowStep
if (!empty($collector->enrollment_flow_step_id)) {
$efsTable = TableRegistry::getTableLocator()->get('EnrollmentFlowSteps');
$step = $efsTable->get((int)$collector->enrollment_flow_step_id);

$this->set('vv_bc_parent_obj', $step);
$this->set('vv_bc_parent_displayfield', $efsTable->getDisplayField());
$this->set('vv_bc_parent_primarykey', $efsTable->getPrimaryKey());
}
}
}
}

return parent::beforeRender($event);
Expand Down
Loading