Global data in drupal 7 - drupal

I'm building one village's official site in Drupal 7. I need to create and store some information about village that will be accessible everywhere on the website (e.g. village's name, mayor's name, phone number, email, etc.). I want to define them in the admin site and access them in any node (e.g. all the data will be shown in the section about municipal office and some of them like phone number mentioned in the contact section. What is the best way to do that? Is there some module to handle that? Or should I write the own one? I have tried to search the answer there, but I found only topics about global variables (in PHP).

You can use the functions variable_get() and variable_set() to store arbitrary information that is available on all pages. It is easy to write a form that automatically saves all form fields with variable_set(), see http://drupal.org/node/222158.
Note:
- Saving variables with variable_set() will clear the cache of all variables, you should not use it for information that changes regularly.
- All variables are cached in a single, global cached and fetched on every single page request. You shouldn't store large amounts of data or data that is only used very seldomly.

The answer by Berdir is already very good in case you only want to store the raw data. However, if you always want to display the data in the same way like in some kind of widget format, you have other options, too.
For example, you could create a block with the contact details and you only show it on specific pages.
If you need more flexibility, you might consider to write a small module with different theming functions. You would either store the data directly in the module or in the variable table as outlined by Berdir.
In any case, if you want to allow the user to change this data on his own, you will probably need to write a small form in the backend. Otherwise, the user will need to manipulate the database directly to change the data.

You could also consider Creating advanced theme settings.
See how you can specify the site's logo path in your theme? You could do something similar with the info you would like to display on your site, practically setting up your theme as a template for a village website.
You get to add custom fields in your theme admin settings, field values can then be retrieved by using theme_get_setting()

Related

Drupal 7 - Functionality for multi-select of nodes and then action to send email to a manually entered email address

I have a webform setup along with a rule that creates a new content type called 'Idea' with most of the submitted data (so that comments can be made on node of type 'Idea')
The webform is for new ideas for the business and depending on the idea it then needs emailed to the correct person in the business so they can respond.
I know a way of doing this would be to create a drop-down list in the webform and assign an email address to that record (eg. IT > (email would go to > it.dave#company.com) but they don't want it to be in the control of the user in case they select the wrong person for the webform submission to go to, they want to be able to manage this themselves manually.
What is the best way to approach this?
I was thinking, is there some sort of multi-select option where you could select one or multiple nodes from the content page and then manually enter an email address, hit a submit button, which emails them.
They want to be able to enter the email part manually and not choose from a list as it may end up going to a large range of different people, not one of a pre-determined list.
I was possibly thinking if rules or workflow or workbench might help but never used the last 2 before, but if someone knows of a way that might be best to approach this it would be appreciated.
Step 1
Use the Rules module to create a Rules Component, which includes whatever Rules Conditions you might need (if any), and with a Rules Action to Send an eMail, for each of those fields you want to be updated.
Step 2
Create a view of the group of nodes for which those eMails should be generated. Then transform that view into a view that uses Views Bulk Operations, and use the technique documented in "How to use Rules to create a custom bulk operation for a VBO view?". In doing so, you'll then be able to use the Rules Component from Step 1.
Tutorial
To get the idea, have a look at the video about Using Rules components with VBO" which uses a Rules Component with (only) 1 parameter. If you want even more, then also watch the subsequent "Using Rules components with more than one parameter" video.
Attention: to process like 100.000 entities at once is quite a challenge (memory requirements, etc). Therefor you might want to also watch the video about "More details about VBO settings" ... Before you are tempted to use VBO for processing them all at once ...

wordpress custom fields: structured data table

I know how to make custom fields for my custom post types. But I need a pretty complex custom field this time.
I'm making a website about agricultural machinery. There are a lot of types of machines. For every type of machine there are some products available with properties like size, mass, diameter, capacity, ....
Per type there is only one description, one title and one image needed. So my custom post-type machine contains posts (custom type = machines) with the basic information. For every machine I would like to sum up all the different size - mass - capacity - prize information in a table. I know I could just create a html table in the description, but I would really like the data to be structured so I can nicely style it, and eventually even do structured searches for price and stuff.
So ideally I would like to have a custom field that looks a bit like an excel sheet where I can create some columns and add rows per available product in the category. Any ideas how I can do this?
EDIT: I'm trying out the Types wordpress plugin http://wordpress.org/extend/plugins/types/. There's an option to group custom fields together and also an option to allow multiple instances of one field. Would be useful for me if there would be a possibility to allow multiple instances of a group. Does something like that exist?
EDIT: This looks promising. http://wp-types.com/documentation/user-guides/bulk-content-editing-with-fields-table/
I will look into it and maybe answer myself if it turns out to work :)
It seems like wp-types had the solution all along.
http://wp-types.com/documentation/user-guides/bulk-content-editing-with-fields-table/
This is what my custom data table looks like now:
Behind the scenes, all data is not actually saved in a single post. But wp-types allows you to create hierarchical relations between post types, and then provides a way to quickly create sub-posts straight from the parent. That's awesome enough for me.
In my case I created two post types. One called machine-type and another called machine.
machine-type holds all the basic information about the machine (title, description and image) while it's sub-type machine holds the specs for any of the different variants.

Drupal data entry forms & db structure?

I'm trying to build a Drupal site in which users can input records containing data about "customers", "employees" and "sales".
I would like to be able to create a form(s) which takes data about a sale/customer/employee and can be associated with a record of a customer/employee(who made the sale)/sale.
I would also like to be able to display records showing a list of sales or customers or employees in which when clicking one record, it will open a page displaying all the relational data.
I'm new to development and am searching around like a headless chicken lol. I was thinking of using content types for sales/employees/customers and using individual nodes for each record then using something like views to displays filtered lists, but I am unsure if this is the best way to go about/structure it (maybe I should use separate custom tables or database and use a custom module to fetch the data?). It would also be nice if some of the fields can populate other fields based on it input and also if some fields can utilize a sort of auto-complete by garbing data from other records, or is that asking way too much?
Thank you for any suggestions you might be able to give me.
I, for one, would certainly prefer using a custom separate database and leave drupal databases to its own devices, if you would ever need to upgrade the site to a higher version of drupal it helps if you don't modify it, and also consider using webform (http://drupal.org/project/webform) as it makes development easier both in components and hooks.

In drupal, does features ignore or delete fields on live data?

We're considering using Features module for pushing out changes to production servers.
If a feature is to update an existing node with exisiting data, how will it behave?
For example, if the update will remove a field, will it remove all data corresponding to this field? If I just rename a field, will it create a new field on the node on the other server or will actually rename the field?
In general if you remove a CCK field on your local site -- you are liable to loose all your data in it. So if you move it to production, using features, the CCK field will get deleted on production and you will loose all your data there too.
Features repeats the same actions that you do on local machine on production machine. So if you simply rename the label on the field (or even the widget type on local machine) you are not going cause any data loss on local. That's because CCK allows people to change Labels and Widget types (though you cannot change the machine name anymore). Enabling the "renaming" feature on production will not cause data loss there too, just the label of the CCK type will change there.
You can perform the above as a simple experiment to verify it.
I am assuming you're not using crazy modules like http://drupal.org/project/cck_field_rename I don't know how features would behave in those scenarios.

How to additionally filter list of published nodes in Drupal 6

I need to adjust the way which a content is determined as published or not published. The editor of particular content (this is a separate non-administrative role) should have a possibility to set the published flag for particular node (it can be achieved using Override Node Options module directly or by implementing it's techniques). He should also be able to set two additional publication attributes, i.e. publication start date and publication end date (the fields can be added using Content Construction Kit). These optional fields should be used to determine node's published status. Let's say that if specified, they will override published flag.
Basically I would like to be able to add my bits of SQL code to the WHERE section of proper query or to postprocess result of such query. Maybe to overwrite some function or provide some callback. Solutions based on writing of custom modules are fully acceptable.
I am using Drupal 6.
It sounds like one of either the Node Expire or Scheduler modules should do what you need.

Resources