Skip to content
Snippets Groups Projects
Commit efef1449 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

prevent php8 warnings, fixes #2204

Closes #2204

Merge request studip/studip!1437
parent 6a20f2ae
No related branches found
No related tags found
1 merge request!4Draft: Icon creation
...@@ -77,6 +77,13 @@ class Form extends Part ...@@ -77,6 +77,13 @@ class Form extends Part
{ {
$metadata = $object->getTableMetadata(); $metadata = $object->getTableMetadata();
// Normalize parameters
$params = array_merge([
'types' => [],
'fields' => [],
'without' => [],
], $params);
if ($params['fields']) { if ($params['fields']) {
//Setting the label //Setting the label
foreach ($params['fields'] as $fieldname => $fielddata) { foreach ($params['fields'] as $fieldname => $fielddata) {
...@@ -89,7 +96,7 @@ class Form extends Part ...@@ -89,7 +96,7 @@ class Form extends Part
//Setting the type and name //Setting the type and name
foreach ($params['fields'] as $fieldname => $fielddata) { foreach ($params['fields'] as $fieldname => $fielddata) {
if (is_array($fielddata)) { if (is_array($fielddata)) {
$meta = $metadata['fields'][$fieldname]; $meta = $metadata['fields'][$fieldname] ?? null;
if (!isset($fielddata['type'])) { if (!isset($fielddata['type'])) {
if ($meta) { if ($meta) {
$fielddata = array_merge(Input::getFielddataFromMeta($meta, $object), $fielddata); $fielddata = array_merge(Input::getFielddataFromMeta($meta, $object), $fielddata);
......
...@@ -194,10 +194,17 @@ abstract class Part ...@@ -194,10 +194,17 @@ abstract class Part
*/ */
public function getInputFromArray(array $data) public function getInputFromArray(array $data)
{ {
// Normalize data
$data = array_merge([
'label' => $data['name'] ?? null,
'value' => null,
'attributes' => [],
], $data);
$context = $this->getContextObject(); $context = $this->getContextObject();
if ($context && method_exists($context, 'getTableMetadata')) { if ($context && method_exists($context, 'getTableMetadata')) {
$metadata = $context->getTableMetadata(); $metadata = $context->getTableMetadata();
$meta = $metadata['fields'][$data['name']]; $meta = $metadata['fields'][$data['name']] ?? null;
if (!isset($data['type'])) { if (!isset($data['type'])) {
if ($meta) { if ($meta) {
$data = array_merge(Input::getFielddataFromMeta($meta, $context), $data); $data = array_merge(Input::getFielddataFromMeta($meta, $context), $data);
...@@ -221,16 +228,18 @@ abstract class Part ...@@ -221,16 +228,18 @@ abstract class Part
$classname = "\\Studip\\Forms\\".ucfirst($data['type'])."Input"; $classname = "\\Studip\\Forms\\".ucfirst($data['type'])."Input";
$attributes = $data; $attributes = $data;
unset($attributes['name']); unset(
unset($attributes['label']); $attributes['name'],
unset($attributes['value']); $attributes['label'],
unset($attributes['type']); $attributes['value'],
unset($attributes['mapper']); $attributes['type'],
unset($attributes['store']); $attributes['mapper'],
unset($attributes['if']); $attributes['store'],
unset($attributes['permission']); $attributes['if'],
unset($attributes['required']); $attributes['permission'],
unset($attributes['attributes']); $attributes['required'],
$attributes['attributes']
);
$attributes = array_merge($attributes, (array) $data['attributes']); $attributes = array_merge($attributes, (array) $data['attributes']);
if (class_exists($classname)) { if (class_exists($classname)) {
$input = new $classname($data['name'], $data['label'], $data['value'], $attributes); $input = new $classname($data['name'], $data['label'], $data['value'], $attributes);
...@@ -242,21 +251,21 @@ abstract class Part ...@@ -242,21 +251,21 @@ abstract class Part
throw new \Exception(sprintf(_("Klasse %s oder %s existiert nicht."), $classname, $data['type'])); 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']; $input->mapper = $data['mapper'];
} }
if ($data['store'] && is_callable($data['store'])) { if (isset($data['store']) && is_callable($data['store'])) {
$input->store = $data['store']; $input->store = $data['store'];
} }
if ($data['if']) { if (!empty($data['if'])) {
$input->if = $data['if']; $input->if = $data['if'];
} }
if (isset($data['permission'])) { if (isset($data['permission'])) {
$input->permission = $data['permission']; $input->permission = $data['permission'];
} }
if ($data['required']) {
$input->required = true; $input->required = !empty($data['required']);
}
return $input; return $input;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment