drupal - collection field with status - publish checkbox - drupal

is there a way to have a publish checkbox on a collection field associated to a content type ?
if i have 3 items on a collection field associated to a node , one i want to set it unpublished so only 2 are displayed.
cars content type:
-mercedes....
-bmw.....
-audi.... = unpublished
Thanks

By default (through the UI) you can't do it.
You can do it programmatically by adding a check-box on your collection by using _form_alter() and add your own validation callback where you'll can modify referenced node accordingly.

Related

vtiger 7 related module quick create autofill

I've created a custom module and related it to vtiger organizations module. The custom module has an uitype10 attribute to link the record to the organization.
Everything works except that the organization name field in the quick create form of my related module is not automatically filled in. What I mean is:
if I go to organizations list, click an organization, click on Contacts icon and then click on the add button to add a new contact from the organization panel, the quick create form shows the organizazion name already filled in with the organization name I currently am in.
if I go to organizations list, click an organization, click on my custom module icon and then click on the add button to add a new record from the organization panel, the quick create form shows the organization name as empty. I have to manually write the organization name in it.
What I need is that my module behaves like the contacts module, so when I add a new record from the organization panel, the field for organization name should already filled in.
Any idea on how to achieve this?
Vtiger store Relation between 2 modules in vtiger_relatedlists table and based on details in this table Create Button URL will get generated in function getCreateViewUrl() in RelationListView.php. You can get core file in modules/Vtiger/models/RelationListView.php.
Solution : Table crestel_relatedlists will have relationfieldid which store the fieldid of your organization module against relation with your module. If relationfieldid is set to "0" then you have to set it with exact fieldid which you can get from vtiger_field table.

Drupal 7 get node reference custom field in path auto pattern

In drupal I have 2 content type "events" and "news". news content type have a node reference field "field_associated_event" to select events from events content type. events have also 2 another field text field "field_url_one" and "field_url_two"
In path auto pattern for events
[node:field_url_one]/[node:field_url_two]/events
For news url I want to get this but it's not working
[node:field_url_one]/[node:field_url_two]/news/{news alias} - not working
at give result in url only : news/{news alias}
I have using entity, entity reference module but not get token to reference fields. It get only event title if I used
[node:field_associated_event]/news/{news alias}
It works fine and get event title in url.
How to get event fields in url for news page?
You need to install Entity tokens module (comes with Entity module). Then you will be able to use [node:field-associated-event:field_url_one] and [node:field-associated-event:field_url_two] tokens in your path patterns.
Note using hyphen instead of underline (i.e. correct is [node:field-associated-event], NOT [node:field_associated_event]).

Drupal 7: how to filter view content (with entity reference field) based on current page content

in my drupal 7 I have 2 content-types like these:
ContentA
ContentB (with a field Entity Reference to ContentA)
In the front-end detail page of ContentA, I would love to show a block/view with a list of ContentB whose Entity Reference field is set to the current ContentA.
I made a view of type Block and added it correctly to the page, but I cannot filter ContentB based on the current ContentA.
Could you help me?
Thanks
You should add a contextual filter for the value you will use for filtering to the block View of ContentB.
Then in your contextual filter in the "When the filter value is NOT in the URL" area select "Provide default value" and Type "PHP code" (You should have enable php filter for this). In your php code area you should have the following code
$node=menu_get_object();
return $node->field_your_machine_field_name['und'][0]['target_id']; // this is the field you will use for fitlering
Hope it helps
UPDATE
The above code will work if you need to show in your block similar results with the same selection (for example similar results of ContentB with the same selection in the referencing field of ContentA ).I will not delete because you might need it also in your project.I misunderstood. Actually the solution is simpler. You should add the contextual filter to the field and in "When the filter value is NOT in the URL" area select "Provide default value" and "Provide id from url"

Drupal views, get node id from url

I want to make a view, that can show a single blog post. This is to be used in a panel.
Is it possible to create a view, that show a node getting the node id from the url?
I have tried creating a view with :
CONTEXTUAL FILTERS -> nodeid -> WHEN THE FILTER VALUE IS NOT AVAILABLE
->Provide default value -> Content ID From URL
This does not seem to work though, maybe the URL to the panel holding the view is constructed wrong?
1) If the panel page is a node template override it will have no problems and it will work without extra settings (you will see that also when you set the panel pane, there are not extra settings).
2) If not (eg if it is a frontpage panel page) you have to pass the argument from panel to views. The path for that page should have a nid argument or a panel pane may have this. Eg your path may be "home/%node". And you have to add a context to your panel that is of type node. Then Assign the Node: id to this argument.
See a similar discussion at https://drupal.stackexchange.com/questions/63538/how-to-pass-a-nid-to-panel-and-load-a-node-with-the-given-nid-as-context

Entity reference field and dependent dropdown

I have a content type with an entity reference field referencing to a custom entity. I need to use a select box because an autocomplete widget is not suitable in my case. However, I cannot load all the entities at once as selectable values because they are too many (72000+ the form won't even load). So I default the entity reference select box to a limited number of values using a views filter and then hide it by default. Then I use an ajax dependent dropdown to show and populate the entity reference select box with filtered down values (I'm using a module that implements hook_form_alter).
My problem is that the form won't validate because now I can select entity reference values which are not the default ones in the select box. So I guess I should control in some way the validation rules of the entity reference field. Is there an easy way to do this? Which hook should I use?
Set the entity reference field to autocomplete and take it out of the process entirely in your form alter with $form['field_entity_ref']['#access'] = FALSE. This should fix the validation problem. (of course, "field_entity_ref" is what I'm calling your actual reference field.
Add your own validation to the form, if that is still necessary.
Finally, implement hook_node_presave() to manually put the value of your custom ajax drop down box.
So if your custom ajax select box was named my_custom_ref, then it would look something like this:
function mymodule_node_presave($node) {
if (isset($node->my_custom_ref)) {
$node->field_entity_ref[$node->language][0]['target_id'] = $node->my_custom_ref;
}
}

Resources