protected function buildViewTemplate($template_config)
 {
     $tab_list = new TabList();
     foreach ($template_config['tabs'] as $tab_name => $tab_config) {
         $panel_list = new PanelList();
         foreach ($tab_config['panels'] as $panel_config) {
             $row_list = new RowList();
             foreach ($panel_config['rows'] as $row_config) {
                 $cell_list = new CellList();
                 foreach ($row_config['cells'] as $cell_config) {
                     $group_list = new GroupList();
                     foreach ($cell_config['groups'] as $group_name => $group_config) {
                         $field_list = new FieldList();
                         foreach ($group_config['fields'] as $field_name => $field_data) {
                             $field = new Field($field_name, new ArrayConfig($field_data));
                             $field_list->addItem($field);
                         }
                         $group_css = $group_config['css'] ?: '';
                         $group_list->addItem(new Group($group_name, $field_list, $group_css));
                     }
                     $cell_css = $cell_config['css'] ?: '';
                     $cell_list->addItem(new Cell($group_list, $cell_css));
                 }
                 $row_css = $row_config['css'] ?: '';
                 $row_list->addItem(new Row($cell_list, $row_css));
             }
             $panel_css = $panel_config['css'] ?: '';
             $panel_list->addItem(new Panel($panel_config['name'], $row_list, $panel_css));
         }
         $tab_css = $tab_config['css'] ?: '';
         $tab_list->addItem(new Tab($tab_name, $panel_list, $tab_css));
     }
     return new ViewTemplate($template_config['name'], $tab_list, $template_config['css']);
 }
示例#2
0
 /**
  * Creates a ViewTemplate instance with one tab, one panel, one row, one list, one group and as many
  * fields as the resource type has attributes. To only include specific attributes as fields set
  * them in the attribute_names method argument.
  *
  * @param string $view_template_name name of the created view template
  * @param ProjectionTypeInterface $resource_type
  * @param array $attribute_names list of attributes to include as view template fields; if empty all
  *                               attributes will be included as fields
  *
  * @return ViewTemplateInterface instance with all or specified attributes as fields
  *
  * @throws RuntimeError in case of an empty view template name
  */
 public function createViewTemplate($view_template_name, ProjectionTypeInterface $resource_type, array $attribute_names = [])
 {
     if (empty($view_template_name)) {
         throw new RuntimeError('A view template name must be specified.');
     }
     $field_list = new FieldList();
     foreach ($resource_type->getAttributes() as $attribute_name => $attribute) {
         if (empty($attribute_names)) {
             $field_list->addItem(new Field($attribute_name));
         } elseif (in_array($attribute_name, $attribute_names)) {
             $field_list->addItem(new Field($attribute_name));
         }
     }
     $group_list = new GroupList();
     $group_list->addItem(new Group('group-content', $field_list));
     $cell_list = new CellList();
     $cell_list->addItem(new Cell($group_list));
     $row_list = new RowList();
     $row_list->addItem(new Row($cell_list));
     $panel_list = new PanelList();
     $panel_list->addItem(new Panel('panel-content', $row_list));
     $tab_list = new TabList();
     $tab_list->addItem(new Tab('tab-content', $panel_list));
     $view_template = new ViewTemplate($view_template_name, $tab_list);
     return $view_template;
 }