Results 1 to 4 of 4

Thread: how to override extend function in Widget

  1. #1
    New user
    Join Date
    10-11-09.
    Posts
    9

    Default how to override extend function in Widget

    I want to add the "title" attribute to my form fields. I was able to add a title field to the tl_form_field table and to the DCA. I was able to get it to show up in my html by adding
    Code:
    case 'title':
    $this->arrAttributes[$strKey] = $varValue;
    break;
    to the
    Code:
    public function __set($strKey, $varValue)
    {
    switch ($strKey)
       {...
    }
    in Widget.php

    I am a relative newbie and no php expert, but I pick things up pretty well.
    I know it's not a good idea to modify that file, but I can't figure out how to extend or override that function in a custom class.

    Any ideas?

    Thanks.

  2. #2
    Experienced user
    Join Date
    06-10-09.
    Location
    Cape Town, South Africa
    Posts
    1,387

    Default Re: how to override extend function in Widget

    no that is really the wrong way to do it.

    You have to extend the DCA, using your own custom folder to place your files in. You will need a dca/tl_form_field.php file to place the code, a language string in languages/en/tl_form_field.php. The title is useless as well without modifying or creating your own routines to display them in the front-end.

    What may I ask is the purpose of the Title? since you can use Headline and Explanation for basic text/headings or HTML to create field groups?

  3. #3
    New user
    Join Date
    10-11-09.
    Posts
    9

    Default Re: how to override extend function in Widget

    I guess I didn't make this clear.

    I am using the titles so that I can add tooltips to my form fields. It is a stylistic preference--I couldn't get the Explanations to look the way I wanted them to look.

    I have extended the DCA, using my own custom folder with a dca/tl_form_field.php file and a language string in languages/en/tl_form_field.php. I have a database.sql file extending the database to add a tile field to tl_form field. I have the routines in place to display them in the front end. The problem I was having was getting the titles that I enter into the DCA to show up as attributes for the form fields in my html.

    I did a little digging into the code and figured out how attributes were inserted into form fields in the Widget class, and by inserting that little piece of code, I was able to get everything to work the way I wanted it to work. Actually, I managed to shorten my addition to one line:

    Code:
    	
    	public function __set($strKey, $varValue)
    	{ ...
    		switch ($strKey)
    		{
                                        ...
                                                    case 'alt':
    			case 'style':
    			case 'onclick':
    			case 'onchange':
    			case 'accesskey':
    			case 'title':  //my addition		
                  $this->arrAttributes[$strKey] = $varValue;
    			break;
    		      ...
                                       }
    In other cases, I have been able to override methods using custom classes and registering them in $GLOBALS['FE_MOD'], but I don't know how to do that in this case.

    If this is the wrong way, is there a better way to accomplish what I am trying to do? Other than the annoyance of having to change the code every time I update, is there any reason not to alter the widget.php file in this way?

  4. #4
    Experienced user
    Join Date
    06-10-09.
    Location
    Cape Town, South Africa
    Posts
    1,387

    Default Re: how to override extend function in Widget

    Leo has started adding all db values to each frontend call, not sure I he's done it for for FE widgets. But you should rather change the template to add the title parameter there, taking the need away for all the override. Otherwise your screwed, because the widgets can be overrided with new versions where you add the additional title part.
    I believe that you can add attributes to a widget, but I haven't checked that.

    Also probably an easier way would be to use the loadformfield hook (which I got added), which you can use to modify the form field widget on load.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •