private function normalizeTabs(BlockInterface $block) { $properties = $block->getProperties(); if (isset($properties['tabs']) && count($properties['tabs'])) { if (isset($properties['tabs'][0]) && !is_array($properties['tabs'][0])) { $converted = array(); $sort = count($properties['tabs']); foreach ($properties['tabs'] as $key => $value) { $converted[] = ['label' => $value, 'key' => $key, 'sort' => $sort--]; } $properties['tabs'] = $converted; } $maxKey = 0; $maxSort = 0; array_walk($properties['tabs'], function ($tab) use(&$maxKey, &$maxSort) { if (isset($tab['key']) && $tab['key'] > $maxKey) { $maxKey = $tab['key']; } if (isset($tab['sort']) && $tab['sort'] > $maxSort) { $maxSort = $tab['sort']; } }); $maxKey++; $maxSort++; foreach ($properties['tabs'] as &$tab) { if (!isset($tab['key']) || $tab['key'] === null || $tab['key'] === "") { $tab['key'] = $maxKey++; } if (!isset($tab['sort']) || $tab['sort'] === null || $tab['sort'] === "") { $tab['sort'] = $maxSort++; } } uasort($properties['tabs'], function ($a, $b) { return $a['sort'] < $b['sort'] ? 1 : 0; }); $block->setProperties($properties); } return $block; }