1

I have a specific requirement of showing categories of selected menu language only. So in my component, I have the field declared as below.

<field name="catid" type="categoryedit" label="JCATEGORY" description="JFIELD_CATEGORY_DESC" class="inputbox input-block-level" required="true"></field>

And in my Model, I am setting the field attribute dynamically based on the menu language.

public function getForm ($data = array(), $loadData = true)
{
  ....
  $language = JFactory::getLanguage()->getTag();
  $form->setFieldAttribute('catid', 'language', $language);
  ....
}

It works perfectly fine. However the only problem is it shows only the list which are meant for the selected language only, for example en-GB will show only list of values which are assigned to the language en-GB.

I need to display all the field values which are assigned to the selected language as well as "All" (or "*", i.e. no language selected).

I cannot set two values to the same field attribute, setting it two time overwrite fist.

$form->setFieldAttribute('catid', 'language', '*');

This doesn't work at all

$form->setFieldAttribute('catid', 'language', $language.', *');

Anyone has any idea how can I do this?

  • Can you show the custom Form Field code i.e. categoryedit.php? – Sahil Purav May 12 '15 at 10:43
1

After a lot of research I couldn't find any possible solution to this. So I overridden categoryedit field type and changed the following code in getOptions method (the field can be created in your component's models/fields directory so that it can be referenced in your form xml)

// Filter language
if (!empty($this->element['language']))
{
    $subQuery->where('language = ' . $db->quote($this->element['language']));
}

to

// Filter language
$languages = array(JFactory::getLanguage()->getTag(), '*');
if (!empty($this->element['language']))
{
    $languages[] = $this->element['language'];
}

$subQuery->where('language IN (' . implode(',', $db->quote($languages)).')');

Hope this helps anyone looking for similar solution.

  • Hi there! Do you know why when I want to use the categoryedit field in my component with the option to allow Adding new categories, it requires to declare in the xml the allowAdd="true", while the Joomla core components do not have to declare this and work without even mentioning the allowAdd? – FFrewin Jan 27 '18 at 19:57
  • That's because the flag is set manually. Example - administrator/components/com_content/models/article.php, function preprocessForm, $form->setFieldAttribute('catid', 'allowAdd', 'true'); – Nagarjun Jan 29 '18 at 10:40
0

You can just change your xml (models/forms/yourform.xml) field definition to include the extra option like this:

<field name="catid" type="contentlanguage" label="yourlabel"
description="yourdescription">
<option value="*">JALL</option></field>

JALL will be automatically translated to your language "All" word.

Hope that helps

  • Thank you for answering, however you misunderstood the question. I do not want to show another category name, rather categories with language set to All. Hope you understand. – Nagarjun May 12 '15 at 2:53
  • 1
    Now I see what you mean. First of all you are using a custom field (categoryedit) so you should check in the "categoryedit.php" to see how to handle this. By the way, have you tried to pass an array like this $form->setFieldAttribute('catid', 'language', array('en-GB','*')) ? – itsam May 12 '15 at 12:08
  • This is not a custom field, it is standard Joomla field. Yes, I tried the array and it gives error " Warning: It is not yet possible to assign complex types to attributes". And checked in categoryedit.php and has code if (!empty($this->element['language'])) { $subQuery->where('language = ' . $db->quote($this->element['language'])); } I believe this cannot be done as I see the above code is not designed to handle this. I am overriding the field now. – Nagarjun May 12 '15 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.