Fork me on GitHub

Language help in pnform (for .8)  Bottom

  • I have some forms where I want to have a text input line for each installed language (like in the category new/edit screen in the category module). Can this be achieved using pnform?

    --
    cyber_wolf
    www.bkbsolutions.com - My Zikula module development site.
  • The easiest solution would be to integrate an input field for every language manually. As you don't install new langauges every day, that would be really simple. But if you intend to release you stuff, you should find a flexible solution. AFAIK there is a plugin in pnRender that produces a dropdown for all installed languages. Look into the code to find out how that one does the job and then copy that to your own plugin. I am sure there is only a pnModAPIFunc call that you can directly put into your template as well.

    --
    best regards from Kiel, sailing city

    Steffen Voss

    Member of the Zikula Steering Committee
    Read The Zikulan's Blog "If you want people to RTFM, make a better FM!"
  • I found a way to do what I wanted. May not be the best way, but it works.

    In the newHandler's class initialize function I have...

    Code

    $sitelang = pnConfigGetVar('language');
    $langs = LanguageUtil::getInstalledLanguages();
    asort($langs);
    $data = array();
    foreach ($langs as $key=>$item) {
      if (!isset($data[$key])) {
        $data[$key] = array('language' => $key,
                            'title'    => 'name_' . $key,
                            'value'    => '',
                            'label'    => ($key == $sitelang) ? 'Site ' . pnml('_bkbTableLanguage') . ' - ' . $item : pnml('_bkbTableLanguage') . ' - ' . $item);
      }
    }

            $render->assign('data', $data2);


    In the editHandler's initialize function...

    Code

    $data2 = array();
    $sitelang = pnConfigGetVar('language');
    $langs = LanguageUtil::getInstalledLanguages();
    asort($langs);
    foreach ($data as $item) {
      $data2[$item['language']] = array('id'       => $item['id'],
                                        'language' => $item['language'],
                                        'title'    => 'name_' . $item['language'],
                                        'value'    => $item['name'],
                                        'label'    => $langs[$item['language']]);
    }
    if (pnConfigGetVar('multilingual') == 1) {
      foreach ($langs as $key=>$item) {
        if (!isset($data2[$key])) {
          $data2[$key] = array('id'       => $this->osid,
                               'language' => $key,
                               'title'    => 'name_' . $key,
                               'value'    => '',
                               'label'    => $item);
        }
      }
    } else {
      $data2 = array($data2[$sitelang]);
    }


    In the Handler's class handle function I have...

    Code

    $nextid = (int)DBUtil::selectFieldMax('bkbmodule_status', 'id') + 1;

    $records = array();
    foreach ($Data as $key => $val) {
      if ((!empty($val)) && (substr($key, 0, 4) == 'name')) {
        $keylang = substr($key, 5);
        if (!$keylang) {
          $keylang = '';
        }
        $records[] = array('id'       => $nextid,
                           'language' => $keylang,
                           'name'     => $val);
      }
    }


    And in the template.....

    Code

    <div class="bkbFormRow">
      <b><!--[pnformlabel for=title text=_bkbStatus]--></b><b r />
      <!--[foreach from=$data item=item]-->
        <!--[pnformtextinput id=$item.title text=$item.value maxLength=32 width=30em]--> (<!--[pnml name="_bkbLanguage"]--> - <!--[$item.label]-->)<b r />
      <!--[/foreach]-->
      <b r />
    </div>




    edited by: cyber_wolf, Nov 28, 2007 - 09:18 PM

    --
    cyber_wolf
    www.bkbsolutions.com - My Zikula module development site.
  • Seems right - I would have suggested something similar.
  • I'm trying to move these routines to a plugin now for easier usage and I'm having a problem in one spot that I cannot figure out.

    If there is a validation error, what functions in the plugins are being called to redraw the screen? I'm sure there is a function that is being inherited that I need to overwrite; but I cannot seem to find it. When the screen is redrawn, all the input fields are gone.

    --
    cyber_wolf
    www.bkbsolutions.com - My Zikula module development site.
  • Figured out my problem. I was trying to save the data in the wrong function. The plugin works good now.

    --
    cyber_wolf
    www.bkbsolutions.com - My Zikula module development site.
  • 0 users

This list is based on users active over the last 60 minutes.