Pages

Saturday, 6 June 2015

Update Language Field of the single Content type

//print_r(allowips_for_role(5));
//$type= node_type_get_types();
//$fields = field_info_fields("node", "document");
 //echo "<pre>";
 //print_r($fields);
 //print_r($type);

$lang = und; // Replace with ISO639-2 code if localizing
$node_type = 'document'; // Machine name of the content type

$query = new EntityFieldQuery;
$result = $query
  ->entityCondition('entity_type', 'node')
  ->propertyCondition('type', $node_type)
  ->execute();

if (!empty($result['node'])) {
  $nodes = entity_load('node', array_keys($result['node']));

  foreach($nodes as $node) {
    // Replace field_foo with the machine name of the field to update.
    // - 0 refers to specific within the field array, for when the field contains
    //    multiple values. If the field only has one value, it should be 0.
//echo "<pre>";
//print_r($node->language);
     $node->language = 'en';
    node_save($node);
  }
}

Get information about node types

node_type_get_names()
returns an array of names
Array ( 
    [article] => Article 
    [page] => Basic page 
) 
node_type_get_types() returns an array of objects
Array (
  [article] => stdClass Object
        (
            [type] => article
            [name] => Article
            [base] => node_content
            [module] => node
            [description] => Use articles for time-sensitive content like news, press releases or blog posts.
            [help] => 
            [has_title] => 1
            [title_label] => Title
            [custom] => 1
            [modified] => 1
            [locked] => 0
            [disabled] => 0
            [orig_type] => article
            [disabled_changed] => 
        )

    [page] => stdClass Object
        (
           ..
        )
    ) 

<?php
  $type = $node->type;
  $types = node_type_get_types();
  $name = $types[$type]->name; 
  $description = $types[$type]->description;   
?>
<?php
$name = node_type_get_name($node);
?>
Returns all field definitions.
$var = field_info_fields("node", "node_type");

Reads in fields that match an array of conditions.
$var = field_read_fields(array('type') => 'node_type');