From e4985c03985e43c5a044fe75b0080930c60df4a9 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Fri, 2 Oct 2020 08:11:31 -0400 Subject: [PATCH] simplify code to replace ml field types (#607) simplify code to replace ml field types --- classes/EventRegistry.php | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/classes/EventRegistry.php b/classes/EventRegistry.php index 79915ca1..6459d0c1 100644 --- a/classes/EventRegistry.php +++ b/classes/EventRegistry.php @@ -149,6 +149,15 @@ public function registerModelTranslation($widget) */ protected function processFormMLFields($fields, $model) { + $typesMap = [ + 'markdown' => 'mlmarkdowneditor', + 'mediafinder' => 'mlmediafinder', + 'repeater' => 'mlrepeater', + 'richeditor' => 'mlricheditor', + 'text' => 'mltext', + 'textarea' => 'mltextarea', + ]; + $translatable = array_flip($model->getTranslatableAttributes()); /* @@ -165,23 +174,8 @@ protected function processFormMLFields($fields, $model) $type = array_get($config, 'type', 'text'); - if ($type == 'text') { - $fields[$name]['type'] = 'mltext'; - } - elseif ($type == 'textarea') { - $fields[$name]['type'] = 'mltextarea'; - } - elseif ($type == 'richeditor') { - $fields[$name]['type'] = 'mlricheditor'; - } - elseif ($type == 'markdown') { - $fields[$name]['type'] = 'mlmarkdowneditor'; - } - elseif ($type == 'repeater') { - $fields[$name]['type'] = 'mlrepeater'; - } - elseif ($type == 'mediafinder') { - $fields[$name]['type'] = 'mlmediafinder'; + if (array_key_exists($type, $typesMap)) { + $fields[$name]['type'] = $typesMap[$type]; } }