Skip to content

Commit

Permalink
Improve FieldHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioannis committed Mar 12, 2024
1 parent 7454e13 commit 58a6cd3
Showing 1 changed file with 43 additions and 32 deletions.
75 changes: 43 additions & 32 deletions app/src/View/Helper/FieldHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,20 +576,16 @@ protected function formNameDiv(string $fieldName,
break;
}
}

return '<div class="'. ($fieldNameClasses ?? 'field-name') . '">'
. '<div class="'. ($fieldTitleClasses ?? 'field-title') . '">'
. (!($labelIsTextOnly) && ($fieldType != 'boolean')
? $this->Form->label($fn, $label)
: $label)
. ($this->editable
&& in_array($fn, $this->reqFields)
? ' <span class="required" aria-hidden="true">*</span>'
. '<span class="visually-hidden">' . __d('field','required') . '</span>'
: '') . '
</div>
' . ($desc ? '<div class="'. ($fieldDescClasses ?? 'field-desc') . '">' . $desc . '</div>' : '') .'
</div>';
. '<div class="'. ($fieldTitleClasses ?? 'field-title') . '">'
// Form Label
. (!($labelIsTextOnly) && ($fieldType != 'boolean') ? $this->Form->label($fn, $label) : $label)
. ($this->editable && in_array($fn, $this->reqFields) ? $this->requiredSpanElement() : '')
. '</div>' // field-title div
// Description element
. ($desc ? '<div class="'. ($fieldDescClasses ?? 'field-desc') . '">' . $desc . '</div>' : '') .'
</div>';
}

/**
Expand Down Expand Up @@ -663,6 +659,17 @@ public function peopleAutocompleteControl(string $fieldName, string $type = 'cop
}
}

/**
* Static required Span Element
*
* @return string
* @since COmanage Registry v5.0.0
*/
protected function requiredSpanElement() {
return "<span class='required' aria-hidden='true'>*</span>"
. "<span class='visually-hidden'>{__d('field', 'required')}</span>";
}

/**
* Emit a source control for an MVEA that has a source_foo_id field pointing
* to an External Identity attribute.
Expand Down Expand Up @@ -720,14 +727,15 @@ public function sourceControl($entity): string {

/**
* Generate a status control (a read only status with an optional link button).
*
* @since Registry Registry v5.0.0
* @param string $fieldName Form field
* @param string $status Status text
* @param array $link Link information, including 'url', 'label', 'class', 'confirm'
* @param string $labelText Label text (fieldName language key used by default)
* @param boolean $labelIsTextOnly true if <label> wrapper should not be included in the markup
*
* @param string $fieldName Form field
* @param string $status Status text
* @param array $link Link information, including 'url', 'label', 'class', 'confirm'
* @param string|null $labelText Label text (fieldName language key used by default)
* @param boolean $labelIsTextOnly true if <label> wrapper should not be included in the markup
*
* @return string
* @since COmanage Registry v5.0.0
*/

public function statusControl(string $fieldName,
Expand All @@ -743,7 +751,7 @@ public function statusControl(string $fieldName,
if(!empty($link['label'])) {
// Create a separate link after $status

$linkHtml .= " " . $this->Html->link(
$linkHtml .= ' ' . $this->Html->link(
$link['label'],
$link['url'],
$link
Expand All @@ -765,17 +773,19 @@ public function statusControl(string $fieldName,
. $this->formInfoDiv($linkHtml)
. $this->endLine();
}

/**
* Start a set of form controls.
*
* @since COmanage Registry v5.0.0
* @param string $modelName Model name for form
* @param string $action Current action
* @param boolean $editable True if controls are read/write, false for read only
* @param array $reqFields Array of required fields
* @param object $entity Entity object (if set, null on add)
* @param string $modelName Model name for form
* @param string $action Current action
* @param boolean $editable True if controls are read/write, false for read only
* @param array $reqFields Array of required fields
* @param null $entity Entity object (if set, null on add)
* @param string|null $pluginName
*
* @return string
* @since COmanage Registry v5.0.0
*/

public function startControlSet(string $modelName,
Expand All @@ -793,13 +803,14 @@ public function startControlSet(string $modelName,

return '<ul id="' . $action . '_' . $modelName . '" class="fields form-list">' . "\n";
}

/**
* Start a form line.
*
* @since COmanage Registry v5.0.0
* @param string $class Optional class to apply to the line
* @param string|null $class Optional class to apply to the line
*
* @return string
* @since COmanage Registry v5.0.0
*/

protected function startLine(string $class=null): string {
Expand All @@ -817,7 +828,7 @@ protected function startLine(string $class=null): string {
/**
* Emit a submit control.
*
* @since Registry Registry v6.0.0
* @since COmanage Registry v5.0.0
* @param string $label Text for submit button
* @return string
*/
Expand Down

0 comments on commit 58a6cd3

Please sign in to comment.