Simple Module + Multiple Languages

edited October 2016 in Modules
I'm trying to build a "gallery" simple module to upload & manage artworks on a multilingual site.
I like how the pages module handles multiple languages (when you select a language, it changes the page variables so you can enter the same data for another language). I have been looking through fuel_pages_model.php and fuel_pagevariables_model.php, but I can't find anything regarding that feature. How can I leverage that feature for my own simple module?

I'm also trying to emulate the way FUEL handles data for multiple languages in my simple module. That is, I've set up my gallery table, and I also have a gallery_variables table. What file can I look at to understand how FUEL integrates these two tables on the admin interface?

I like the way FUEL pages work, so I wanted to try and do something similar for my own module. Trying not to reinvent the wheel!

Thanks!

Comments

  • edited 12:22PM
    The fuel/modules/fuel/controllers/pages.php controller contains a lot of special logic for saving page variables for a page. The fuel/modules/fuel/assets/js/fuel/controller/PageController.js file is the javascript logic used to switch between the different languages. Those would be two places I'd look at to replicate.
  • edited October 2016
    Thanks very much!
    What's throwing me is a function that gets called a lot: _process()
    I've located it in \fuel\modules\fuel\controllers\module.php, but it throws errors if I try to access it from my model (in \fuel\application\models\), even if I require_once() the module.php file. What does _process() do?

    If I add the _process function directly to my model file, I get this error:
    ( ! ) Fatal error: Maximum function nesting level of '100' reached, aborting!
  • edited October 2016
    Update: I replace _process() with $_POST and it works. But that's probably not a sustainable solution? Maybe it has consequences I'm not aware of?
  • edited 12:22PM
    The "_process" method is inherited from the fuel/modules/fuel/controllers/Module.php controller (which the Pages controller inherits from). That method is protected so you won't be able to access it from your model.
  • edited 12:22PM
    Is it OK to replace it with $_POST?
  • edited 12:22PM
    Any change to a core FUEL file may be subject to change. You can inherit from the Module controller if you aren't already, overwrite the method and create the routes to point to your controller instead.
  • edited 12:22PM
    I think I should really be doing this in an advanced module, but I've already invested a lot of time in a simple module, so I'm trying to make it work.

    In a simple module, how can I get the ID of the entry before I create it? In an on_after_save() function I'm trying to get the ID of the item that was saved in the save() function. If I call $this->model->save(), I get an infinite loop error.
  • edited 12:22PM
    The on_after_save methods passes an array of values that were saved. This will include the newly created 'id':
    public function on_after_save($values) { print_r($values); return $values; }
  • edited 12:22PM
    Finally, it works! Thank you.
  • edited 12:22PM
    Sorry- another question. My module works without issue now, but when I go to delete an entry, the page displays this message:
    You are about to delete the item: 0

    Though it deletes the proper entry from the DB, why does it say the item "0"? Where can I access that variable that's being outputted as 0?
  • edited 12:22PM
    There is a property called "display_field" you can specify on your simple modules configuration that is a field returned by find_all_array. This field is used as the friendly text for the record and usually includes the name/title field value for that record if that record has it:
    http://docs.getfuelcms.com/modules/simple
  • edited April 2018

    Hi! I am returning to this code after a year and a half of not looking at it, and I'm coming up against a problem (of course). When I query my gallery model, it's only pulling the data from the gallery table. Could you please jog my memory re: how to make it automatically join with the data from the galleryvariables table to output it on the front end? Thanks!

Sign In or Register to comment.