Drupal 7 - How to edit a value stored in variable table - php

I have inherited a multi-site in Drupal 7. There is a page where the client needs to edit the title element but this page is not a content type, a block or a taxonomy item!? I have queried the db and found only one instance of the value which needs to be changed. It is stored in the Variable table. If I change the value here the value changes as expected on the site. Can anyone shed any light on where the administration page is likely to be for this value based on the location of the value? I guess this could be defined anywhere really but was hoping someone may have come across this before.

You can change any variable value by using variable_set.
// Example
variable_set('variable_name', 'value to save');
Another way is to use devel module. After enabling the module; Go to ?q=devel/variable, find the variable you need to change from the table and click on Edit next to it.

The values of variables in Drupal can be set in a couple of ways:
From code - Using variable_set() function.
Look in the code if anywhere this function is called to set the value of the variable. If this is the case, you can implement your own module with some configuration form to override the value of the variable.
From a form defined using the Form API - Using system_settings_form() function.
I'll suggest you to look for the name of the variable who's value is used to set the page title, and then search in the code if there is a form element by that name, which is returned using system_settings_form. Then find out where this form is rendered - might be at some menu. After which you can change the value of this variable from the form itself.

Related

Can I get a hidden value from the backend form by hook?

In Typo3 9.5 I'm trying to read a hidden value from a page which holds the ID of a specific content element. I'm using a hook for some calculation and thought I could reuse the hook to check if a value changed. If the value changed I want to delete the content element. Right now I can create the element and save the ID in the hiddenValue. But the hiddenValue is never passed to the preProcessFieldArray or the postProcessFieldArray which I use.
I did add a passthrough field but this seems to not affect the fieldArray. I can't find anything on the passthrough type in the documentation

How do I get data from a content type field into a view?

I have a client who wants to be able to put a custom header on certain views. However, I don't want to give him access to edit the view header, so I've put a field in a content type that is being used for the view with the machine name field_related_content_title.
The machine name for the content type used is landing_page, and the view's machine name is related_content.
I'm not quite sure how to make this work. I have the basic idea, that I would use a hook in template.php (but not at all sure which one to use), and I'm sure my logic is faulty.
Any tips would be appreciated. Thanks!
Configure the view in order to have a header (Custom text, por example). Then, in your module you can use the hook views_pre_render:
function mymodule_views_pre_render(&$view) {
$view->header['area_text_custom']->options['content'] = $view->result[0]->field_related_content_title[0]['rendered'];
}
This will put the value of the field_related_content_title field (for the first views result) in the header of the view.
You can show this field value in the same way you show the other fields. If you are using views ui, put field_related_content_title as the first field (using hide if empty, if you want).
My answer is a question: does this view show only one item (landing_page), or multiple?

Drupal 6 php for node.tpl field contains rather than equal to

I've edited my question as a response to the first commenter.
I'm new to PHP and Drupal templates and an not an experienced programmer.
My organization has events throughout the year. For each event we make recordings, speakers slides and other materials available to either anonymous users or just our members (a custom role). Each event has multiple files and whether they're made available to anonymous users or our members is made a file-by-file basis. So an event can have certain files available to anonymous users and others available only to our members.
We're using the ImageField Extended Fields module to add fields to file uploads and have a checkbox called "Make Public" along with "Description" and "Sort Order" (which I'm hoping can be used to order the files for display on the page... but that's not a priority). A content editor will check the box to make the file available to anonymous users but the default is just for our members.
The first commenter said the field contents look like a serialized array:
a:3:{s:11:"description";s:50:"text text text text text";s:19:"fapi_sort_order_key";a:3:{s:4:"body";s:1:"1";s:6:"format";i:0;s:5:"style";s:9:"textfield";}s:29:"workflow_fapi_make_public_key";i:1;}
I would like to evaluate this field to see whether the "workflow_fapi_make_public_key" portion is 1 or 0 and have the node.tpl.php file display differently depending on the results.
I started with
<?php if ($node->field_eli_event_files_data[0]) : ?>
then moved on to
<?php if (strpos($node->field_eli_event_files_data, '"workflow_fapi_make_public_key";i:0') !== FALSE) : ?>
<h1>Hi there!</h1>
<?php endif; ?>
. The latter statement always came up as false.
Any advice as to how this can be best accomplished would be greatly appreciated.
Thanks.
The value of the field that you have submitted is the serialized form found in the database, i.e. a string used to store the value of a complex variable - an array in this case - in a single database text field. You won't find this string anywhere in the node object. If you need more information on that, please refer to serialize() and unserialize() functions documentation in the php.net site.
If you need to test the value of workflow_fapi_make_public_key you will find it in $node->field_IMAGEFIELD_NAME[0]['data']['workflow_fapi_make_public_key'] (you should verify this via Devel module or another way to inspect the node's content).

Using POST function in Smarty

Can someone explain to me the exact steps on how to use the post function in Smarty PHP? I have to be leaving something out somewhere, and I'm not sure what. I'm workingin CMSMadeSimple and I want to post a variable from one form to another, except the variable doesn't exist in the first form. What are the steps I need to take to do this?
Clarification: I am using a module in CMSMS called FormBuilder. This module is accessing info from Products, another module. Now, these fields are what I'm trying to access. For instance, I am trying to pass info from the first form to a field in the second form which should be selected, where the name is "cntnt01" and the value is "205".
To assign the variable where it will be available to the first form, you need to call $smarty->assign() in the PHP script that produces the first form:
// Assuming your Smarty object is $smarty
$smarty->assign('variablename', $variablename);

Custom drupal form with predetermined values

I need to customise my forms in drupal so that each field has a value placed in it using a php script.
I have a php script which takes a url and gets a page title and meta description. It's easy enough to pass these values into a form by placing the required php in the input value. I can do this on a static 'test' form.
However, I'm not sure how to do this with a node form as I don't directly have access to the input value.
Any ideas or solutions would be greatly appreciated.
Use hook_form_alter() in order to alter some existing form entity. A basic knowledge about Form API and module development is sufficient.
I'd suggest using JavaScript to accomplish this since it's very good at manipulating form values (in Drupal too). If you can get the variables in JavaScript then it would be as simple as setting the input id value on page load.

Categories