You are hereModules

Modules


"Price is locked and cannot be edited" - how to unlock this or any other field

So to cut it short, just write this in your code, probably devel/php, change the filed name and you will have unlock a filed (probably commerce_price field).

$field_name = 'field_name';
$field = field_read_field($field_name);
$field['locked'] = 0; // 0: unlock; 1: lock.
field_update_field($field);

After you do what you need to do, you should put it back to lock.

Importing wordpress (ver 3 and 4) users to Drupal 7, how to solve password problem

So importing data from WP is not so hard, you can do it in different ways, mapping data as you need. But what to do about passwords. they are encrypted, WP uses "one-way encryption" and you will need hacker to know what is in them. There are 2 methods.

1. Copy paste

Ajax error on node add/edit, opened a new browser window instead of file upload or reference edit

One of those things. We have spent 4 hours, 2 persons combined hunting down this problem. Google GTM code, which we for specific reason enabled on node add forms, broke all ajax forms and made crayze problem of opening new browser window instead of editing the node reference field with inline entity form. The same thing happened also on image upload widget. Remove google GTM code from page, solved the issue.

Two ways to change patterns in pathauto

First is to use hook_pathauto_pattern_alter and add some code to it like

function hook_pathauto_pattern_alter(&$pattern, array &$context) {
// Switch out any [node:created:*] tokens with [node:updated:*] on update.
if ($module == 'node' && ($context['op'] == 'update')) {
$pattern = preg_replace('/\[node:created(\:[^]]*)?\]/', '[node:updated$1]', $pattern);
}
}

where in context you will find all the date you need to match specific entity and language

Or you can use Variables and make a token out of it and it is i18n aware.

Getting product display info from product ID and building node object with only needed fields

So we make query to get node ID from particular product ID

$query = new EntityFieldQuery;
$query->entityCondition('entity_type', 'node', '=')
->propertyCondition('type', 'product_display')
->fieldCondition('field_product_reference', 'product_id', '1092', '=')
->range(0, 1);

If node is present, we do the array building

if ($result = $query->execute()) {

$nodeview = $result['node'];

// At first we need to get field's id. If you already know field id, you can ommit this step

RESTws using PHP-CURL to update or add data. Loging in and authentication

Although there is an article here about it http://blog.ampli.fi/creating-drupal-7-nodes-with-php-via-the-restws-api/
I will copy mine code I used to test, just in case.

Things to watch out for is NOT to include JSON suffix, when using CURL

* Update: HTTP PUT //.
or HTTP PUT // (requires HTTP
Content-Type header set to the MIME type of the posted format)

and the hard limit when querying.

theme_debug twig debugging in drupal 7

For some time this has been in drupal 7, ported from drupal 8
https://www.drupal.org/node/2307505

But not really mentioned much. Its a nice feature where you get directly in your html template file names you can use for changing html.
Looking like this

so you done need to DPM and see what is what for each content part, just have it all there. How to activate it?
Just set variable to TRUE

Loading content with AJAX link, anywhere

There are different methods and bunch of modules to ajaxify links in drupal. There are different solutions with code, like this one
https://www.drupal.org/node/2046693
and there are more simple I would add, like this one
http://codekarate.com/blog/drupal-7-javascript-ajax-framework-example-link

I used variation of the codekarate tutorial. To put my AJAX link anywhere. I used template, to be more precise I added a custom form element in rendered array. Like this

$content['helpful-comments'] = array(
'#type' => 'link',
'#title' => t('Most helpful first'),

Custom form, custom template or preprocess function

Having custom template or function to preprocess your custom form in module has few tricks.

First you need to define it in form

$form = array();
$form['#theme'] = 'my_form_theming_function';
....

then define hook_theme

function my_module_theme() {
return array(
'my_form_theming_function' => array(
'render element' => 'form',
),
);
}

and then finally define that theme function in module as

function theme_my_form_theming_function($variables) {
dpm($variables);

Add title/label to fivestar field in custom form

Took time to find out this one. To set title or label for a fivestar form field you need to add
'#title' => t('Your rate'), to your code, so it should go like.

$pane_form['rating'] = array(
'#type' => 'fivestar',
'#default_value' => 100,
'#title' => t('Your rate'),
'#widget' => array(
'name' => 'some__stars',
),
);