2

I am having trouble overriding the user registration component.

My objective is that I must not display the Name field because the name is split into three fields: First, Middle and Last Name and is filled out in the User Profile section (which is an overridden plugin and is dealt accordingly).

The override must not be by template override for us to support scalability and make the application upgrade-proof of core files.

So far, what I have tested is that I tried to upload the modified clone of the com_users component, in which I've removed the Name element in the com_users\models\forms, created a zip file and uploaded it via Extension Manager.
But still, the override did not work.

Any thoughts?

  • So do you just need to remove the field or also add the three split fields? – David Fritsch Sep 25 '14 at 4:30
  • I just need only to remove the field, since the three split fields are already in the User Profile plugin and that modified plugin also updates the Name column in the database. – Ju-chan Sep 25 '14 at 5:31
  • stackoverflow.com/a/18237104/1440242. Creating a clone of user component is not a good idea. The cloned component will not be updated. If you want to clone it, you need to link the cloned component to the registration menu item. – Farahmand Sep 25 '14 at 7:56
  • You need to create a user plugin that alters the jform before rendering and after save – Brian Bolli Sep 25 '14 at 19:46
4

You can do this most easily from a plugin actually. No core files are changed, so it should be completely update proof. You likely already have a plugin for the profile system that is adding the fields to the form. You may not want to edit that either, but it should be simple to copy the user plugin and set up the following function in that:

function onContentPrepareForm($form, $data)
{
    if (!($form instanceof JForm))
    {
        $this->_subject->setError('JERROR_NOT_A_FORM');
        return false;
    }

    // Check we are manipulating a valid form.
    $name = $form->getName();
    if (!in_array($name, array('com_admin.profile', 'com_users.user', 'com_users.profile', 'com_users.registration')))
    {
        return true;
    }

    $form->removeField('name');

    // you can also do checks to just remove fields on the front end or backend
    // if that makes more sense for your application
    if (JFactory::getApplication()->isAdmin()) {
        $form->removeField('captcha');
        $form->removeField('email2');
    }

    return true;
}
2

If you introduce modifications into the component files, they are going to be replaced in the next Joomla! update.

These are the output overrides that allow customization:

Understanding Output Overrides - http://docs.joomla.org/Understanding_Output_Overrides

  • Component Output Types and Layout Overrides
    • 3.1 Output Types
    • 3.2 Layouts
    • 3.3 Copying or Creating Layout Files
    • 3.4 Overriding Sub-Layouts

If they are not enought to solve your needs, you must create a new component (instead of changing a core component files).

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.