Juergen Posted August 26, 2016 Share Posted August 26, 2016 Hello @ all, I have created a very simple Textformatter module which should add a class to ordered and unordered lists. <?php /** * Processwire module for adding a special class for lists added via CKEditor. * by Juergen Kern * * ProcessWire 2.x * Copyright (C) 2011 by Ryan Cramer * Licensed under GNU/GPL v2, see LICENSE.TXT * * http://www.processwire.com * http://www.ryancramer.com * */ class TextformatterListCK extends Textformatter implements Module { public static function getModuleInfo() { return array( 'title' => "Textformatter for Lists", 'version' => "100", 'summary' => "This little Textformatter adds a class to the ol and ul tag (only for lists added via editor)", 'author' => "Juergen Kern", 'autoload' => false, 'singular' => false, 'permanent' => false, 'requires' => array( "PHP>=5.4.0", "ProcessWire>=2.5.28" ), 'icon' => 'list' ); } public function format(&$str) { $str = str_replace('<ul>', '<ul class="textlist fa-ul">', $str); $str = str_replace('<ol>', '<ol class="rounded-list">', $str); } } ?> Problem: This Textformatter is added to the body field, but it doesnt change anything and I could not find any mistake. Maybe someone has a better experience in creating Textformatter modules and could give me a hint why it is not working. Thanks in advance Link to comment Share on other sites More sharing options...
BitPoet Posted August 26, 2016 Share Posted August 26, 2016 The module itself is fine. Is the markup in the body field really what you think (i.e. no whitespaces or additional attributes in the ul/ol tags)? Does the content you look at really come from a body fields? Do you have caching enabled? Link to comment Share on other sites More sharing options...
Juergen Posted August 26, 2016 Author Share Posted August 26, 2016 Hello BitPoet, no whitespaces or additional attributes and the content comes from the body field. Caching is deactivated. Thats the reason why I am a little bit confused why it is not working Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted August 26, 2016 Share Posted August 26, 2016 Just to make sure... How do you check for output? In the frontend or in the admin? Link to comment Share on other sites More sharing options...
Macrura Posted August 26, 2016 Share Posted August 26, 2016 you might try using Tracy debugger, this way you can bd($str) inside the function when viewing the frontend and see what's going on there. 1 Link to comment Share on other sites More sharing options...
Juergen Posted August 26, 2016 Author Share Posted August 26, 2016 Hmmmm! Tracy Debugger says that this Textformatter module is not loaded (I cannot find it in the list of loaded modules) The other Textformatter that I have added to the body field will be loaded (it appears on the module list of Tracy Debugger). Link to comment Share on other sites More sharing options...
adrian Posted August 26, 2016 Share Posted August 26, 2016 20 minutes ago, Juergen said: Hmmmm! Tracy Debugger says that this Textformatter module is not loaded (I cannot find it in the list of loaded modules) The other Textformatter that I have added to the body field will be loaded (it appears on the module list of Tracy Debugger). In a rush, but when I install your module the flag field in the module's database table is set to 0. If you change that to 1 and do a modules refresh then Tracy shows it as loaded. Link to comment Share on other sites More sharing options...
Juergen Posted August 26, 2016 Author Share Posted August 26, 2016 Doesnt work in my case. After refreshing the modules the value is set back to 0. Link to comment Share on other sites More sharing options...
adrian Posted August 26, 2016 Share Posted August 26, 2016 I think the problem is one of these: 'autoload' => false, 'singular' => false, 'permanent' => false, Just remove all those and refresh and it should work - at least it does here. Link to comment Share on other sites More sharing options...
Juergen Posted August 26, 2016 Author Share Posted August 26, 2016 Flag stays at 1, but nothing happens on the frontend. I will take a closer look tomorrow. Link to comment Share on other sites More sharing options...
tpr Posted August 26, 2016 Share Posted August 26, 2016 Gave you tried clearing compiled files, or reinstall the module? Btw, multivalue textformatter (see my sig below) uses different methods than yours. Why is that? Link to comment Share on other sites More sharing options...
adrian Posted August 26, 2016 Share Posted August 26, 2016 2 minutes ago, Juergen said: Flag stays at 1, but nothing happens on the frontend. I will take a closer look tomorrow. Working fine here so I would try uninstalling and reinstalling. Is it now being loaded at least and just not formatting, or is it not even showing up as loaded by Tracy? Stupid question I know, but after all your testing, do you now definitely have it applied to the desired field? 2 Link to comment Share on other sites More sharing options...
Juergen Posted August 27, 2016 Author Share Posted August 27, 2016 After reinstalling it is not being loaded at all, flag stays at 1 in the db and it is definitely the body field where I have applied this Textformatter. I have created another CKEditor field for testing purposes and have applied this Textformatter too - same effect. The problem is definitely that the Textformatter will not be loaded in my case. I use the latest dev version (3.0.30) of PW. Link to comment Share on other sites More sharing options...
Juergen Posted August 27, 2016 Author Share Posted August 27, 2016 Hello @tpr, I see you use a different approach. Your function in MultivalueTextformatter looks like public function formatValue(Page $page, Field $field, &$value) { while my function is public function format(&$str) Could this be a reason? Link to comment Share on other sites More sharing options...
adrian Posted August 27, 2016 Share Posted August 27, 2016 A wild and unlikely guess, but any chance it has something to do with the case of your class name and your php version? What if you try: TextformatterListCk Note the lowercase "k" 1 Link to comment Share on other sites More sharing options...
Juergen Posted August 27, 2016 Author Share Posted August 27, 2016 Thanks for the tipp Adrian, I will try this if I am at home and post my results here. Link to comment Share on other sites More sharing options...
Robin S Posted August 27, 2016 Share Posted August 27, 2016 @Juergen, you should remove the closing PHP tag at the end of the file. For PHP-only files it's normally considered best practice to omit the closing tag, because you can get errors and odd behaviour if any character or whitespace is accidentally added after the closing tag. Not sure if that could cause the problem you're having (your module works normally for me). 2 Link to comment Share on other sites More sharing options...
Juergen Posted August 27, 2016 Author Share Posted August 27, 2016 Thanks @ Robin for the hint, I know this and i have tried it without the closing tag yesterday, but there was no influence. Currently I am not at home so I cannot test all the recommendations. 1 Link to comment Share on other sites More sharing options...
LostKobrakai Posted August 27, 2016 Share Posted August 27, 2016 7 hours ago, Juergen said: Could this be a reason? Both functions can be used to alter the markup. Only difference is that format() does not receive $page and $field. 2 Link to comment Share on other sites More sharing options...
Juergen Posted August 27, 2016 Author Share Posted August 27, 2016 Thanks for the Explanation @LostKobrakai Link to comment Share on other sites More sharing options...
BitPoet Posted August 27, 2016 Share Posted August 27, 2016 Another idea: is there a class with the same name (TextformatterListCK) lying around somewhere in an include path? 1 Link to comment Share on other sites More sharing options...
Juergen Posted August 27, 2016 Author Share Posted August 27, 2016 Thank you all for your contribution!! Finally I ended up with this piece of code, which works as expected: <?php /** * Processwire module for adding a special class for lists added via CKEditor. * by Juergen Kern * * ProcessWire 2.x * Copyright (C) 2011 by Ryan Cramer * Licensed under GNU/GPL v2, see LICENSE.TXT * * http://www.processwire.com * http://www.ryancramer.com * */ class TextformatterForLists extends Textformatter implements Module { public static function getModuleInfo() { return array( 'title' => "Textformatter for lists", 'version' => "100", 'summary' => "This little Textformatter adds a class to the ol and ul tags", 'author' => "Juergen Kern", 'requires' => array( "PHP>=5.4.0", "ProcessWire>=2.5.28" ), 'icon' => 'list' ); } public function format(&$str) { $str = str_replace('<ul>', '<ul class="textlist fa-ul">', $str); $str = str_replace('<ol>', '<ol class="rounded-list">', $str); } } It seems that the class name causes the problem, but I swear I have not the same class anywhere on the page. Maybe the CK in the classname was responsible for the behaviour. Anyway now it works. 3 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now