Skip to content
Snippets Groups Projects
Commit de8f8e1a authored by Demian Katz's avatar Demian Katz
Browse files

Simplify code with null coalescing.

parent 1101dda2
No related merge requests found
...@@ -101,15 +101,11 @@ class RecordDataFormatter extends AbstractHelper ...@@ -101,15 +101,11 @@ class RecordDataFormatter extends AbstractHelper
continue; continue;
} }
// Allow dynamic label override: // Allow dynamic label override:
if (isset($current['labelFunction']) $label = is_callable($current['labelFunction'] ?? null)
&& is_callable($current['labelFunction']) ? call_user_func($current['labelFunction'], $data) : $field;
) { $result[$label] = [
$field = call_user_func($current['labelFunction'], $data);
}
$context = $current['context'] ?? [];
$result[$field] = [
'value' => $text, 'value' => $text,
'context' => $context 'context' => $current['context'] ?? [],
]; ];
} }
} }
...@@ -179,9 +175,7 @@ class RecordDataFormatter extends AbstractHelper ...@@ -179,9 +175,7 @@ class RecordDataFormatter extends AbstractHelper
return $method; return $method;
} }
$useCache = isset($options['useCache']) && $options['useCache']; if ($useCache = ($options['useCache'] ?? false)) {
if ($useCache) {
$cacheKey = $driver->getUniqueID() . '|' $cacheKey = $driver->getUniqueID() . '|'
. $driver->getSourceIdentifier() . '|' . $method; . $driver->getSourceIdentifier() . '|' . $method;
if (isset($cache[$cacheKey])) { if (isset($cache[$cacheKey])) {
...@@ -254,7 +248,7 @@ class RecordDataFormatter extends AbstractHelper ...@@ -254,7 +248,7 @@ class RecordDataFormatter extends AbstractHelper
*/ */
protected function getLink($value, $options) protected function getLink($value, $options)
{ {
if (isset($options['recordLink']) && $options['recordLink']) { if ($options['recordLink'] ?? false) {
$helper = $this->getView()->plugin('record'); $helper = $this->getView()->plugin('record');
return $helper->getLink($options['recordLink'], $value); return $helper->getLink($options['recordLink'], $value);
} }
...@@ -275,7 +269,7 @@ class RecordDataFormatter extends AbstractHelper ...@@ -275,7 +269,7 @@ class RecordDataFormatter extends AbstractHelper
protected function renderSimple(RecordDriver $driver, $data, array $options) protected function renderSimple(RecordDriver $driver, $data, array $options)
{ {
$view = $this->getView(); $view = $this->getView();
$escaper = (isset($options['translate']) && $options['translate']) $escaper = ($options['translate'] ?? false)
? $view->plugin('transEsc') : $view->plugin('escapeHtml'); ? $view->plugin('transEsc') : $view->plugin('escapeHtml');
$transDomain = $options['translationTextDomain'] ?? ''; $transDomain = $options['translationTextDomain'] ?? '';
$separator = $options['separator'] ?? '<br />'; $separator = $options['separator'] ?? '<br />';
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment