How to Hack the Core for Longer Titles?

14

4

My client needs longer titles/URL titles/Structure url titles, but there is no add-on available with this specific functionality. I already know about these add-ons, but they don't do what I need. A support request with Title Master is already filed, it extends titles in Structure, but the url_title is still cut-off at the shorter length, all three components needed to be extended.

So I need to hack the core, but I'm not sure which files I need to modify. So far, I've found these 2 files:

  • /system/expressionengine/controllers/cp/content_publish.php, lines 2279 & 2291
  • /system/expressionengine/third-party/structure/tab.structure.php, line 156

Those files seem to update the "maxlength" parameter on the HTML for the 3 title input fields.

And I've found these database tables:

  • exp_channel_titles > title
  • exp_channel_titles > url_title
  • exp_structure_listings > uri

So I think I just need to change a few more files, but I don't know where they are:

  • Javascript file that controls the URL Title auto-fill on the publish page.
  • Javascript file that controls the Structure URL Title auto-fill on the publish page.
  • Structure Page URL database column.

Does anybody know where these are, and possibly what line number I need to edit? Am I forgetting anything? Thanks.

kgrote

Posted 2013-01-02T22:39:34.067

Reputation: 2 139

Answers

11

Note: The Title Master add-on should take care of all of this, but if you can't use that for whatever reason, here is the procedure for the hack:

Update 10/10/14: Title Master appears to be abandonware at this point.

This works as of EE 2.9

Always back up your files and database before hacking the core!

Native EE Titles & URL Titles

  • /system/expressionengine/controllers/cp/content_publish.php:

    $deft_fields = array(
        'title'         => array(
            /* ... */
            'field_maxl'            => 100 // update to desired max title length
        ),
        'url_title'     => array(
            /* ... */
            'field_maxl'            => 75 // update to desired max url title length
        ),
    
        /* ... */
    

    This updates the maxlength attribute on the input fields so you can type longer titles/URL titles.

  • /system/expressionengine/libraries/Api.php:

    $url_title = substr($url_title, 0, 75); // update to desired max url title length
    
    /* ... */
    
    if (strlen($url_title) > 70) // update to desired max url title length minus 5
    {
        $url_title = substr($url_title, 0, 70); // update to desired max url title length minus 5
    
    /* ... */
    
    if (strlen($url_title.$url_title_suffix) > 75) // update to desired max url title length
    

    This updates the function that actually publishes the entry to the database to allow a longer URL title.

  • /themes/javascript/compressed/jquery/plugins/ee_url_title.js:

    Near the end of the code, find .val(a.substring(0,75)) and update "75" to your desired URL title length. This allows the URL title to autofill to the correct length.

  • Go into the database and update the length of the following columns:

    • exp_channel_titles.title
    • exp_channel_titles.url_title

    This will allow your longer titles to be stored correctly in the database columns.

Structure URL Titles

  • /system/expressionengine/third_party/structure/tab.structure.php, inside the publish_tabs() method, in the "Field: Page URI/Slug" section:

    $settings[] = array(
        /* ... */
        'field_maxl'            => 100, // update to your desired max url title length
    
        /* ... */
    

    This updates the maxlength attribute in the input field.

  • Update the length of this database column:

    • exp_structure_listings.uri

    This allows for longer URL titles on Structure listing-type entries. Page-type entry URL titles are encrypted and stored in the exp_sites table, and I do not believe you need to make any modifications there for longer URL titles to work.

Document, Document, Document!

Be sure to document the changes you made so they don't get overwritten when you update EE. It's also just the professional thing to do. If you leave the project and another developer has to take your place and figure out what you did, good documentation will keep them from cursing your black soul. I recommend Focus Lab's Dev Docs module.

kgrote

Posted 2013-01-02T22:39:34.067

Reputation: 2 139

1On EE v2.7.3 the content publish line nnumbers are 2172 and 2184. – Mike Lohrman – 2014-02-20T22:20:52.163

11

I've had the need to do this a number of times, particularly on sites that have press releases. For some reason, press release titles can be insanely long. This is all we ever have to do:

In system/expressionengine/controllers/cp/content_publish.php, appx line 2279, change this to what you desire:

'title' => array(
  ...
  'field_maxl' => 255
),

If you need to alter the URL title too, look for the same thing in the url_title array below it, around line 2292:

'url_title' => array(
  ...
  'field_maxl' => 75
),

The only other thing we do is alter the database column in exp_channel_titles accordingly.

ALter the DB fields to match your max length

Unless I'm missing something, that's all we've ever needed to do. As for updating this to work on Structure titles, I'm sure the method is similar, but I don't use Structure very often so I can't really speak to it. Sounds like you're on the right path with where you're looking. I'm not sure why you would need to alter any of the JavaScript around the title fields.

As always, you should document your core hacks, no matter how simple they are.

Ryan Masuga

Posted 2013-01-02T22:39:34.067

Reputation: 1 317

2This change worked for you without changing the maxlength attribute in the view files? Even if the DB length is changed, that maxlength needs to be changed (its hard coded) or else you just can't type past 100 characters. – Brian Litzinger – 2013-01-03T17:15:33.430

I don't recall having to do that (EE 2.5.3). – Ryan Masuga – 2013-01-03T20:06:13.157

@Brian, the maxlength attribute does not seem to be hardcoded in 2.5.3, and will use whatever value is entered for field_maxl in the url_title and title arrays that Ryan mentioned. But I think there might be another step needed (not sure what) to allow for the url_title to go past 75 chars, though. – Alex Kendrick – 2013-01-03T20:20:40.197

There's definitely something keeping the URL Title and Structure URL fields from being auto-filled to the full length. I changed the field_maxl variables as you suggested - the maxlength parameters on the HTML input reflects that change, and you can manually type the longer title, but the autofill stops at the original, shorter length. The weird thing is my web inspector shows no event listeners on those input fields, but I could be doing it wrong. – kgrote – 2013-01-07T16:50:59.573

5

I'm not certain why Title Master would be insufficient for your needs. It handles increasing title length, url_title length, and works with Structure. Maybe if you state what it doesn't do that you need, that could help in identifying an alternative.

Otherwise, if you're going to hack, I think you've hit all the main spots, obviously making sure the database will handle the new size is also necessary, but it looks like you've got that covered. We hacked once for a client, in EE1, but the areas were similar, except no Structure.

nonprofit_tech

Posted 2013-01-02T22:39:34.067

Reputation: 4 819

1Do you really need the url titles to be the same length as the title? Usually in our case the client wants a 100+ length title, but a 100+ length url slug is kind of excessive... it can be shortened to something sane manually. – Brian Litzinger – 2013-01-03T16:25:22.777

I asked for clarification, because you didn't link to or state 'why' it didn't meet your needs in the original post. I'll edit the original request for you. Also, we've never edit the Javascript files for this to work, client manually entered longer url_title, if needed. – nonprofit_tech – 2013-01-03T17:15:25.480

@Brian Litzinger My client is quite adamant about the URL titles matching the entry titles, "because that's what Joomla used to do". – kgrote – 2013-01-03T17:40:38.413

My goal was to prevent the hacking of EE core. Obviously, you know its not a great idea, especially if the client doesn't use your services to perform future updates. It sounds like Title Master does most of what you want, have you considered just hacking that to get the last bit of functionality. It probably won't be updated nearly as frequently as EE would. Also, if it was, with the increased lengths, its possible the client would even notice a disruption for most titles. – nonprofit_tech – 2013-01-03T18:11:04.110

I was wondering the same thing, what wasn't working with Title Master? Not only does it lengthen Titles and URL Titles and support Structure, you get the added UX benefits of allowing concatenated fields to auto-generate Title and URL Title fields making duplication of data entry unnecessary. – Stuart McCoy – 2013-01-03T18:32:12.113

1

@StuartMcCoy Currently there's a bug with the native URL Title auto-fill functionality. The developer has known about it for quite some time, but has offered no status updates on a fix.

– kgrote – 2013-01-03T20:16:36.857

1There was a bug but he recently updated Title Master which seems to have fixed the issue. I'm currently using it on a site I'm developing and it works fine. – Stuart McCoy – 2013-01-03T20:42:02.590

@StuartMcCoy I had to uninstall and re-install the module for the changes to take effect, but you are correct, the Title Master issue is fixed now. Would have been nice if the developer responded to all those support requests about it. – kgrote – 2013-01-07T16:41:08.943

@kgrote I think it's broken again in Structure 3.3.7. I'm not sure what changes from version to version of Structure that breaks Title Master so much but I wish Marc and Jack and Travis would work together to ensure this doesn't keep happening. – Stuart McCoy – 2013-01-08T19:09:54.623

1

This plugin doesn't support Structure i don't think, but it still works for making titles longer. http://devot-ee.com/add-ons/mx-title-control. The Title Master plugin looks to be no longer supported.

Just adding this info for future searchers.

Mike Lohrman

Posted 2013-01-02T22:39:34.067

Reputation: 374

1

I ran into the need for longer titles (eg. scientific paper titles), and (shameless plug) Zenbu Studio's Kyara module did the trick. Structure url titles are not supported as of this writing, however.

Zenbuman

Posted 2013-01-02T22:39:34.067

Reputation: 171

If it doesn't support Structure, it's not going to work for me. – kgrote – 2013-01-03T00:54:59.797