1

I'm trying to find a way to customize the message displayed after a successful record has been saved in a custom component. Well not really the entire message, just the 'item' part. For instance if my component is titled Resources, I'd like the success message to display, 'resource saved' rather than 'item saved'. And in the list view when it displays: 'N_ITEMS_CHECKED_IN' I would also like to replace the 'ITEMS' part. I know I could just interpret this in the language file. But I would still like to know how to change it.

I know the $text_prefix variable in the AdminModel controls the prefix. I looked for something similar in the Joomla core files, but I couldn't find anything. Or maybe I just didn't look in the correct place.

4
  • I'm not sure I understand your issue. You already know you can use a custom prefix if your model extends Joomla\CMS\MVC\Model\AdminModel. Or are you looking for something else?
    – Sharky
    Commented Jan 3, 2023 at 8:48
  • I guess I don't know how to use a custom prefix then. Because setting $text_prefix doesn't replace the message 'item saved', even though it says it's used with controller messages. I've looked at Joomla\CMS\MVC\Model\AdminModel and none of the variables correspond with replacing 'item' on messages. You're saying I can create a custom prefix to allow this?
    – chavab_1
    Commented Jan 4, 2023 at 1:18
  • What value did you try for $text_prefix?
    – Sharky
    Commented Jan 4, 2023 at 6:46
  • I just put a language string that translates to the name of my component. In looking at other examples, that's how I've always seen it used. For instance, in this case I put COM_REPORTS. And in my language file I translate it to the official name of my component. This does get translated and rendered in various location in the component. However, it doesn't replace the 'item saved' text.
    – chavab_1
    Commented Jan 5, 2023 at 8:37

1 Answer 1

0

The Joomla\CMS\MVC\Model\FormModel::$text_prefix property is used to define a prefix used for building language keys throughout the model. It defaults to component's element (e.g. COM_REPORTS). This would result in a language key like COM_REPORTS_N_ITEMS_CHECKED_IN. To use multiple strings per component, use different suffixes per model, e.g. COM_REPORTS_RESOURCES in one model (which would result in a key like COM_REPORTS_RESOURCES_N_ITEMS_CHECKED_IN ) and COM_REPORTS_SOMEOTHERITEMS in another model. And add the appropriate language strings to language files.

You should note that Joomla\CMS\MVC\Controller\FormController also has $text_prefix property which is used the same way. This is where the generic "Item saved" string comes from. They key by default would be COM_REPORTS_SAVE_SUCCESS but you can change it by changing the prefix.

1
  • Thank you!! The controller's $text_prefix property and the _SAVE_SUCCESS key was what I needed. I had never changed that property in the controller, only in the model.
    – chavab_1
    Commented Jan 13, 2023 at 6:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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