Soma Posted April 1, 2014 Share Posted April 1, 2014 Ah sorry for the misinforming, ok it's the value is returned by the formatValue so you grab it via $event->return. This should work: wire()->addHookAfter("FieldtypeText::formatValue", null, function($event){ $value = $event->return; $value = str_replace(array("<p>","</p>"), "", $value); $event->return = $value; }); 1 Link to comment Share on other sites More sharing options...
bytesource Posted April 2, 2014 Author Share Posted April 2, 2014 @Soma Now everything is working! Thank you so much for your help and patience! Cheers, Stefan Link to comment Share on other sites More sharing options...
bytesource Posted April 4, 2014 Author Share Posted April 4, 2014 Hi, I only today realized that the following hook is not working fully as intended: wire()->addHookAfter("FieldtypeTextLanguage::formatValue", null, function($event){ $value = $event->return; $value = str_replace(array("<p>","</p>"), "", $value); $event->return = $value; }); It also gets called on FieldtypeTextareaLanguage (I am only using FieldtypeTextLanguage and FieldtypeTextareaLanguage). I verified by adding: echo $event->arguments("field")->type; inside the hook function. Does anyone know why this happens? Cheers, Stefan EDIT: Removed a typo: (I am only using FieldtypeText and FieldtypeTextarea) changed to: (I am only using FieldtypeTextLanguage and FieldtypeTextareaLanguage) Link to comment Share on other sites More sharing options...
Soma Posted April 4, 2014 Share Posted April 4, 2014 I'm not sure I fully understand, it doesn't get called also on FieldtypeTextareaLanguage. And how do you now if you say you only use FieldtypeText and FieldtypeTextarea? One thing I could imagine is that FieldtypeText is base fieldtype for a lot of the other text fieldtypes, but testing here it works fine and only is replacing for the FieldtypeTextLanguage. Link to comment Share on other sites More sharing options...
bytesource Posted April 4, 2014 Author Share Posted April 4, 2014 @soma I am sorry, there was a typo in my previous post. What I wanted to say is that I am only using FieldtypeTextLanguage and FieldtypeTextareaLanguage at the moment. When I echo the type of the field the hook is called on, I get both FieldtypeTextLanguage and FieldtypeTextareaLanguage as output. You are right about the fieldtypes: FieldtypeTextareaLanguage extends FieldtypeTextarea FieldtypeTextarea extends FieldtypeText Also, I actually made two hooks to cover both FieldtypeTextLanguage, and FieldtypeText (although I am not using FieldtypeText at this moment, but will later): $fieldClasses = array("FieldtypeTextLanguage", "FieldtypeText"); foreach ($fieldClasses as $class) { wire()->addHookAfter("$class::formatValue", null, function(HookEvent $event){ $value = $event->return; $value = str_replace(array("<p>","</p>"), "", $value); $event->return = $value; }); } Cheers, Stefan Link to comment Share on other sites More sharing options...
netcarver Posted April 6, 2014 Share Posted April 6, 2014 @bytesource I know Soma has a perfectly good solution to this (adding the Paragraph stripper) but I'd like to support single-fields directly in textile so I have just checked code into the master branch to add this ability. I hope to do an update to the textileTextformatter soon that will let you get at this directly without having to strip anything using a second formatter. Link to comment Share on other sites More sharing options...
Soma Posted April 6, 2014 Share Posted April 6, 2014 It's not me it's PW having a designed built in solution. If you hardcodre it into textile textformatter it should be optional. Link to comment Share on other sites More sharing options...
netcarver Posted April 6, 2014 Share Posted April 6, 2014 @bytesource I just pushed an updated TextformatterTextile module that adds a new formatter: TextformatterTextileField that should do just what you need without you having to hook things or use the P stripper. 2 Link to comment Share on other sites More sharing options...
bytesource Posted April 7, 2014 Author Share Posted April 7, 2014 @netcarver Thanks a lot for this update! I agree adding an additional formatter is a good choice, as it does not break existing code. Cheers, Stefan Link to comment Share on other sites More sharing options...
bytesource Posted April 7, 2014 Author Share Posted April 7, 2014 @netcarver I noticed that the array on line 35 of TextformatterTextile.module was not closed. After fixing the typo and updating the modules in the module section of the admin, I wanted to install Textile Field. However, the install button was diabled as can be seen on the attached screenshot. Do I need to first uninstall the old Textile module and then reinstall the updated one from within the admin? What I did was replacing the old folder with the new one before hitting 'Check For New Modules'. I was afraid that reinstalling the old version first might de-attach the Textile formatter from its respective fields. Cheers, Stefan Link to comment Share on other sites More sharing options...
netcarver Posted April 7, 2014 Share Posted April 7, 2014 @bytesource Thanks for that. I've fixed it and pushed it up to github. Regarding installing the new version. I'm not sure about the 'official' way to go about this but I think Ryan will have orphan checks built in to the code so you can't just un-install things that are in use. As the new version still provides exactly the same formatters as before I'd try backing up the existing folder (somewhere out of your directory tree) then dropping the new module in its place and then hitting the 'Check For New Modules' button and seeing where it gets you. Otherwise, switch the old folder back in, remove the formatter from your fields, deinstall, switch out etc. 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