Skip to content

Commit

Permalink
Restructure CoreEnroller for top-level form generation (CFM-218) (#355)
Browse files Browse the repository at this point in the history
  • Loading branch information
arlen authored Dec 15, 2025
1 parent f0b5328 commit f4d559b
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 6 deletions.
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]);
}
}
2 changes: 1 addition & 1 deletion app/templates/Standard/dispatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

// Form body
print '<div id="dispatch-list-container">';
print $this->element('form/unorderedList');
print $this->element('CoreEnroller.unorderedList');
print '</div>';

// Inject the Petition ID into the form, though it will most likely
Expand Down

0 comments on commit f4d559b

Please sign in to comment.