0

I'm trying to bulk update image alt and title tags for about 1,500 images on a site.

I've tried a number of methods and I will outline them all. I've also tried with the media module enabled and disabled. I think my issue is something to do with not being able to save the changes through to the image itself.

The relevant part of my image array (the image field - called "field_meeme_image" can hold mulitple values) is as follows:

 [field_meeme_image] => Array ( 
        [und] => Array ( 
              [0] => Array ( [fid] => 131 [alt] => Test [title] => [width] => 500

Currently I am trying Devel Execute PHP to just change one node as follows:

$node = node_load(63);
$node->log = 'Test2';
$node->field_meeme_image[$node->language][0]['title'] = $node->title;
node_save($node);

Using ['und'][0]['title'] doesn't work either

I also tried using both methods from this post

And neither one worked for me. I have confirmed that VBO is working. For example if I simply set:

$entity->log = $entity->title;
node_save($entity);

The log gets changed fine but if I try:

$entity->field_meeme_image[$entity->language][0]['title'] = $entity->title;
$entity->field_meeme_image['und'][0]['title'] = $entity->title;
node_save($entity);

The change doesn't get saved.

I've even tried using a preprocess function in my template (I've tried everything I can think of)

function footheme_preprocess_node(&$vars) {
    $node = $vars['node'];
    $user = $vars['user'];
    if ($node->type == 'meeme') {
    if (in_array('administrator', array_values($user->roles))) {
        $node->field_meeme_image[$node->language][0]['alt'] = $node->title;
        node_save($node);
        }
    }

This makes the change in the $node array but it doesn't actually show up as the alt tag for the image and it doesn't save.

Any help would be massively appreciated. Cheers.

1

Hope my below answer helps you.

if you are using Image field, then Image field provides an option to insert "Alt" and "Title" tags. When enabled, you can insert the values in the fields. When you are saving if yourself, custom save, then the image field array needs to look something like below.

[field_image] => Array
    (
        [und] => Array
            (
                [0] => Array
                    (
                        [alt] => alt text
                        [title] => title text
                        [fid] => 12
                        [display] => 1
                        [width] => 220
                        [height] => 169
                        [description] => 
                        [upload_button] => Upload
                        [remove_button] => Remove
                        [upload] => 
                    )

            )

    )

However, the above is from the node presave, but when tested for empty values, and changing values in node presave, this worked flawless. Try that out, curious to know why It wont work, Should be simple (If I understand this correctly :) )

Now, you also need to see at what point you want to implement it. Node presave, node view or any other point in time.

  • Hey thanks OSSGuys, is there any chance you could copy and paste the code you used to to test that worked and the hook you used it in / or how you executed it? That would be awesome! – I am Bish Nov 30 '13 at 8:30
0

Okay,

I found out everything should work but I was just trying to do this at a bad time as there is a bug in core that needs to be patched in 7.24

https://drupal.org/node/2066275

Phew that was driving me nuts!

Thanks for all your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.