aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/forms
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+studip@gmail.com>2023-02-21 17:26:28 +0000
committerJan-Hendrik Willms <tleilax+studip@gmail.com>2023-02-21 17:26:28 +0000
commitefef144922e593e5c64fec8d416e17f8a16ab3fa (patch)
tree95815b2982837f0e6c8c97ab12506587579450ec /lib/classes/forms
parent6a20f2aebb96ed0d9816c5da9903946abe11284f (diff)
prevent php8 warnings, fixes #2204
Closes #2204 Merge request studip/studip!1437
Diffstat (limited to 'lib/classes/forms')
-rw-r--r--lib/classes/forms/Form.php9
-rw-r--r--lib/classes/forms/Part.php43
2 files changed, 34 insertions, 18 deletions
diff --git a/lib/classes/forms/Form.php b/lib/classes/forms/Form.php
index ba0258d..936f324 100644
--- a/lib/classes/forms/Form.php
+++ b/lib/classes/forms/Form.php
@@ -77,6 +77,13 @@ class Form extends Part
{
$metadata = $object->getTableMetadata();
+ // Normalize parameters
+ $params = array_merge([
+ 'types' => [],
+ 'fields' => [],
+ 'without' => [],
+ ], $params);
+
if ($params['fields']) {
//Setting the label
foreach ($params['fields'] as $fieldname => $fielddata) {
@@ -89,7 +96,7 @@ class Form extends Part
//Setting the type and name
foreach ($params['fields'] as $fieldname => $fielddata) {
if (is_array($fielddata)) {
- $meta = $metadata['fields'][$fieldname];
+ $meta = $metadata['fields'][$fieldname] ?? null;
if (!isset($fielddata['type'])) {
if ($meta) {
$fielddata = array_merge(Input::getFielddataFromMeta($meta, $object), $fielddata);
diff --git a/lib/classes/forms/Part.php b/lib/classes/forms/Part.php
index 4831945..3609eb4 100644
--- a/lib/classes/forms/Part.php
+++ b/lib/classes/forms/Part.php
@@ -194,10 +194,17 @@ abstract class Part
*/
public function getInputFromArray(array $data)
{
+ // Normalize data
+ $data = array_merge([
+ 'label' => $data['name'] ?? null,
+ 'value' => null,
+ 'attributes' => [],
+ ], $data);
+
$context = $this->getContextObject();
if ($context && method_exists($context, 'getTableMetadata')) {
$metadata = $context->getTableMetadata();
- $meta = $metadata['fields'][$data['name']];
+ $meta = $metadata['fields'][$data['name']] ?? null;
if (!isset($data['type'])) {
if ($meta) {
$data = array_merge(Input::getFielddataFromMeta($meta, $context), $data);
@@ -221,16 +228,18 @@ abstract class Part
$classname = "\\Studip\\Forms\\".ucfirst($data['type'])."Input";
$attributes = $data;
- unset($attributes['name']);
- unset($attributes['label']);
- unset($attributes['value']);
- unset($attributes['type']);
- unset($attributes['mapper']);
- unset($attributes['store']);
- unset($attributes['if']);
- unset($attributes['permission']);
- unset($attributes['required']);
- unset($attributes['attributes']);
+ unset(
+ $attributes['name'],
+ $attributes['label'],
+ $attributes['value'],
+ $attributes['type'],
+ $attributes['mapper'],
+ $attributes['store'],
+ $attributes['if'],
+ $attributes['permission'],
+ $attributes['required'],
+ $attributes['attributes']
+ );
$attributes = array_merge($attributes, (array) $data['attributes']);
if (class_exists($classname)) {
$input = new $classname($data['name'], $data['label'], $data['value'], $attributes);
@@ -242,21 +251,21 @@ abstract class Part
throw new \Exception(sprintf(_("Klasse %s oder %s existiert nicht."), $classname, $data['type']));
}
- if ($data['mapper'] && is_callable($data['mapper'])) {
+ if (isset($data['mapper']) && is_callable($data['mapper'])) {
$input->mapper = $data['mapper'];
}
- if ($data['store'] && is_callable($data['store'])) {
+ if (isset($data['store']) && is_callable($data['store'])) {
$input->store = $data['store'];
}
- if ($data['if']) {
+ if (!empty($data['if'])) {
$input->if = $data['if'];
}
if (isset($data['permission'])) {
$input->permission = $data['permission'];
}
- if ($data['required']) {
- $input->required = true;
- }
+
+ $input->required = !empty($data['required']);
+
return $input;
}
}