public function transform(array $fields) { $display = new LayoutDisplay(); // Fields known to the layout $layout = $this->getProperty('field_layout'); foreach ($layout as $section) { $tab = new LayoutTab($section['id'], $section['name']); if (!$section['visible']) { $tab->hide(); } foreach ($section['fields'] as $field_info) { if (empty($field_info)) { continue; } $field_id = $field_info['field']; // Looking for a field that is not there...skip it for now if (!array_key_exists($field_id, $fields)) { continue; } $field = $fields[$field_id]; if ($field_info['collapsed']) { $field->collapse(); } if (!$field_info['visible']) { $field->hide(); } $tab->addField($field); unset($fields[$field_id]); } $display->addTab($tab); } // "New" (unknown) fields $publish_tab = $display->getTab('publish'); foreach ($fields as $field_id => $field) { if (strpos($field_id, '__') === FALSE) { $tab = $publish_tab; } else { list($tab_id, $garbage) = explode('__', $field_id); try { $tab = $display->getTab($tab_id); } catch (InvalidArgumentException $e) { $tab = new LayoutTab($tab_id, $tab_id); $display->addTab($tab); } } $tab->addField($field); } return $display; }
/** * Transform a field array into a LayoutDisplay object */ public function transform(array $fields) { $display = new LayoutDisplay(); // add the tabs they wanted foreach ($this->layout as $section) { $tab = new LayoutTab($section['id'], $section['name']); foreach ($section['fields'] as $field) { $field_id = $field['field']; $tab->addField($fields[$field_id]); unset($fields[$field_id]); } $display->addTab($tab); } // add any leftover fields to the default tab $tab = $display->getTab($this->getDefaultTab()); foreach ($fields as $field_id => $field) { $tab->addField($field); } return $display; }