form_fields using blocks in a template

edited September 2016 in Bug Reports
I'm building a module with a fieldset that I want to have repeatable blocks available within. I've got the layout sorted but the content isn't rendering into the blocks. The data is getting serialised and saved but it isn't being loaded into the blocks.

Heres some of code from the model:
public $serialized_fields = array('make_hub_page'); public function form_fields($values = array(), $related = array()) { ... $fields['Hub'] = array('type' => 'fieldset', 'label' => 'Hub Page', 'order' => 200, 'class' => 'tab'); $fields['make_hub_page'] = array( 'display_label' => FALSE, 'type' => 'template', 'init_display' => 'first', 'dblclick' => 'toggle', 'order' => 210, 'label' => 'Page sections', 'fields' => array('block' => array('type' => 'block', 'folder' => 'manufacturer_landing'),), 'add_extra' => FALSE, 'repeatable' => TRUE, ); .... }
this is getting saved to the 'make_hub_page' field in the database:
[{"block":{"title":"test title","content":"test content","tips":"test tips","no_results_message":"no results","images":[{"title":"","image":""}],"block_name":"main_search"}},{"block":{"header_text":"test header","text":"test text","disclosure_text":"test disclosure text","block_name":"manufacturer_finance"}}]
I can't help feeling I've missed something obvious.

Cheers

David

Comments

  • edited 7:40AM
    What is an example of one of the block layouts being used and what version of FUEL are you using?
  • edited September 2016
    We're using the latest version of Fuel, but haven't pulled for a few months.

    the layout looks like this :

    $man_landing_layout = new Fuel_layout('manufacturer_landing'); $man_landing_layout->set_description('This layout is for the New cars.'); $man_landing_layout->set_label('Manufacturer Landing Page'); $CI->load->model("Cap_range_model"); $CI->load->model("Cap_model_model"); $man_layout_fields = array( 'Sections' => array('type' => 'fieldset', 'label' => 'Sections', 'class' => 'tab'), 'sections' => array( 'type' => 'template', 'display_label' => FALSE, 'label' => 'Sections', 'add_extra' => FALSE, 'repeatable' => TRUE, 'max' => 12, 'min' => 0, 'title_field' => 'block', 'fields' => array( 'section' => array('type' => 'section', 'value' => 'Section <span class="num">{num}</span>'), 'block' => array('type' => 'block', 'folder' => 'manufacturer_landing'), ), ), 'body_class' => array(), ); $man_landing_layout->add_fields($common_meta); $franchise_name = array( 'franchise_name' => array('type' => 'select2', 'required' => TRUE, 'options' => $franchise_manufacturer_list) ); $man_landing_layout->add_fields($franchise_name); $man_landing_layout->add_fields($man_layout_fields); $config['layouts']['manufacturer_landing'] = $man_landing_layout;

    and this is one of the blocks:

    <div class="branch-block-container"> <div class="branch-block-overlay"> <div class="branch-block-inner"> <i class="fa fa-map-marker"></i> <h1><?= $title ?></h1> <p><?= $content ?></p> <form id="homepage-postcode-search" action="<?= site_url(); ?>dealerships/filtered" method="get" > <input type="text" name="dealership-filter-postcode" value="" id="dealership-filter-postcode" placeholder="Your Postcode..."> <input type="hidden" name="dealership-filter-manufacturer" value="<?= $franchise_name ?>"> <input type="button" name="" value="Go" id="homepage-postcode-search-button" class="green-cta"> </form> </div> </div> <div class="branch-block" id="map" style="width: 100%; height: 100%;"> </div> </div>
    I don't explicitly have block layouts, where would I put them? the CMs is loading the blocks ok, it's just not putting the data in the fields to edit.

    Cheers
  • edited September 2016
    it might be worth mentioning that the layouts are currently working in the "Pages" module, I'm trying to use them in a simple module
  • edited September 2016
    I've changed form_fields to this:

    $fields['make_hub_page'] = array( 'type' => 'template', 'display_label' => FALSE, 'label' => 'Page sections', 'add_extra' => FALSE, 'repeatable' => TRUE, 'title_field' => "block", 'init_display' => 'first', 'dblclick' => 'toggle', 'order' => 210, 'fields' => array( 'section' => array('type' => 'section', 'value' => 'Section <span class="num">{num}</span>'), 'block' => array('type' => 'block', 'block_name' => 'branch'), ), );

    and it loads the data, but I now can't select other block types. is it possible to load multiple block_name's. tried an array but it falls over
  • edited 7:40AM
    Is there a block layout specified for the block itself (above looks to be the page layout)?
    http://docs.getfuelcms.com/general/layouts#layouts_block_layouts
  • edited 7:40AM
    I have added this one to the layout file,:

    $branch_block = new fuel_block_layout('branch'); $branch_block->set_label('Branch block test'); $branch_block->add_field('title', array()); $branch_block->add_field('content', array('type' =>'text')); $config['blocks']['branch'] = $branch_block;
  • edited 7:40AM
    it only covers one of the blocks, but it's the block I've been concentrating on
  • edited 7:40AM
    I've added block layout for all the blocks and it still doesn't put to content in the form for editing
  • edited 7:40AM
    For your $branch_block block layout, try adding the following model parameter (but substitute 'my_model' with your model name):
    $branch_block->set_model('my_model');
  • edited 7:40AM
    that's sorted it, must have missed that in the doc's

    Cheers

    David
Sign In or Register to comment.