Drupal - Views + node preview woes - php

I have a few Views on my Drupal 6 site which take care of some of a node's fields.
For example, I have a content type called Country, which has a field called Capital. I've excluded this field in the node display, but there is a view that takes the node ID as an argument and displays it in the right column. This is all very pretty and has been working out well for me, but how do I take care of the node preview mode? Since the node isn't saved yet, the Capital field won't have its new value yet.
Note: I am ready to do some very dirty hacks to make this work :)

don't hack drupal! :)
One of not so simple and unchecked idea:
use hook_form_alter or hook_nodeapi with validate in custom module, there's you should see data of new capital field, save it somewhere (for example, into sessions), and show it's into block via theming Views field.

Related

How to add a form field to modx 2.2.14 manager pages

I'm trying to add the editiedon field to the modx manager pages so my users can edit the value using this bit of documentation as a start point:
http://rtfm.modx.com/revolution/2.x/case-studies-and-tutorials/adding-custom-fields-to-manager-forms
Which does work, but:
how can I make that a date/time field?
how can I place it in the settings tab of the given resource?
Isn't input type="date" the answer to the first question? I'm not sure how you would do the second part, unless you managed to get the rendered content and splice it in there somehow (unless theres som hidden specified method).
Otherwise, you could always solve it with regular form customization. You'll want to create a TV of type Date, and give it a custom default data through a snippet, that just fetches the current resources editedon value. I guess you only need to update the resource/update form set. Under the template variables tab of the set, make sure your TV is connected and change the region value of it to "modx-resource-settings"
There are two different ways which have their own pros & cons.
At first you can use template variable with Date type. It gives you correct ExtJS component for dates and you'll see calendar in TV's tab.
If you'll choose this method you have to create a plugin which invokes on OnBeforeDocFormSave event. There you can redefine modResource editedon property from your TV and it will be saved in proper way. Also you may invoke another event(OnLoadWebDocument). There you can set modResource editedon property from you TV if you want to see correct data.
Pros:
fast calendar integration to the one of modResource's tab
you can use Form Customization for security reasons. It's rather easy and from the box.
Cons:
Additional TV which complicates modResource updating process a little bit
Another method is more complicated (you need skills in ExtJS).
Create plugin which invokes on OnDocFormPrerender event. You can add JS to the modResource page there. Your scripts should render new custom tab to the document where you can add your special field with calendar. So there is special ExtJS component in MODX for these purposes. And of course you need events from first method for loading and updating editedon value.
Also you can just render special field to the existing tab instead of creating new tab and rendering your custom field to it.
Pros:
you don't need TV anymore
it's flexible
Cons:
it's more complicated and takes time
P.S. You can view Xlexicon github repo. There you can find example of rendering new tab and manipulation with modResource properties.
Also you can check modAvatar extra for MODX. There is an example of manupulation with existing tab.

Drupal, Ubercart - Add custom field to checkout form

Need help of Drupal experts.
My purpose (with Drupal 7 and Ubercart 3 in hands) is to add a custom field to the Checkout page, that should be dynamic (values from ajax request) and it content depends on user's delivery city input.
With "Extra Fields Pane" module I've successfully created field with some placeholder value. Than, I use JS methods to append values to that field. The problem has appeared when I submit form with that dynamic-added selected value - I have an "invalid selection" error for that field. When non-added-by-js value (placeholder) selected - everything works as expected.
Can you please hint me solution to that problem?
I found one here https://stackoverflow.com/a/5159013/837255 and it seems to be a common approach, but here other issue begins.
In %my module% in a hook I can't access field to do manipulations on it.
Example of how I need to make changes in created by module 'ajax_field_name':
$form['panes']['delivery']['ajax_field_name']['#ajax'] = ....
But my *cking pane has no any $form['panes']['delivery']['ajax_field_name']. When I do var_dump($form['panes']['delivery']) I see that 'ajax_field_name' located somewhere in $form['panes']['delivery']['address']['#uc_addresses_address'] OBJECT behind a private property.
function uc_nova_poshta_form_alter(&$form, &$form_state, $form_id){
if ($form_id == 'uc_cart_checkout_form'){
$obj = $form['panes']['delivery']['address']['#uc_addresses_address'];
// addressBook is a private property
$obj->addressBook;
}
}
In fact, this code does what I need -
$form['panes']['delivery']['address']['ajax_field_name2'] = array(
'#type' => 'select',
...
}
creates a custom field, in a right place, with access to it, BUT only in that form and this field does not affect any further activity (order review, admin pages, etc.). Also in $form['panes']['delivery'] this field ('ajax_field_name2') is located separately from created with module 'ajax_field_name'.
I guess the reason of this behavior are some modules e.g. uc_addresses (am I right?), but even when I disabled most suspicious of them - the problem is still there.
Is there a possibility to find out how to get access to 'ajax_field_name' created field?
Thank you.
This may not completely solve your problem (if you still have it as this seems a rather old question...), but one problem is you are using the wrong hooks. You should use hook_uc_checkout_pane_alter and target uc_checkout_pane_delivery to accomplish this. I learned this the hard way trying to set the default country selected to something other than US; things will break badly if you manipulate them via hook_form_alter and it's variants.
I'm working through something similar right now. I will update this answer with further information as I uncover it.

