Skip to content

Commit

Permalink
Improve Form global edit mode handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Sep 27, 2024
1 parent 1c97ecb commit 8fcfc71
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

// This view does currently not support read-only
if($vv_action == 'add' || $vv_action == 'edit') {
// XXX Placeholder
}
// Currently this Configuration View has no fields

$this->Field->disableFormEditMode();

26 changes: 24 additions & 2 deletions app/src/View/Helper/FieldHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class FieldHelper extends Helper {
*/
public const EDITABLE_ACTIONS = [
'add', 'edit', // CRUD actions
'start' // ENROLLMENT FLOW actions
];

// Is this read-only or read-write?
Expand Down Expand Up @@ -82,7 +81,8 @@ public function initialize(array $config): void
$this->reqFields = $this->getView()->get('vv_required_fields');
$this->modelName = $this->getView()->getName();
$this->action = $this->getView()->get('vv_action');
$this->editable = \in_array($this->action, self::EDITABLE_ACTIONS, true);
$vv_is_editable = filter_var($this->getView()->get('vv_is_editable'), FILTER_VALIDATE_BOOLEAN);
$this->editable = \in_array($this->action, self::EDITABLE_ACTIONS, true) || $vv_is_editable;
$this->pluginName = $this->getView()->getPlugin();
$this->entity = $this->getView()->get('vv_obj');
$this->fieldTypes = $this->getView()->get('vv_field_types');
Expand Down Expand Up @@ -464,6 +464,28 @@ public function isEditable(): bool
return $this->editable;
}

/**
* Enable Form Edit mode. This will allow fields to be editable
* and the submit button will be rendered
*
* @return void
*/
public function enableFormEditMode(): void
{
$this->editable = true;
}

/**
* Disable Form's edit mode. Fields will be become readonly/disabled
* and the submit button will be removed from the DOM
*
* @return void
*/
public function disableFormEditMode(): void
{
$this->editable = false;
}

/**
* @param string $field
*
Expand Down
2 changes: 2 additions & 0 deletions app/templates/EnrollmentFlows/start.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

// Enrollment Flow Start has its own file of fields
$this->set('vv_fields_inc', 'start.inc');
// Set form edit ability
$this->set('vv_is_editable', true);

// Create the Form
print $this->Form->create();
Expand Down

0 comments on commit 8fcfc71

Please sign in to comment.