There are 2 easy Methods to achieve this:
Method 1 is more straightforward; Configure your File Entity Module and in the alt and title attribute fields, replace the token with [current-page:title]
which is also one of the available tokens
Please note: for this method above, the title and attribute fields are
replaced if the fields are empty, if any text is input in them at any
time, that text will be used instead.
Method 2 uses Rules to achieve this and this is how:
Create Rules with the following events:
a. after saving new content
b. after updating existing content
Add condition: "content is of type: (add your content type(s) here.....)" Note: without this condition, rules does not seem to pull out the alt and title attributes from your image field.
You may also add other conditions to check if the fields are empty or not (" using data value is empty....") so that you do not alter existing text in the fields. This gives better control than Method 1 above.
Add 2 actions to set your data values for both alt and title fields here using the node title.
For even finer control, you may install the "Conditional Rules" module to check if both or one of alt and title attributes were filled up (example scenario is "if alt is NOT empty and title is empty, update title attribute" or "if alt is empty and title is NOT empty, update alt attribute... etc).
If you do not want to install the conditional rules module but still want better control in checking empty fields, then just create 2 different rules to independently check both fields.
- Save Your rule. that's it.
You may also simply import this rule i created which does the simple steps above. Note that my field is named "field_image" and my content type is "article":
{ "rules_update_image_alt_and_title_automatically" : {
"LABEL" : "Update image alt and title automatically",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules" ],
"ON" : { "node_update" : [], "node_insert" : [] },
"IF" : [
{ "node_is_of_type" : { "node" : [ "node" ], "type" : { "value" : { "article" : "article" } } } }
],
"DO" : [
{ "data_set" : { "data" : [ "node:field-image:alt" ], "value" : "[node:title]" } },
{ "data_set" : { "data" : [ "node:field-image:title" ], "value" : "[node:title]" } }
]
}
}