How to use entity field type array with multiple different form widgets in symfony2

I am looking at an entity called content where I will store data about the content (textfield1, textfield2, bgcolor etc.) in an array inside the entity content (if this is not the best way to go please advice me).
The reason I want to put it in an array instead of just making separate entity fields for it is that I will have different 'content templates' so the amount and type of data fields will be different for each template (and each template of course has its own formbuilder; ContentXType.php, contentYType.php etc.). While one content type might have only one textfield, another might have 10.
I initially started on a design with datafield1, datafield2 etc. but realized that will leave me with a bunch of nullvalues and won't really be pretty =)
At savetime I will generate an html output for this content in a different field called contentRendered.
At edit time I will again want to be able to open up the different datafields from my array in different form widgets, so for example textfield1 in a textfield, textfield2 in a textarea, and bgcolor (the third value of my array) in a colorpicker form widget (I guess I will use a textfield with a jQuery color picker widget).
So my little issue is whether entity type array is the best way to go for this, can I even from within my form builder pick out value 1 from the array and put that in one field, value 2 in a different form field etc.?
Or do I need to go with say a new entity called content_data and use relations?
Or would a better way to go be to define a new entity for each kind of content I plan on using, and then embedding a form for that content type in my main content form?
After some more research I will define a new entity for template in which I will specify my templates, and have different twig files for the rendering of each template.
The actual data for each template, which will be of variable amount of fields, will be stored in a serialized array.

copy CCK content (for auto translations) upon new content created tigger in drupal

what I want and need to do is upon the event that triggers when a new node is created, is first to translate it into every language enabled except the one is created and copy and even translate if possible the CCK content.
I'm doing this with triggers and it is creating and translating the content but only the title and body (non CCK)
What I want to do is copy the images that were uploaded on the original node, set the dropdowns, etc etc..
of course it wouldn't be bad to use the i18n gtranslate to translate the textboxes and textfields to the translated CCK on the new node when the event triggers :)
I'm sure this problem was solved before, but I don't know how to affect the newly created node and use it's CCK ... and how to refer to the original node from which is being translated on the php evaluation block..
If you are using the module Rules, you will be able to create "actions" which is basically a callback where you can do whatever you want.
You execute those actions when an event is triggered (let's say for example when a node is created) and if a set of conditions is evaluated to true (node type, if some fields have some particular values etc).
In this action callback you can fetch the "source node", generated a new node which your translations on each field and then save a node for each language.

How to have drupal views show dynamic content based on node

Is it possible to have views show a query based on the current node (not 1 set node but any node)
my situation:
A user submits a node with information
another user can donate to that node from another content type using 2 fields: node reference (to pick the node) and integer (to enter donation amount)
I need a block view to show all the donated amounts for the current displayed node
(would be even better if someone told me how to just all the donated amounts up to show the total amount!)
thanks in advance
If you need dynamic filtering, views arguments is your friend.
After you add fields and filters, add an argument Content: node reference (the name would be whatever you chose to name it, but make sure it's node reference).
In the argument setting, for "Action to take if argument is not present" click on provide default argument and choose Node ID from URL, do validation.
Add a block view and enable it on the block settings page. It's only going to show on the appropriate nodes.
Check this tutorial for more detail.
To do calculations, take a look at Views Calc module.

Categories