I've used markup field in the past with great success to add HTML markup to the edit areas of my input forms. I'm trying to find a way to add either PHP or tokens inside these markup fields now, however, and I'm not sure how to go about doing that. Simple stuff like inserting the node id (should work since I use multistep, so the node is already saved by the time the user would view this field), or pulling in information from their already existing content profile.
I checked around with existing cck field contributions, and none seem to do what I'm looking for, including computed field and dynamic field. Markup field seems the closest if I can just include PHP, or somehow add my own tokens for the module.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | markup-formats.patch | 1.25 KB | alonpeer |
Comments
Comment #1
sansui commentedI added $form['format'] = filter_form(3); to markup_field_settings, and that gives the form the input format selection. However, the value of the field isn't rendered as PHP. Any ideas?
Comment #2
sansui commentedAlright, I think I finally got it. Had to add check_markup to #value in hook_widget to process it as my PHP filter
Comment #3
Miguel.Andrade commentedThanks! This is a really useful feature. You just save me the trouble to figure it out myself.
I wish this to be in the next module release!
Miguel
Comment #4
Fidelix commentedIt worked like a charm! Thanks!
Comment #5
rfiertek commentedIs placing this code into the markup field adequate?
This does not seem to print out anything.
Thanks,
Rob
Comment #6
alonpeer commentedHere's the right implementation (can some plz create a patch? My Mac is having CVS issues at the moment):
Comment #7
alonpeer commentedOK, here's the patch.
Comment #8
smoothify commentedI will be adding this functionality to the module shortly, currently i'm not looking to go the input filter route though, and instead plan to take care of the php evaluation internally as other cck fields tend to do.
Comment #9
smoothify commentedI have just committed php functionality into the module. It should appear in the next Dev release, most likely dated the 16th December.
There will now be an 'Allow PHP Code' checkbox under the markup field in the field settings. Currently you can access the current node through the $node object. If any other objects or variables should be accessed in the code, please request here.
Comment #10
Fidelix commentedNice work @smoothify!
Thanks!
Comment #11
cyu commentedIf you want to evaluate PHP Code for a field, shouldn't you use Computed Field instead? Allowing PHP Code in Markup module suddenly makes this module very dangerous and will force me to re-evaluate who has permissions to edit content types and fields.
Comment #12
Fidelix commentedcYu, i sincerely dont see how it is dangerous.
If a user has permission to edit Content Types and fields, he can already break your whole site. So i don't see the point...
Comment #13
smoothify commentedComputed field does have a different use case, as it only displays on the node view and not the node edit form. This module of course is to display markup to site contributors as they edit nodes and doesn't save anything to the db.
Many other CCK fields such as text fields allow php code for things such as allowed values and default value - i don't believe they are protected by permissions or isolated in any way?
If they have permission to edit content types and fields, wouldn't that mean that they can add a text field or similar and execute php code in that way?
Personally I can't imagine a situation where I give permission to edit types / fields without trusting them not to run something dangerous - but if this is considered a valid concern, there are ways around it such as
- Put the php aspect in a separate module so if you don't enable it, you can't run it.
- Add a user permission for executing php code.
I'd be interested to hear the general consensus on this, or perhaps find out what approaches other field modules (that allow php) take.
Comment #14
cyu commented@Fidelix - there is a large security difference between allowing someone to administer content types and arbitrarily execute PHP code on your server.
@smoothify -
From the Best Practices section at: http://drupal.org/handbook/modules/filter
From a Lullabot article on input filters: http://www.lullabot.com/articles/drupal-input-formats-and-filters
At the very least, a separate permission to enable this feature or re-use of the "Use PHP input for field settings (dangerous - grant with care)" (which is what you'd need to add PHP to text fields as you mentioned above) permission would make me feel a little better about it.
My biggest concern is for the people who already have the module and do somewhat of a blind upgrade from the dev version to the first stable not realizing what power they are giving to their existing users that already have permission to edit this field. Outside of that, I still have a "healthy sense of fear" about the functionality in general but do see the use case for it.
Comment #15
smoothify commented@cYu
Point taken, I will definitely wrap some access control around it.
What would your vote be for?
1 - reusing content.module's "Use PHP input for field settings (dangerous - grant with care)",
2 - a markup field specific permission such as: "Use PHP input for markup field (dangerous - grant with care)"
Comment #16
Fidelix commented@cYu, i understood your concern, and i acknowledge it as truthful.
@smoothify, for the sake of simplicity, 1 would be better.
I cant see why would someone be alowed to use php for general inputs but not for markup fields.
Comment #17
smoothify commentedI have now added access control to the php code, reusing the one from content.module.
I had to change the way it works slightly, instead of having the markup field with an 'Allow PHP Code' checkbox underneath there is a separate text area field inside a PHP Code fieldset.
The reason for this is, with the checkbox it would be possible for an administrator to allow php code for a specific field, but then leave the markup (therefore the php code itself) editable by those with edit content type permissions.
Instead, now an administrator can add php code for a field, and those with the edit content type permissions can see the code but can't edit or override it.
http://drupal.org/cvs?commit=466668
Comment #18
Fidelix commentedNice idea smoothify. This approach was interesting...
Comment #19
Vote_Sizing_Steve commented#17 works well, providing that there is some kind of text (like 'Placeholder for PHP code below') in the html field - it won't get displayed with the php, but without it the php won't get displayed.
Comment #20
candelas commentedis this already intregated in the dev version?
my client wants to see the article node nid when editing and i am not finding a solution in any module.
if not, can anybody please tell to me how do you do it?
thanks
Comment #21
smoothify commented@candelas
Yes, this is in the dev version, and there is access to the node object.
Comment #22
candelas commentedso i go to try it.
thanks a lot lot for sharing your code with us :)
Comment #23
candelas commentedsmoothify i am trying to use it but i have a luck in understanding.
if i put a text in the markup field, everything works but if i write in the php field, it doesn't work.
my code is very simple
i am looking on the issues but i dont find howto do it.
can you give to me a tip, please? :)
Comment #24
candelas commentedi also tried to write it as in default value with php on other cck fields but also, it doesnt work...
also, if i write in both fields (markup and php) it gives to me this error (i write it just in case it would be useful to you)
thanks for your time :)
Comment #25
smoothify commentedHave your tried simply returning the $values:
This does need some more documentation though :)
Comment #26
candelas commentedi just tried but the markup doesnt show.
i am trying in a form on a story tipe of content with the only field added is your markup.
and yes :) i have to learn much php.
gracie mile
Comment #27
candelas commentedi have tried also
but the markup (nor field wrapper, nor label) will show in the edit node form.
if i write markup and not in the php field, it shows.
I just installed devel module to see if i found something to help :)
Comment #28
candelas commentedme again :)
in a new installation with only view and cck, if i dont put php and write in the normal markup field i get
but if i write in the php, i dont get anything in the html.
?¿?
Comment #29
candelas commentedgood morning :)
one more thing that i forgot is i am working with drupal 6.20
Comment #30
smoothify commented@candela
You are right, there was a bug in this functionality.
I have now committed a fix to the git repository here:
http://drupalcode.org/project/markup.git/commitdiff/e73695d
This won't be in the next automated dev release until midnight GMT, but you can retrieve a patch from the above link, or get the new module file here
Let me know how you get on :)
Comment #31
smoothify commentedI forgot to add, the intended behaviour is to use print or echo to output any text, but return does seem to work too.
Comment #32
candelas commentedthanks thanks!!!!
it works as i needed!
i put my code here just in case someone needs it :)
i dont change the issue fixed because maybe you want to make something else ;)
Comment #33
candelas commented:)
another little bug... i report here because i think it is not that important...
since i dont do webs often, i do a trick to conserve especial fields that i create.
so when i try to add the field to this new content type using the the possibility of "select an existing field" and save it, i get this error in the page where i am redireted to modify it (admin/content/node-type/story/fields/field_identificador)
then i give the order to save and it is ok.
if i try to edit the field, no more warnings...
i have disable all the modules but cck and views and i get the same error with a fresh db.
i mean, first time when i create the markup, all it is ok but, when i add the field to another type of content, i get the error.
i am on ubuntu 10.04 and mysql server and client 5.1
i pleasure to contribute on this little debugging.
and now i keep with my work that i am late!!! o.o
Comment #34
candelas commentedhello again :))
one thing that i dont know if has to be with your module or it is a conflict with hierarchy select
now i started to rebuild the site with pieces that i have construct. so i made active the hierarchie select module an when a content has your field, when i go to add that type of content, i get this error:
I looked into issues on hierarchy select and nobody talks about this.
I also made searches through internet and nothing that i could find.
now to eat and sleep and tomorrow afternoon, more :)
Comment #35
candelas commentedi have tried your module without hierarchy select and other kinds of fields and no problem (number, text, select) and nomal taxonomy fields (default from drupal).
i dont undertand the problem (i have used hours to do it but drupal is too big for me in the amount of time that i have to finish this project).
so i find a "while solution": it works and roles dont see the problem... (dirty one)... i dont like to work like that but... while we find the solution (i will ask a friend that is a excellent programmer for tips) i can keep working because.. :( i need to finish... or i will do it throught theme (also no as good solution as your module for updates).
thanks a lot, your module is a big help :)
i will have an eye for updates on it!
Comment #36
candelas commentedmore :))
the workflow module field lets you put permssions on the workflow for the different cck fields.
you can check a field as editable and viewable.
the rest of the cck fields work ok with this but, the makup has to be editable for it to be seen.
AND has to have editable permissions in the modules permissions for that field in the drupal core permissions.
it made me crazy!!
i almost stopped using markup.
so, i think it would be a nice idea to put this on the documentation :)
by other side, when i preview a node, the error line about 429 that i mention before appears twice.
i will tell here all the things i go seen, just in case they help to you to debug :)
Comment #37
anybody